From: Davin McCall Date: Fri, 15 Jun 2018 09:11:15 +0000 (+0100) Subject: Refactor: move "start-interruptible" flag into onstart_flags X-Git-Tag: v0.3.0~23 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=383137897685a8576ff47977bce29793667350a5;p=oweals%2Fdinit.git Refactor: move "start-interruptible" flag into onstart_flags --- diff --git a/src/baseproc-service.cc b/src/baseproc-service.cc index 214bc69..2cffa65 100644 --- a/src/baseproc-service.cc +++ b/src/baseproc-service.cc @@ -186,7 +186,6 @@ base_process_service::base_process_service(service_set *sset, string name, reserved_child_watch = false; tracking_child = false; stop_timer_armed = false; - start_is_interruptible = false; } void base_process_service::do_restart() noexcept diff --git a/src/includes/proc-service.h b/src/includes/proc-service.h index bccce7a..5a0cab3 100644 --- a/src/includes/proc-service.h +++ b/src/includes/proc-service.h @@ -83,7 +83,6 @@ class base_process_service : public service_record bool stop_timer_armed : 1; bool reserved_child_watch : 1; bool tracking_child : 1; // whether we expect to see child process status - bool start_is_interruptible : 1; // whether we can interrupt start // Launch the process with the given arguments, return true on success bool start_ps_process(const std::vector &args, bool on_console) noexcept; @@ -110,7 +109,8 @@ class base_process_service : public service_record virtual bool can_interrupt_start() noexcept override { - return waiting_restart_timer || start_is_interruptible || service_record::can_interrupt_start(); + return waiting_restart_timer || onstart_flags.start_interruptible + || service_record::can_interrupt_start(); } virtual bool can_proceed_to_start() noexcept override @@ -177,11 +177,6 @@ class base_process_service : public service_record start_timeout = timeout; } - void set_start_interruptible(bool value) noexcept - { - start_is_interruptible = value; - } - // Set an additional signal (other than SIGTERM) to be used to terminate the process void set_extra_termination_signal(int signo) noexcept { diff --git a/src/includes/service.h b/src/includes/service.h index 54dca7e..09000c5 100644 --- a/src/includes/service.h +++ b/src/includes/service.h @@ -120,11 +120,12 @@ struct onstart_flags_t { 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 + bool start_interruptible : 1; // the startup of this service process is ok to interrupt with SIGINT bool skippable : 1; // if interrupted the service is skipped (scripted services) onstart_flags_t() noexcept : rw_ready(false), log_ready(false), no_sigterm(false), runs_on_console(false), starts_on_console(false), - pass_cs_fd(false), skippable(false) + pass_cs_fd(false), start_interruptible(false), skippable(false) { } }; diff --git a/src/load-service.cc b/src/load-service.cc index 108879f..ffc5564 100644 --- a/src/load-service.cc +++ b/src/load-service.cc @@ -450,7 +450,6 @@ service_record * dirload_service_set::load_service(const char * name) int term_signal = -1; // additional termination signal bool auto_restart = false; bool smooth_recovery = false; - bool start_is_interruptible = false; string socket_path; int socket_perms = 0666; // Note: Posix allows that uid_t and gid_t may be unsigned types, but eg chown uses -1 as an @@ -599,7 +598,7 @@ service_record * dirload_service_set::load_service(const char * name) onstart_flags.pass_cs_fd = true; } else if (option_txt == "start-interruptible") { - start_is_interruptible = true; + onstart_flags.start_interruptible = true; } else if (option_txt == "skippable") { onstart_flags.skippable = true; @@ -688,7 +687,6 @@ service_record * dirload_service_set::load_service(const char * name) rvalps->set_restart_delay(restart_delay); rvalps->set_stop_timeout(stop_timeout); rvalps->set_start_timeout(start_timeout); - rvalps->set_start_interruptible(start_is_interruptible); rvalps->set_extra_termination_signal(term_signal); rvalps->set_run_as_uid_gid(run_as_uid, run_as_gid); rvalps->set_workding_dir(working_dir); @@ -706,7 +704,6 @@ service_record * dirload_service_set::load_service(const char * name) rvalps->set_restart_delay(restart_delay); rvalps->set_stop_timeout(stop_timeout); rvalps->set_start_timeout(start_timeout); - rvalps->set_start_interruptible(start_is_interruptible); rvalps->set_extra_termination_signal(term_signal); rvalps->set_run_as_uid_gid(run_as_uid, run_as_gid); onstart_flags.runs_on_console = false; @@ -720,7 +717,6 @@ service_record * dirload_service_set::load_service(const char * name) rvalps->set_workding_dir(working_dir); rvalps->set_stop_timeout(stop_timeout); rvalps->set_start_timeout(start_timeout); - rvalps->set_start_interruptible(start_is_interruptible); rvalps->set_extra_termination_signal(term_signal); rvalps->set_run_as_uid_gid(run_as_uid, run_as_gid); rval = rvalps; diff --git a/src/tests/proctests.cc b/src/tests/proctests.cc index c716833..2f024fb 100644 --- a/src/tests/proctests.cc +++ b/src/tests/proctests.cc @@ -52,7 +52,6 @@ static void init_service_defaults(base_process_service &ps) ps.set_restart_interval(time_val(10,0), 3); ps.set_restart_delay(time_val(0, 200000000)); // 200 milliseconds ps.set_stop_timeout(time_val(10,0)); - ps.set_start_interruptible(false); } // Regular service start @@ -591,8 +590,8 @@ void test_scripted_start_skip2() init_service_defaults(p); onstart_flags_t sflags; sflags.skippable = true; + sflags.start_interruptible = true; p.set_flags(sflags); - p.set_start_interruptible(true); sset.add_service(&p); service_record *s2 = new service_record(&sset, "test-service-2", service_type_t::INTERNAL, {{&p, REG}});