From daacd062b1cd99103b6408f843aea353b974f066 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 2 Jun 2017 19:39:07 +0100 Subject: [PATCH] Separate "runs-on-console" into runs-on- and starts-on- options. --- README | 20 +++++++++++++++----- doc/linux/services/auxfscheck | 2 +- doc/linux/services/rootfscheck | 2 +- src/load_service.cc | 5 +++++ src/service.cc | 9 ++++----- src/service.h | 3 ++- 6 files changed, 28 insertions(+), 13 deletions(-) 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) { } }; -- 2.25.1