Browse Source

Separate "runs-on-console" into runs-on- and starts-on- options.

Davin McCall 7 years ago
parent
commit
daacd062b1
6 changed files with 28 additions and 13 deletions
  1. 15 5
      README
  2. 1 1
      doc/linux/services/auxfscheck
  3. 1 1
      doc/linux/services/rootfscheck
  4. 5 0
      src/load_service.cc
  5. 4 5
      src/service.cc
  6. 2 1
      src/service.h

+ 15 - 5
README

@@ -220,13 +220,23 @@ options = ( runs-on-console | nosigterm | starts-rwfs | starts-log ) ...
   runs-on-console : specifies that this service uses the console; its input
               and output should be directed to the console. A service running
               on the console prevents other services from running on the
-              console (they will queue for the console). For scripted services
-              "runs-on-console" applies only during execution of the start
-              script.
+              console (they will queue for the console).
 
               The "interrupt" key (normally control-C) will be active for
-              process / scripted services that run on the console. This is
-              useful to allow filesystem checks to be interrupted/skipped.
+              process / scripted services that run on the console. Handling
+              of an interrupt is determined by the service process, but
+              typically will cause it to terminate.
+              
+  starts-on-console : specifies that this service uses the console during
+              service startup. This is implied by runs-on-console, but can
+              be specified separately for services that need the console
+              while they start but not afterwards.
+              
+              This setting is not applicable to regular "process" services,
+              but can be used for "scripted" and "bgprocess" services. It
+              allows for interrupting startup via the "interrupt" key
+              (normally control-C). This is useful to allow filesystem checks
+              to be interrupted/skipped.
 
   starts-rwfs : this service mounts the root filesystem read/write (or at
               least mounts the normal writable filesystems for the system).

+ 1 - 1
doc/linux/services/auxfscheck

@@ -3,7 +3,7 @@
 type = scripted
 command = /sbin/fsck -A -R -C -a
 restart = false
-options = runs-on-console
+options = starts-on-console
 
 depends-on = early-filesystems
 depends-on = udevd

+ 1 - 1
doc/linux/services/rootfscheck

@@ -3,7 +3,7 @@
 type = scripted
 command = /etc/dinit.d/rootfscheck.sh start
 restart = false
-options = runs-on-console pass-cs-fd
+options = starts-on-console pass-cs-fd
 
 depends-on = early-filesystems
 depends-on = udevd

+ 5 - 0
src/load_service.cc

@@ -468,6 +468,11 @@ ServiceRecord * ServiceSet::loadServiceRecord(const char * name)
                         }
                         else if (option_txt == "runs-on-console") {
                             onstart_flags.runs_on_console = true;
+                            // A service that runs on the console necessarily starts on console:
+                            onstart_flags.starts_on_console = true;
+                        }
+                        else if (option_txt == "starts-on-console") {
+                            onstart_flags.starts_on_console = true;
                         }
                         else if (option_txt == "pass-cs-fd") {
                             onstart_flags.pass_cs_fd = true;

+ 4 - 5
src/service.cc

@@ -69,8 +69,7 @@ void ServiceSet::stopService(const std::string & name) noexcept
 // is due to an unexpected process termination.
 void ServiceRecord::stopped() noexcept
 {
-    if (service_type != ServiceType::SCRIPTED && service_type != ServiceType::BGPROCESS
-            && onstart_flags.runs_on_console) {
+    if (onstart_flags.runs_on_console) {
         tcsetpgrp(0, getpgrp());
         discard_console_log_buffer();
         releaseConsole();
@@ -625,7 +624,7 @@ bool ServiceRecord::open_socket() noexcept
 
 void ServiceRecord::allDepsStarted(bool has_console) noexcept
 {
-    if (onstart_flags.runs_on_console && ! has_console) {
+    if (onstart_flags.starts_on_console && ! has_console) {
         waiting_for_deps = true;
         queueForConsole();
         return;
@@ -689,7 +688,7 @@ bool bgproc_service::read_pid_file() noexcept
 
 void ServiceRecord::started() noexcept
 {
-    if (onstart_flags.runs_on_console && (service_type == ServiceType::SCRIPTED || service_type == ServiceType::BGPROCESS)) {
+    if (onstart_flags.starts_on_console && ! onstart_flags.runs_on_console) {
         tcsetpgrp(0, getpgrp());
         releaseConsole();
     }
@@ -722,7 +721,7 @@ void ServiceRecord::started() noexcept
 
 void ServiceRecord::failed_to_start(bool depfailed) noexcept
 {
-    if (!depfailed && onstart_flags.runs_on_console) {
+    if (!depfailed && onstart_flags.starts_on_console) {
         tcsetpgrp(0, getpgrp());
         releaseConsole();
     }

+ 2 - 1
src/service.h

@@ -88,10 +88,11 @@ struct OnstartFlags {
     // Not actually "onstart" commands:
     bool no_sigterm : 1;  // do not send SIGTERM
     bool runs_on_console : 1;  // run "in the foreground"
+    bool starts_on_console : 1; // starts in the foreground
     bool pass_cs_fd : 1;  // pass this service a control socket connection via fd
     
     OnstartFlags() noexcept : rw_ready(false), log_ready(false),
-            no_sigterm(false), runs_on_console(false), pass_cs_fd(false)
+            no_sigterm(false), runs_on_console(false), starts_on_console(false), pass_cs_fd(false)
     {
     }
 };