Refactoring: Move fields from service_record to base_process_service.
authorDavin McCall <davmac@davmac.org>
Fri, 5 Jan 2018 19:33:47 +0000 (19:33 +0000)
committerDavin McCall <davmac@davmac.org>
Fri, 5 Jan 2018 19:33:47 +0000 (19:33 +0000)
src/load_service.cc
src/service.cc
src/service.h

index 4937dee19b758ff8ad00241e7ccfda68aaa423b8..2280aa0ed702275a3247c6bd7306947badc6db6b 100644 (file)
@@ -614,9 +614,7 @@ service_record * dirload_service_set::load_service(const char * name)
                     rval = rvalps;
                 }
                 else {
-                    rval = new service_record(this, string(name), service_type,
-                            std::move(command), command_offsets,
-                            depends);
+                    rval = new service_record(this, string(name), service_type, depends);
                 }
                 rval->set_log_file(logfile);
                 rval->set_auto_restart(auto_restart);
index 7378c02d852d6e80fe7cb77975ab881847307f46..bbbe37a98559cb1f64b45a694d31bd62ba26d3e1 100644 (file)
@@ -1387,9 +1387,12 @@ base_process_service::base_process_service(service_set *sset, string name,
         service_type service_type_p, string &&command,
         std::list<std::pair<unsigned,unsigned>> &command_offsets,
         const std::list<prelim_dep> &deplist_p)
-     : service_record(sset, name, service_type_p, std::move(command), command_offsets,
-         deplist_p), child_listener(this), child_status_listener(this)
+     : service_record(sset, name, service_type_p, deplist_p), child_listener(this),
+       child_status_listener(this)
 {
+    program_name = std::move(command);
+    exec_arg_parts = separate_args(program_name, command_offsets);
+
     restart_interval_count = 0;
     restart_interval_time = {0, 0};
     restart_timer.service = this;
index 152686533bffaa1c722d8a9e87ddc08edaaeca32..e06eff59ce0a490bd05feca61356b1ba759d3044 100644 (file)
@@ -275,12 +275,6 @@ class service_record
     service_state_t desired_state = service_state_t::STOPPED; /* service_state_t::STOPPED / STARTED */
 
     protected:
-    string program_name;          // storage for program/script and arguments
-    std::vector<const char *> exec_arg_parts; // pointer to each argument/part of the program_name, and nullptr
-    
-    string stop_command;          // storage for stop program/script and arguments
-    std::vector<const char *> stop_arg_parts; // pointer to each argument/part of the stop_command, and nullptr
-    
     string pid_file;
     
     onstart_flags_t onstart_flags;
@@ -489,16 +483,7 @@ class service_record
             pdep.to->dependents.push_back(&(*b));
         }
     }
-    
-    service_record(service_set *set, string name, service_type record_type_p, string &&command,
-            std::list<std::pair<unsigned,unsigned>> &command_offsets,
-            const std::list<prelim_dep> &deplist_p)
-        : service_record(set, name, record_type_p, deplist_p)
-    {
-        program_name = std::move(command);
-        exec_arg_parts = separate_args(program_name, command_offsets);
-    }
-    
+
     virtual ~service_record() noexcept
     {
     }
@@ -517,13 +502,6 @@ class service_record
     // Console is available.
     void acquired_console() noexcept;
     
-    // Set the stop command and arguments (may throw std::bad_alloc)
-    void set_stop_command(std::string command, std::list<std::pair<unsigned,unsigned>> &stop_command_offsets)
-    {
-        stop_command = command;
-        stop_arg_parts = separate_args(stop_command, stop_command_offsets);
-    }
-    
     // Get the target (aka desired) state.
     service_state_t get_target_state() noexcept
     {
@@ -642,6 +620,12 @@ class base_process_service : public service_record
     void do_restart() noexcept;
 
     protected:
+    string program_name;          // storage for program/script and arguments
+    std::vector<const char *> exec_arg_parts; // pointer to each argument/part of the program_name, and nullptr
+
+    string stop_command;          // storage for stop program/script and arguments
+    std::vector<const char *> stop_arg_parts; // pointer to each argument/part of the stop_command, and nullptr
+
     service_child_watcher child_listener;
     exec_status_pipe_watcher child_status_listener;
     process_restart_timer restart_timer;
@@ -710,6 +694,13 @@ class base_process_service : public service_record
     {
     }
 
+    // Set the stop command and arguments (may throw std::bad_alloc)
+    void set_stop_command(std::string command, std::list<std::pair<unsigned,unsigned>> &stop_command_offsets)
+    {
+        stop_command = command;
+        stop_arg_parts = separate_args(stop_command, stop_command_offsets);
+    }
+
     void set_restart_interval(timespec interval, int max_restarts) noexcept
     {
         restart_interval = interval;