From f6f570d358b40ef9775042f752034d9b534b5f7f Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Fri, 5 Jan 2018 19:33:47 +0000 Subject: [PATCH] Refactoring: Move fields from service_record to base_process_service. --- src/load_service.cc | 4 +--- src/service.cc | 7 +++++-- src/service.h | 37 ++++++++++++++----------------------- 3 files changed, 20 insertions(+), 28 deletions(-) diff --git a/src/load_service.cc b/src/load_service.cc index 4937dee..2280aa0 100644 --- a/src/load_service.cc +++ b/src/load_service.cc @@ -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); diff --git a/src/service.cc b/src/service.cc index 7378c02..bbbe37a 100644 --- a/src/service.cc +++ b/src/service.cc @@ -1387,9 +1387,12 @@ base_process_service::base_process_service(service_set *sset, string name, service_type service_type_p, string &&command, std::list> &command_offsets, const std::list &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; diff --git a/src/service.h b/src/service.h index 1526865..e06eff5 100644 --- a/src/service.h +++ b/src/service.h @@ -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 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 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> &command_offsets, - const std::list &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> &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 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 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> &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; -- 2.25.1