Refactor: move "start-interruptible" flag into onstart_flags
authorDavin McCall <davmac@davmac.org>
Fri, 15 Jun 2018 09:11:15 +0000 (10:11 +0100)
committerDavin McCall <davmac@davmac.org>
Fri, 15 Jun 2018 09:11:15 +0000 (10:11 +0100)
src/baseproc-service.cc
src/includes/proc-service.h
src/includes/service.h
src/load-service.cc
src/tests/proctests.cc

index 214bc6928d037a0a3886b4c9ab13005988db9952..2cffa65a9fdd863f1b0b0c713d10b51c666b6d11 100644 (file)
@@ -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
index bccce7a27264b39020a142c9d0f0cf5d0d6013c4..5a0cab3cf9ad05c8689fc549d315b6d4190d5da0 100644 (file)
@@ -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<const char *> &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
     {
index 54dca7e3e58240e715dc23c413192711820e7836..09000c5b776df4391bd9aa9b8746ea32be87faf3 100644 (file)
@@ -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)
     {
     }
 };
index 108879f825de08dc4bdca13ef5d215aa1c0fbcef..ffc55646c62725f871d33f682f87f323736b9d88 100644 (file)
@@ -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;
index c7168339c44dce7c74304a70a799ed79603899e4..2f024fbdcdf6cf9f1844fbf9defb840d57d792c7 100644 (file)
@@ -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}});