From: Davin McCall Date: Fri, 2 Jun 2017 18:39:07 +0000 (+0100) Subject: Separate "runs-on-console" into runs-on- and starts-on- options. X-Git-Tag: v0.06~105 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=daacd062b1cd99103b6408f843aea353b974f066;p=oweals%2Fdinit.git Separate "runs-on-console" into runs-on- and starts-on- options. --- diff --git a/README b/README index 3312c92..c9213a7 100644 --- a/README +++ b/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). diff --git a/doc/linux/services/auxfscheck b/doc/linux/services/auxfscheck index 5eccc38..135871d 100644 --- a/doc/linux/services/auxfscheck +++ b/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 diff --git a/doc/linux/services/rootfscheck b/doc/linux/services/rootfscheck index 236cc1f..c8e0ef2 100644 --- a/doc/linux/services/rootfscheck +++ b/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 diff --git a/src/load_service.cc b/src/load_service.cc index 61ed0e7..e01f50c 100644 --- a/src/load_service.cc +++ b/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; diff --git a/src/service.cc b/src/service.cc index 282809c..f8cc7e3 100644 --- a/src/service.cc +++ b/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(); } diff --git a/src/service.h b/src/service.h index e4dd2d9..21411b6 100644 --- a/src/service.h +++ b/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) { } };