From 08138c09d1d3cfc00e1b7e1bd7349b95f40f007e Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 4 Jul 2017 09:37:21 +0100 Subject: [PATCH] Various renaming of camelCase to underscored_name for consistency. --- src/control.cc | 14 +++++------ src/dinit-log.cc | 12 +++++----- src/dinit-log.h | 62 ++++++++++++++++++++++++------------------------ src/dinit.cc | 10 ++++---- src/service.cc | 42 ++++++++++++++++---------------- src/service.h | 32 ++++++++----------------- 6 files changed, 80 insertions(+), 92 deletions(-) diff --git a/src/control.cc b/src/control.cc index b2152c4..d17dc48 100644 --- a/src/control.cc +++ b/src/control.cc @@ -111,7 +111,7 @@ bool control_conn_t::processFindLoad(int pktType) std::vector rp_buf; rp_buf.reserve(7); rp_buf.push_back(DINIT_RP_SERVICERECORD); - rp_buf.push_back(static_cast(record->getState())); + rp_buf.push_back(static_cast(record->get_state())); for (int i = 0; i < (int) sizeof(handle); i++) { rp_buf.push_back(*(((char *) &handle) + i)); } @@ -166,29 +166,29 @@ bool control_conn_t::processStartStop(int pktType) if (do_pin) service->pinStart(); service->start(); services->process_queues(); - already_there = service->getState() == service_state_t::STARTED; + already_there = service->get_state() == service_state_t::STARTED; break; case DINIT_CP_STOPSERVICE: // force service to stop if (do_pin) service->pinStop(); service->stop(true); - service->forceStop(); + service->forced_stop(); services->process_queues(); - already_there = service->getState() == service_state_t::STOPPED; + already_there = service->get_state() == service_state_t::STOPPED; break; case DINIT_CP_WAKESERVICE: // re-start a stopped service (do not mark as required) if (do_pin) service->pinStart(); service->start(false); services->process_queues(); - already_there = service->getState() == service_state_t::STARTED; + already_there = service->get_state() == service_state_t::STARTED; break; case DINIT_CP_RELEASESERVICE: // remove required mark, stop if not required by dependents if (do_pin) service->pinStop(); service->stop(false); services->process_queues(); - already_there = service->getState() == service_state_t::STOPPED; + already_there = service->get_state() == service_state_t::STOPPED; break; } @@ -258,7 +258,7 @@ bool control_conn_t::listServices() pkt_buf[0] = DINIT_RP_SVCINFO; pkt_buf[1] = nameLen; - pkt_buf[2] = static_cast(sptr->getState()); + pkt_buf[2] = static_cast(sptr->get_state()); pkt_buf[3] = static_cast(sptr->getTargetState()); pkt_buf[4] = 0; // reserved diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 717e601..81f1647 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -398,7 +398,7 @@ static void do_log_commit(int idx) noexcept } // Log a multi-part message beginning -void logMsgBegin(LogLevel lvl, const char *msg) noexcept +void log_msg_begin(LogLevel lvl, const char *msg) noexcept { log_current_line[DLOG_CONS] = lvl >= log_level[DLOG_CONS]; log_current_line[DLOG_MAIN] = lvl >= log_level[DLOG_MAIN]; @@ -416,14 +416,14 @@ void logMsgBegin(LogLevel lvl, const char *msg) noexcept } // Continue a multi-part log message -void logMsgPart(const char *msg) noexcept +void log_msg_part(const char *msg) noexcept { do_log_part(DLOG_CONS, msg); do_log_part(DLOG_MAIN, msg); } // Complete a multi-part log message -void logMsgEnd(const char *msg) noexcept +void log_msg_end(const char *msg) noexcept { for (int i = 0; i < 2; i++) { do_log_part(i, msg); @@ -432,19 +432,19 @@ void logMsgEnd(const char *msg) noexcept } } -void logServiceStarted(const char *service_name) noexcept +void log_service_started(const char *service_name) noexcept { do_log_cons("[ OK ] ", service_name, "\n"); do_log_main("dinit: service ", service_name, " started.\n"); } -void logServiceFailed(const char *service_name) noexcept +void log_service_failed(const char *service_name) noexcept { do_log_cons("[FAILED] ", service_name, "\n"); do_log_main("dinit: service ", service_name, " failed to start.\n"); } -void logServiceStopped(const char *service_name) noexcept +void log_service_stopped(const char *service_name) noexcept { do_log_cons("[STOPPD] ", service_name, "\n"); do_log_main("dinit: service ", service_name, " stopped.\n"); diff --git a/src/dinit-log.h b/src/dinit-log.h index 0b2153c..d3fbe98 100644 --- a/src/dinit-log.h +++ b/src/dinit-log.h @@ -25,12 +25,12 @@ bool is_log_flushed() noexcept; void discard_console_log_buffer() noexcept; void log(LogLevel lvl, const char *msg) noexcept; -void logMsgBegin(LogLevel lvl, const char *msg) noexcept; -void logMsgPart(const char *msg) noexcept; -void logMsgEnd(const char *msg) noexcept; -void logServiceStarted(const char *service_name) noexcept; -void logServiceFailed(const char *service_name) noexcept; -void logServiceStopped(const char *service_name) noexcept; +void log_msg_begin(LogLevel lvl, const char *msg) noexcept; +void log_msg_part(const char *msg) noexcept; +void log_msg_end(const char *msg) noexcept; +void log_service_started(const char *service_name) noexcept; +void log_service_failed(const char *service_name) noexcept; +void log_service_stopped(const char *service_name) noexcept; // Convenience methods which perform type conversion of the argument. // There is some duplication here that could possibly be avoided, but @@ -40,79 +40,79 @@ static inline void log(LogLevel lvl, const std::string &str) noexcept log(lvl, str.c_str()); } -static inline void logMsgBegin(LogLevel lvl, const std::string &str) noexcept +static inline void log_msg_begin(LogLevel lvl, const std::string &str) noexcept { - logMsgBegin(lvl, str.c_str()); + log_msg_begin(lvl, str.c_str()); } -static inline void logMsgBegin(LogLevel lvl, int a) noexcept +static inline void log_msg_begin(LogLevel lvl, int a) noexcept { constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2; char nbuf[bufsz]; snprintf(nbuf, bufsz, "%d", a); - logMsgBegin(lvl, nbuf); + log_msg_begin(lvl, nbuf); } -static inline void logMsgPart(const std::string &str) noexcept +static inline void log_msg_part(const std::string &str) noexcept { - logMsgPart(str.c_str()); + log_msg_part(str.c_str()); } -static inline void logMsgPart(int a) noexcept +static inline void log_msg_part(int a) noexcept { constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2; char nbuf[bufsz]; snprintf(nbuf, bufsz, "%d", a); - logMsgPart(nbuf); + log_msg_part(nbuf); } -static inline void logMsgEnd(const std::string &str) noexcept +static inline void log_msg_end(const std::string &str) noexcept { - logMsgEnd(str.c_str()); + log_msg_end(str.c_str()); } -static inline void logMsgEnd(int a) noexcept +static inline void log_msg_end(int a) noexcept { constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2; char nbuf[bufsz]; snprintf(nbuf, bufsz, "%d", a); - logMsgEnd(nbuf); + log_msg_end(nbuf); } -static inline void logServiceStarted(const std::string &str) noexcept +static inline void log_service_started(const std::string &str) noexcept { - logServiceStarted(str.c_str()); + log_service_started(str.c_str()); } -static inline void logServiceFailed(const std::string &str) noexcept +static inline void log_service_failed(const std::string &str) noexcept { - logServiceFailed(str.c_str()); + log_service_failed(str.c_str()); } -static inline void logServiceStopped(const std::string &str) noexcept +static inline void log_service_stopped(const std::string &str) noexcept { - logServiceStopped(str.c_str()); + log_service_stopped(str.c_str()); } // It's not intended that methods in this namespace be called directly: namespace dinit_log { - template static inline void logParts(A a) noexcept + template static inline void log_parts(A a) noexcept { - logMsgEnd(a); + log_msg_end(a); } - template static inline void logParts(A a, B... b) noexcept + template static inline void log_parts(A a, B... b) noexcept { - logMsgPart(a); - logParts(b...); + log_msg_part(a); + log_parts(b...); } } // Variadic 'log' method. template static inline void log(LogLevel lvl, A a, B ...b) noexcept { - logMsgBegin(lvl, a); - dinit_log::logParts(b...); + log_msg_begin(lvl, a); + dinit_log::log_parts(b...); } #endif diff --git a/src/dinit.cc b/src/dinit.cc index 460bef0..fa804eb 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -342,19 +342,19 @@ int dinit_main(int argc, char **argv) shutdown_type_t shutdown_type = services->getShutdownType(); if (am_system_init) { - logMsgBegin(LogLevel::INFO, "No more active services."); + log_msg_begin(LogLevel::INFO, "No more active services."); if (shutdown_type == shutdown_type_t::REBOOT) { - logMsgEnd(" Will reboot."); + log_msg_end(" Will reboot."); } else if (shutdown_type == shutdown_type_t::HALT) { - logMsgEnd(" Will halt."); + log_msg_end(" Will halt."); } else if (shutdown_type == shutdown_type_t::POWEROFF) { - logMsgEnd(" Will power down."); + log_msg_end(" Will power down."); } else { - logMsgEnd(" Re-initiating boot sequence."); + log_msg_end(" Re-initiating boot sequence."); } } diff --git a/src/service.cc b/src/service.cc index 8fa93ec..7b20e43 100644 --- a/src/service.cc +++ b/src/service.cc @@ -48,7 +48,7 @@ service_record * service_set::find_service(const std::string &name) noexcept return ::find_service(records, name.c_str()); } -void service_set::stopService(const std::string & name) noexcept +void service_set::stop_service(const std::string & name) noexcept { service_record *record = find_service(name); if (record != nullptr) { @@ -107,7 +107,7 @@ void service_record::stopped() noexcept } } - logServiceStopped(service_name); + log_service_stopped(service_name); notify_listeners(service_event::STOPPED); } @@ -156,7 +156,7 @@ void service_record::emergency_stop() noexcept start_explicit = false; release(); } - forceStop(); + forced_stop(); stop_dependents(); stopped(); } @@ -300,7 +300,7 @@ void bgproc_service::handle_exit_status(int exit_status) noexcept start_explicit = false; release(); } - forceStop(); + forced_stop(); stop_dependents(); stopped(); } @@ -410,7 +410,7 @@ void service_record::require() noexcept if (required_by++ == 0) { prop_require = !prop_release; prop_release = false; - services->addToPropQueue(this); + services->add_prop_queue(this); } } @@ -423,7 +423,7 @@ void service_record::release() noexcept // the require was pending though: prop_release = !prop_require; prop_require = false; - services->addToPropQueue(this); + services->add_prop_queue(this); if (service_state == service_state_t::STOPPED) { services->service_inactive(this); @@ -480,7 +480,7 @@ void service_record::start(bool activate) noexcept waiting_for_deps = true; if (start_check_dependencies(true)) { - services->addToStartQueue(this); + services->add_transition_queue(this); } } @@ -562,7 +562,7 @@ void service_record::dependencyStarted() noexcept { if ((service_state == service_state_t::STARTING || service_state == service_state_t::STARTED) && waiting_for_deps) { - services->addToStartQueue(this); + services->add_transition_queue(this); } } @@ -575,7 +575,7 @@ bool service_record::start_check_dependencies(bool start_deps) noexcept if (start_deps) { all_deps_started = false; (*i)->prop_start = true; - services->addToPropQueue(*i); + services->add_prop_queue(*i); } else { return false; @@ -588,7 +588,7 @@ bool service_record::start_check_dependencies(bool start_deps) noexcept if (start_deps) { if (to->service_state != service_state_t::STARTED) { to->prop_start = true; - services->addToPropQueue(to); + services->add_prop_queue(to); i->waiting_on = true; all_deps_started = false; } @@ -717,7 +717,7 @@ void service_record::all_deps_started(bool has_console) noexcept } } -void service_record::acquiredConsole() noexcept +void service_record::acquired_console() noexcept { if (service_state != service_state_t::STARTING) { // We got the console but no longer want it. @@ -808,7 +808,7 @@ void service_record::started() noexcept release_console(); } - logServiceStarted(service_name); + log_service_started(service_name); service_state = service_state_t::STARTED; notify_listeners(service_event::STARTED); @@ -841,7 +841,7 @@ void service_record::failed_to_start(bool depfailed) noexcept release_console(); } - logServiceFailed(service_name); + log_service_failed(service_name); service_state = service_state_t::STOPPED; if (start_explicit) { start_explicit = false; @@ -853,7 +853,7 @@ void service_record::failed_to_start(bool depfailed) noexcept for (sr_iter i = dependents.begin(); i != dependents.end(); i++) { if ((*i)->service_state == service_state_t::STARTING) { (*i)->prop_failure = true; - services->addToPropQueue(*i); + services->add_prop_queue(*i); } } for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) { @@ -1108,18 +1108,18 @@ void service_record::run_child_proc(const char * const *args, const char *logfil } // Mark this and all dependent services as force-stopped. -void service_record::forceStop() noexcept +void service_record::forced_stop() noexcept { if (service_state != service_state_t::STOPPED) { force_stop = true; - services->addToStopQueue(this); + services->add_transition_queue(this); } } void service_record::dependent_stopped() noexcept { if (service_state == service_state_t::STOPPING && waiting_for_deps) { - services->addToStopQueue(this); + services->add_transition_queue(this); } } @@ -1174,7 +1174,7 @@ void service_record::do_stop() noexcept service_state = service_state_t::STOPPING; waiting_for_deps = true; if (stop_dependents()) { - services->addToStopQueue(this); + services->add_transition_queue(this); } } @@ -1205,11 +1205,11 @@ bool service_record::stop_dependents() noexcept if (force_stop) { // If this service is to be forcefully stopped, dependents must also be. - (*i)->forceStop(); + (*i)->forced_stop(); } (*i)->prop_stop = true; - services->addToPropQueue(*i); + services->add_prop_queue(*i); } return all_deps_stopped; @@ -1375,7 +1375,7 @@ void base_process_service::do_restart() noexcept } else { desired_state = service_state_t::STOPPED; - forceStop(); + forced_stop(); } services->process_queues(); } diff --git a/src/service.h b/src/service.h index 8e23593..a1eb686 100644 --- a/src/service.h +++ b/src/service.h @@ -403,7 +403,7 @@ class service_record } } - // Queue to run on the console. 'acquiredConsole()' will be called when the console is available. + // Queue to run on the console. 'acquired_console()' will be called when the console is available. // Has no effect if the service has already queued for console. void queue_for_console() noexcept; @@ -428,6 +428,8 @@ class service_record services = set; service_name = name; record_type = service_type::DUMMY; + socket_perms = 0; + exit_status = 0; } service_record(service_set *set, string name, service_type record_type_p, @@ -477,7 +479,7 @@ class service_record void do_stop() noexcept; // Console is available. - void acquiredConsole() noexcept; + void acquired_console() noexcept; // Set the stop command and arguments (may throw std::bad_alloc) void setStopCommand(std::string command, std::list> &stop_command_offsets) @@ -486,12 +488,6 @@ class service_record stop_arg_parts = separate_args(stop_command, stop_command_offsets); } - // Get the current service state. - service_state_t getState() noexcept - { - return service_state; - } - // Get the target (aka desired) state. service_state_t getTargetState() noexcept { @@ -541,12 +537,12 @@ class service_record } const std::string &getServiceName() const noexcept { return service_name; } - service_state_t getState() const noexcept { return service_state; } + service_state_t get_state() const noexcept { return service_state; } void start(bool activate = true) noexcept; // start the service void stop(bool bring_down = true) noexcept; // stop the service - void forceStop() noexcept; // force-stop this service and all dependents + void forced_stop() noexcept; // force-stop this service and all dependents // Pin the service in "started" state (when it reaches the state) void pinStart() noexcept @@ -871,28 +867,20 @@ class service_set // Stop the service with the given name. The named service will begin // transition to the 'stopped' state. - void stopService(const std::string &name) noexcept; + void stop_service(const std::string &name) noexcept; // Add a service record to the state propagation queue. The service record will have its // do_propagation() method called when the queue is processed. - void addToPropQueue(service_record *service) noexcept + void add_prop_queue(service_record *service) noexcept { if (! prop_queue.is_queued(service)) { prop_queue.insert(service); } } - // Add a service record to the start queue. The service record will have its - // execute_transition() method called when the queue is processed. - void addToStartQueue(service_record *service) noexcept - { - // The start/stop queue is actually one queue: - addToStopQueue(service); - } - // Add a service record to the stop queue. The service record will have its // execute_transition() method called when the queue is processed. - void addToStopQueue(service_record *service) noexcept + void add_transition_queue(service_record *service) noexcept { if (! stop_queue.is_queued(service)) { stop_queue.insert(service); @@ -932,7 +920,7 @@ class service_set } else { service_record * front = console_queue.pop_front(); - front->acquiredConsole(); + front->acquired_console(); } } -- 2.25.1