From 5f590128f0aef529c1f2593f5382bb0c31c21fc6 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Wed, 25 Jul 2018 13:33:26 +0100 Subject: [PATCH] Fix a number of minor issues found by static analysis. --- src/dinit.cc | 2 ++ src/includes/proc-service.h | 19 ++++++++++--------- src/includes/service.h | 14 ++++++++------ src/load-service.cc | 4 ++-- src/service.cc | 2 +- 5 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/dinit.cc b/src/dinit.cc index 77ba20f..b7fe727 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -704,6 +704,7 @@ void setup_external_log() noexcept // basically use it anyway. try { setup_main_log(sockfd); + external_log_open = true; } catch (std::exception &e) { log(loglevel_t::ERROR, "Setting up log failed: ", e.what()); @@ -724,6 +725,7 @@ void setup_external_log() noexcept if (log_fd >= 0) { try { setup_main_log(log_fd); + external_log_open = true; } catch (std::exception &e) { log(loglevel_t::ERROR, "Setting up log failed: ", e.what()); diff --git a/src/includes/proc-service.h b/src/includes/proc-service.h index 962a558..398eb2a 100644 --- a/src/includes/proc-service.h +++ b/src/includes/proc-service.h @@ -20,7 +20,7 @@ class process_restart_timer : public eventloop_t::timer_impl> &stop_command_offsets) + void set_stop_command(const std::string &command, + std::list> &stop_command_offsets) { stop_command = command; stop_arg_parts = separate_args(stop_command, stop_command_offsets); @@ -191,7 +192,7 @@ class base_process_service : public service_record } // Set the working directory - void set_workding_dir(string working_dir_p) + void set_workding_dir(const string &working_dir_p) { working_dir = working_dir_p; } @@ -225,9 +226,9 @@ class process_service : public base_process_service virtual void bring_down() noexcept override; public: - process_service(service_set *sset, string name, string &&command, + process_service(service_set *sset, const string &name, string &&command, std::list> &command_offsets, - std::list depends_p) + const std::list &depends_p) : base_process_service(sset, name, service_type_t::PROCESS, std::move(command), command_offsets, depends_p) { @@ -255,9 +256,9 @@ class bgproc_service : public base_process_service pid_result_t read_pid_file(bp_sys::exit_status *exit_status) noexcept; public: - bgproc_service(service_set *sset, string name, string &&command, + bgproc_service(service_set *sset, const string &name, string &&command, std::list> &command_offsets, - std::list depends_p) + const std::list &depends_p) : base_process_service(sset, name, service_type_t::BGPROCESS, std::move(command), command_offsets, depends_p) { @@ -287,9 +288,9 @@ class scripted_service : public base_process_service bool interrupting_start : 1; // running start script (true) or stop script (false) public: - scripted_service(service_set *sset, string name, string &&command, + scripted_service(service_set *sset, const string &name, string &&command, std::list> &command_offsets, - std::list depends_p) + const std::list &depends_p) : base_process_service(sset, name, service_type_t::SCRIPTED, std::move(command), command_offsets, depends_p), interrupting_start(false) { diff --git a/src/includes/service.h b/src/includes/service.h index 53f4ba2..7892fbe 100644 --- a/src/includes/service.h +++ b/src/includes/service.h @@ -139,7 +139,7 @@ class service_load_exc std::string excDescription; protected: - service_load_exc(std::string serviceName, std::string &&desc) noexcept + service_load_exc(const std::string &serviceName, std::string &&desc) noexcept : serviceName(serviceName), excDescription(std::move(desc)) { } @@ -148,7 +148,7 @@ class service_load_exc class service_not_found : public service_load_exc { public: - service_not_found(std::string serviceName) noexcept + service_not_found(const std::string &serviceName) noexcept : service_load_exc(serviceName, "Service description not found.") { } @@ -157,7 +157,7 @@ class service_not_found : public service_load_exc class service_cyclic_dependency : public service_load_exc { public: - service_cyclic_dependency(std::string serviceName) noexcept + service_cyclic_dependency(const std::string &serviceName) noexcept : service_load_exc(serviceName, "Has cyclic dependency.") { } @@ -166,7 +166,7 @@ class service_cyclic_dependency : public service_load_exc class service_description_exc : public service_load_exc { public: - service_description_exc(std::string serviceName, std::string &&extraInfo) noexcept + service_description_exc(const std::string &serviceName, std::string &&extraInfo) noexcept : service_load_exc(serviceName, std::move(extraInfo)) { } @@ -690,12 +690,14 @@ class service_record if (dep.get_to() == to && dep.dep_type == dep_type) { for (auto j = to->dependents.begin(); ; j++) { if (*j == &dep) { - dependents.erase(j); + to->dependents.erase(j); break; } } + if (dep.holding_acq) { + to->release(); + } depends_on.erase(i); - to->release(); break; } } diff --git a/src/load-service.cc b/src/load-service.cc index 3d99d6e..6dc47d4 100644 --- a/src/load-service.cc +++ b/src/load-service.cc @@ -796,13 +796,13 @@ service_record * dirload_service_set::load_service(const char * name) catch (setting_exception &setting_exc) { // Must remove the dummy service record. - std::remove(records.begin(), records.end(), rval); + records.erase(std::find(records.begin(), records.end(), rval)); delete rval; throw service_description_exc(name, std::move(setting_exc.get_info())); } catch (...) { // Must remove the dummy service record. - std::remove(records.begin(), records.end(), rval); + records.erase(std::find(records.begin(), records.end(), rval)); delete rval; throw; } diff --git a/src/service.cc b/src/service.cc index 40d7156..fe7f9dc 100644 --- a/src/service.cc +++ b/src/service.cc @@ -26,7 +26,7 @@ static service_record * find_service(const std::list & records { using std::list; list::const_iterator i = records.begin(); - for ( ; i != records.end(); i++ ) { + for ( ; i != records.end(); ++i ) { if (strcmp((*i)->get_name().c_str(), name) == 0) { return *i; } -- 2.25.1