From 794993eb8316196b471b8172428d425a68d247a7 Mon Sep 17 00:00:00 2001 From: Davin McCall Date: Tue, 4 Jul 2017 19:34:42 +0100 Subject: [PATCH] More camelCase to under_score renaming. --- src/control.cc | 26 ++++++++--------- src/dinit-log.cc | 18 ++++++------ src/dinit-log.h | 16 +++++------ src/dinit.cc | 34 +++++++++++------------ src/load_service.cc | 28 +++++++++---------- src/service.cc | 68 ++++++++++++++++++++++----------------------- src/service.h | 24 ++++++++-------- 7 files changed, 107 insertions(+), 107 deletions(-) diff --git a/src/control.cc b/src/control.cc index d17dc48..a3eaae2 100644 --- a/src/control.cc +++ b/src/control.cc @@ -97,7 +97,7 @@ bool control_conn_t::processFindLoad(int pktType) record = services->load_service(serviceName.c_str()); } catch (service_load_exc &slexc) { - log(LogLevel::ERROR, "Could not load service ", slexc.serviceName, ": ", slexc.excDescription); + log(loglevel_t::ERROR, "Could not load service ", slexc.serviceName, ": ", slexc.excDescription); } } else { @@ -115,7 +115,7 @@ bool control_conn_t::processFindLoad(int pktType) for (int i = 0; i < (int) sizeof(handle); i++) { rp_buf.push_back(*(((char *) &handle) + i)); } - rp_buf.push_back(static_cast(record->getTargetState())); + rp_buf.push_back(static_cast(record->get_target_state())); if (! queuePacket(std::move(rp_buf))) return false; } else { @@ -163,14 +163,14 @@ bool control_conn_t::processStartStop(int pktType) switch (pktType) { case DINIT_CP_STARTSERVICE: // start service, mark as required - if (do_pin) service->pinStart(); + if (do_pin) service->pin_start(); service->start(); services->process_queues(); already_there = service->get_state() == service_state_t::STARTED; break; case DINIT_CP_STOPSERVICE: // force service to stop - if (do_pin) service->pinStop(); + if (do_pin) service->pin_stop(); service->stop(true); service->forced_stop(); services->process_queues(); @@ -178,14 +178,14 @@ bool control_conn_t::processStartStop(int pktType) break; case DINIT_CP_WAKESERVICE: // re-start a stopped service (do not mark as required) - if (do_pin) service->pinStart(); + if (do_pin) service->pin_start(); service->start(false); services->process_queues(); 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(); + if (do_pin) service->pin_stop(); service->stop(false); services->process_queues(); already_there = service->get_state() == service_state_t::STOPPED; @@ -252,14 +252,14 @@ bool control_conn_t::listServices() for (auto sptr : slist) { std::vector pkt_buf; - const std::string &name = sptr->getServiceName(); + const std::string &name = sptr->get_service_name(); int nameLen = std::min((size_t)256, name.length()); pkt_buf.resize(8 + nameLen); pkt_buf[0] = DINIT_RP_SVCINFO; pkt_buf[1] = nameLen; pkt_buf[2] = static_cast(sptr->get_state()); - pkt_buf[3] = static_cast(sptr->getTargetState()); + pkt_buf[3] = static_cast(sptr->get_target_state()); pkt_buf[4] = 0; // reserved pkt_buf[5] = 0; @@ -324,7 +324,7 @@ bool control_conn_t::queuePacket(const char *pkt, unsigned size) noexcept return false; } if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { - log(LogLevel::WARN, "Error writing to control connection: ", strerror(errno)); + log(loglevel_t::WARN, "Error writing to control connection: ", strerror(errno)); return false; } // EAGAIN etc: fall through to below @@ -379,7 +379,7 @@ bool control_conn_t::queuePacket(std::vector &&pkt) noexcept return false; } if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { - log(LogLevel::WARN, "Error writing to control connection: ", strerror(errno)); + log(loglevel_t::WARN, "Error writing to control connection: ", strerror(errno)); return false; } // EAGAIN etc: fall through to below @@ -431,7 +431,7 @@ bool control_conn_t::dataReady() noexcept // Note file descriptor is non-blocking if (r == -1) { if (errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { - log(LogLevel::WARN, "Error writing to control connection: ", strerror(errno)); + log(loglevel_t::WARN, "Error writing to control connection: ", strerror(errno)); return true; } return false; @@ -453,7 +453,7 @@ bool control_conn_t::dataReady() noexcept } else if (rbuf.get_length() == 1024) { // Too big packet - log(LogLevel::WARN, "Received too-large control package; dropping connection"); + log(loglevel_t::WARN, "Received too-large control package; dropping connection"); bad_conn_close = true; iob.set_watches(OUT_EVENTS); } @@ -488,7 +488,7 @@ bool control_conn_t::sendData() noexcept // spurious readiness notification? } else { - log(LogLevel::ERROR, "Error writing to control connection: ", strerror(errno)); + log(loglevel_t::ERROR, "Error writing to control connection: ", strerror(errno)); return true; } return false; diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 81f1647..a67e5d3 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -15,7 +15,7 @@ extern eventloop_t eventLoop; static bool log_current_line[2]; // Whether the current line is being logged (for console, main log) -LogLevel log_level[2] = { LogLevel::WARN, LogLevel::WARN }; +loglevel_t log_level[2] = { loglevel_t::WARN, loglevel_t::WARN }; static service_set *services = nullptr; // Reference to service set @@ -302,16 +302,16 @@ template static void append(BufferedLogStream &buf, const char append(buf, t...); } -static int log_level_to_syslog_level(LogLevel l) +static int log_level_to_syslog_level(loglevel_t l) { switch (l) { - case LogLevel::DEBUG: + case loglevel_t::DEBUG: return LOG_DEBUG; - case LogLevel::INFO: + case loglevel_t::INFO: return LOG_INFO; - case LogLevel::WARN: + case loglevel_t::WARN: return LOG_WARNING; - case LogLevel::ERROR: + case loglevel_t::ERROR: return LOG_ERR; default: ; } @@ -334,7 +334,7 @@ template static void push_to_log(int idx, T ... args) noexcept } // Variadic method to potentially log a sequence of strings as a single message with the given log level: -template static void do_log(LogLevel lvl, T ... args) noexcept +template static void do_log(loglevel_t lvl, T ... args) noexcept { log_current_line[DLOG_CONS] = lvl >= log_level[DLOG_CONS]; log_current_line[DLOG_MAIN] = lvl >= log_level[DLOG_MAIN]; @@ -368,7 +368,7 @@ template static void do_log_main(T ... args) noexcept } // Log a message. A newline will be appended. -void log(LogLevel lvl, const char *msg) noexcept +void log(loglevel_t lvl, const char *msg) noexcept { do_log(lvl, "dinit: ", msg, "\n"); } @@ -398,7 +398,7 @@ static void do_log_commit(int idx) noexcept } // Log a multi-part message beginning -void log_msg_begin(LogLevel lvl, const char *msg) noexcept +void log_msg_begin(loglevel_t 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]; diff --git a/src/dinit-log.h b/src/dinit-log.h index d3fbe98..b94a658 100644 --- a/src/dinit-log.h +++ b/src/dinit-log.h @@ -9,7 +9,7 @@ class service_set; -enum class LogLevel { +enum class loglevel_t { DEBUG, INFO, WARN, @@ -17,15 +17,15 @@ enum class LogLevel { ZERO // log absolutely nothing }; -extern LogLevel log_level[2]; +extern loglevel_t log_level[2]; void enable_console_log(bool do_enable) noexcept; void init_log(service_set *sset); void setup_main_log(int fd); bool is_log_flushed() noexcept; void discard_console_log_buffer() noexcept; -void log(LogLevel lvl, const char *msg) noexcept; -void log_msg_begin(LogLevel lvl, const char *msg) noexcept; +void log(loglevel_t lvl, const char *msg) noexcept; +void log_msg_begin(loglevel_t 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; @@ -35,17 +35,17 @@ 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 // it doesn't seem like a big deal. -static inline void log(LogLevel lvl, const std::string &str) noexcept +static inline void log(loglevel_t lvl, const std::string &str) noexcept { log(lvl, str.c_str()); } -static inline void log_msg_begin(LogLevel lvl, const std::string &str) noexcept +static inline void log_msg_begin(loglevel_t lvl, const std::string &str) noexcept { log_msg_begin(lvl, str.c_str()); } -static inline void log_msg_begin(LogLevel lvl, int a) noexcept +static inline void log_msg_begin(loglevel_t lvl, int a) noexcept { constexpr int bufsz = (CHAR_BIT * sizeof(int) - 1) / 3 + 2; char nbuf[bufsz]; @@ -109,7 +109,7 @@ namespace dinit_log { } // Variadic 'log' method. -template static inline void log(LogLevel lvl, A a, B ...b) noexcept +template static inline void log(loglevel_t lvl, A a, B ...b) noexcept { log_msg_begin(lvl, a); dinit_log::log_parts(b...); diff --git a/src/dinit.cc b/src/dinit.cc index ae859e0..696271f 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -317,13 +317,13 @@ int dinit_main(int argc, char **argv) // exit if user process). } catch (service_not_found &snf) { - log(LogLevel::ERROR, snf.serviceName, ": Could not find service description."); + log(loglevel_t::ERROR, snf.serviceName, ": Could not find service description."); } catch (service_load_exc &sle) { - log(LogLevel::ERROR, sle.serviceName, ": ", sle.excDescription); + log(loglevel_t::ERROR, sle.serviceName, ": ", sle.excDescription); } catch (std::bad_alloc &badalloce) { - log(LogLevel::ERROR, "Out of memory when trying to start service: ", svc, "."); + log(loglevel_t::ERROR, "Out of memory when trying to start service: ", svc, "."); break; } } @@ -338,7 +338,7 @@ int dinit_main(int argc, char **argv) shutdown_type_t shutdown_type = services->getShutdownType(); if (am_system_init) { - log_msg_begin(LogLevel::INFO, "No more active services."); + log_msg_begin(loglevel_t::INFO, "No more active services."); if (shutdown_type == shutdown_type_t::REBOOT) { log_msg_end(" Will reboot."); @@ -371,7 +371,7 @@ int dinit_main(int argc, char **argv) } catch (...) { // Now what do we do? try to reboot, but wait for user ack to avoid boot loop. - log(LogLevel::ERROR, "Could not start 'boot' service. Will attempt reboot."); + log(loglevel_t::ERROR, "Could not start 'boot' service. Will attempt reboot."); wait_for_user_input(); shutdown_type = shutdown_type_t::REBOOT; } @@ -391,7 +391,7 @@ int dinit_main(int argc, char **argv) // Fork and execute dinit-reboot. execl("/sbin/shutdown", "/sbin/shutdown", "--system", cmd_arg, nullptr); - log(LogLevel::ERROR, "Could not execute /sbin/shutdown: ", strerror(errno)); + log(loglevel_t::ERROR, "Could not execute /sbin/shutdown: ", strerror(errno)); // PID 1 must not actually exit, although we should never reach this point: while (true) { @@ -435,7 +435,7 @@ static void control_socket_cb(eventloop_t *loop, int sockfd) new control_conn_t(loop, services, newfd); // will delete itself when it's finished } catch (std::exception &exc) { - log(LogLevel::ERROR, "Accepting control connection: ", exc.what()); + log(loglevel_t::ERROR, "Accepting control connection: ", exc.what()); close(newfd); } } @@ -450,7 +450,7 @@ void open_control_socket(bool report_ro_failure) noexcept struct sockaddr_un * name = static_cast(malloc(sockaddr_size)); if (name == nullptr) { - log(LogLevel::ERROR, "Opening control socket: out of memory"); + log(loglevel_t::ERROR, "Opening control socket: out of memory"); return; } @@ -465,14 +465,14 @@ void open_control_socket(bool report_ro_failure) noexcept int sockfd = dinit_socket(AF_UNIX, SOCK_STREAM, 0, SOCK_NONBLOCK | SOCK_CLOEXEC); if (sockfd == -1) { - log(LogLevel::ERROR, "Error creating control socket: ", strerror(errno)); + log(loglevel_t::ERROR, "Error creating control socket: ", strerror(errno)); free(name); return; } if (bind(sockfd, (struct sockaddr *) name, sockaddr_size) == -1) { if (errno != EROFS || report_ro_failure) { - log(LogLevel::ERROR, "Error binding control socket: ", strerror(errno)); + log(loglevel_t::ERROR, "Error binding control socket: ", strerror(errno)); } close(sockfd); free(name); @@ -484,13 +484,13 @@ void open_control_socket(bool report_ro_failure) noexcept // No connections can be made until we listen, so it is fine to change the permissions now // (and anyway there is no way to atomically create the socket and set permissions): if (chmod(saddrname, S_IRUSR | S_IWUSR) == -1) { - log(LogLevel::ERROR, "Error setting control socket permissions: ", strerror(errno)); + log(loglevel_t::ERROR, "Error setting control socket permissions: ", strerror(errno)); close(sockfd); return; } if (listen(sockfd, 10) == -1) { - log(LogLevel::ERROR, "Error listening on control socket: ", strerror(errno)); + log(loglevel_t::ERROR, "Error listening on control socket: ", strerror(errno)); close(sockfd); return; } @@ -501,7 +501,7 @@ void open_control_socket(bool report_ro_failure) noexcept } catch (std::exception &e) { - log(LogLevel::ERROR, "Could not setup I/O on control socket: ", e.what()); + log(loglevel_t::ERROR, "Could not setup I/O on control socket: ", e.what()); close(sockfd); } } @@ -529,7 +529,7 @@ void setup_external_log() noexcept struct sockaddr_un * name = static_cast(malloc(sockaddr_size)); if (name == nullptr) { - log(LogLevel::ERROR, "Connecting to log socket: out of memory"); + log(loglevel_t::ERROR, "Connecting to log socket: out of memory"); return; } @@ -538,7 +538,7 @@ void setup_external_log() noexcept int sockfd = dinit_socket(AF_UNIX, SOCK_DGRAM, 0, SOCK_NONBLOCK | SOCK_CLOEXEC); if (sockfd == -1) { - log(LogLevel::ERROR, "Error creating log socket: ", strerror(errno)); + log(loglevel_t::ERROR, "Error creating log socket: ", strerror(errno)); free(name); return; } @@ -551,7 +551,7 @@ void setup_external_log() noexcept setup_main_log(sockfd); } catch (std::exception &e) { - log(LogLevel::ERROR, "Setting up log failed: ", e.what()); + log(loglevel_t::ERROR, "Setting up log failed: ", e.what()); close(sockfd); } } @@ -577,7 +577,7 @@ static void sigquit_cb(eventloop_t &eloop) noexcept // This performs an immediate shutdown, without service rollback. close_control_socket(); execl("/sbin/shutdown", "/sbin/shutdown", "--system", (char *) 0); - log(LogLevel::ERROR, "Error executing /sbin/shutdown: ", strerror(errno)); + log(loglevel_t::ERROR, "Error executing /sbin/shutdown: ", strerror(errno)); sync(); // since a hard poweroff might be required at this point... } diff --git a/src/load_service.cc b/src/load_service.cc index 9a6b1d2..5c8a200 100644 --- a/src/load_service.cc +++ b/src/load_service.cc @@ -50,12 +50,12 @@ static string read_setting_name(string_iterator & i, string_iterator end) } namespace { - class SettingException + class setting_exception { std::string info; public: - SettingException(const std::string &&exc_info) : info(std::move(exc_info)) + setting_exception(const std::string &&exc_info) : info(std::move(exc_info)) { } @@ -114,7 +114,7 @@ static string read_setting_value(string_iterator & i, string_iterator end, c = *i; if (c == '\"') break; if (c == '\n') { - throw SettingException("Line end inside quoted string"); + throw setting_exception("Line end inside quoted string"); } else if (c == '\\') { // A backslash escapes the following character. @@ -122,7 +122,7 @@ static string read_setting_value(string_iterator & i, string_iterator end, if (i != end) { c = *i; if (c == '\n') { - throw SettingException("Line end follows backslash escape character (`\\')"); + throw setting_exception("Line end follows backslash escape character (`\\')"); } rval += c; } @@ -134,7 +134,7 @@ static string read_setting_value(string_iterator & i, string_iterator end, } if (i == end) { // String wasn't terminated - throw SettingException("Unterminated quoted string"); + throw setting_exception("Unterminated quoted string"); } } else if (c == '\\') { @@ -148,7 +148,7 @@ static string read_setting_value(string_iterator & i, string_iterator end, rval += *i; } else { - throw SettingException("Backslash escape (`\\') not followed by character"); + throw setting_exception("Backslash escape (`\\') not followed by character"); } } else if (isspace(c, locale::classic())) { @@ -165,7 +165,7 @@ static string read_setting_value(string_iterator & i, string_iterator end, else if (c == '#') { // Possibly intended a comment; we require leading whitespace to reduce occurrence of accidental // comments in setting values. - throw SettingException("hashmark (`#') comment must be separated from setting value by whitespace"); + throw setting_exception("hashmark (`#') comment must be separated from setting value by whitespace"); } else { if (new_part) { @@ -606,7 +606,7 @@ service_record * dirload_service_set::load_service(const char * name) else if (service_type == service_type::SCRIPTED) { auto rvalps = new scripted_service(this, string(name), std::move(command), command_offsets, std::move(depends_on), depends_soft); - rvalps->setStopCommand(stop_command, stop_command_offsets); + rvalps->set_stop_command(stop_command, stop_command_offsets); rvalps->set_stop_timeout(stop_timeout); rval = rvalps; } @@ -615,11 +615,11 @@ service_record * dirload_service_set::load_service(const char * name) std::move(command), command_offsets, std::move(depends_on), depends_soft); } - rval->setLogfile(logfile); - rval->setAutoRestart(auto_restart); - rval->setSmoothRecovery(smooth_recovery); - rval->setOnstartFlags(onstart_flags); - rval->setExtraTerminationSignal(term_signal); + rval->set_log_file(logfile); + rval->set_auto_restart(auto_restart); + rval->set_smooth_recovery(smooth_recovery); + rval->set_flags(onstart_flags); + rval->set_extra_termination_signal(term_signal); rval->set_socket_details(std::move(socket_path), socket_perms, socket_uid, socket_gid); *iter = rval; break; @@ -628,7 +628,7 @@ service_record * dirload_service_set::load_service(const char * name) return rval; } - catch (SettingException &setting_exc) + catch (setting_exception &setting_exc) { // Must remove the dummy service record. std::remove(records.begin(), records.end(), rval); diff --git a/src/service.cc b/src/service.cc index 7b20e43..d806085 100644 --- a/src/service.cc +++ b/src/service.cc @@ -36,7 +36,7 @@ static service_record * find_service(const std::list & records using std::list; list::const_iterator i = records.begin(); for ( ; i != records.end(); i++ ) { - if (strcmp((*i)->getServiceName().c_str(), name) == 0) { + if (strcmp((*i)->get_service_name().c_str(), name) == 0) { return *i; } } @@ -169,11 +169,11 @@ void process_service::handle_exit_status(int exit_status) noexcept if (exit_status != 0 && service_state != service_state_t::STOPPING) { if (did_exit) { - log(LogLevel::ERROR, "Service ", service_name, " process terminated with exit code ", + log(loglevel_t::ERROR, "Service ", service_name, " process terminated with exit code ", WEXITSTATUS(exit_status)); } else if (was_signalled) { - log(LogLevel::ERROR, "Service ", service_name, " terminated due to signal ", + log(loglevel_t::ERROR, "Service ", service_name, " terminated due to signal ", WTERMSIG(exit_status)); } } @@ -218,11 +218,11 @@ void bgproc_service::handle_exit_status(int exit_status) noexcept if (exit_status != 0 && service_state != service_state_t::STOPPING) { if (did_exit) { - log(LogLevel::ERROR, "Service ", service_name, " process terminated with exit code ", + log(loglevel_t::ERROR, "Service ", service_name, " process terminated with exit code ", WEXITSTATUS(exit_status)); } else if (was_signalled) { - log(LogLevel::ERROR, "Service ", service_name, " terminated due to signal ", + log(loglevel_t::ERROR, "Service ", service_name, " terminated due to signal ", WTERMSIG(exit_status)); } } @@ -319,11 +319,11 @@ void scripted_service::handle_exit_status(int exit_status) noexcept else { // ??? failed to stop! Let's log it as info: if (did_exit) { - log(LogLevel::INFO, "Service ", service_name, " stop command failed with exit code ", + log(loglevel_t::INFO, "Service ", service_name, " stop command failed with exit code ", WEXITSTATUS(exit_status)); } else if (was_signalled) { - log(LogLevel::INFO, "Serivice ", service_name, " stop command terminated due to signal ", + log(loglevel_t::INFO, "Serivice ", service_name, " stop command terminated due to signal ", WTERMSIG(exit_status)); } // Just assume that we stopped, so that any dependencies @@ -339,11 +339,11 @@ void scripted_service::handle_exit_status(int exit_status) noexcept else { // failed to start if (did_exit) { - log(LogLevel::ERROR, "Service ", service_name, " command failed with exit code ", + log(loglevel_t::ERROR, "Service ", service_name, " command failed with exit code ", WEXITSTATUS(exit_status)); } else if (was_signalled) { - log(LogLevel::ERROR, "Service ", service_name, " command terminated due to signal ", + log(loglevel_t::ERROR, "Service ", service_name, " command terminated due to signal ", WTERMSIG(exit_status)); } failed_to_start(); @@ -373,7 +373,7 @@ rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) n } } sr->pid = -1; - log(LogLevel::ERROR, sr->service_name, ": execution failed: ", strerror(exec_status)); + log(loglevel_t::ERROR, sr->service_name, ": execution failed: ", strerror(exec_status)); if (sr->service_state == service_state_t::STARTING) { sr->failed_to_start(); } @@ -441,7 +441,7 @@ void service_record::release_dependencies() noexcept } for (auto i = soft_deps.begin(); i != soft_deps.end(); ++i) { - service_record * to = i->getTo(); + service_record * to = i->get_to(); if (i->holding_acq) { to->release(); i->holding_acq = false; @@ -493,7 +493,7 @@ void service_record::do_propagation() noexcept } for (auto i = soft_deps.begin(); i != soft_deps.end(); ++i) { - service_record * to = i->getTo(); + service_record * to = i->get_to(); to->require(); i->holding_acq = true; } @@ -584,7 +584,7 @@ bool service_record::start_check_dependencies(bool start_deps) noexcept } for (auto i = soft_deps.begin(); i != soft_deps.end(); ++i) { - service_record * to = i->getTo(); + service_record * to = i->get_to(); if (start_deps) { if (to->service_state != service_state_t::STARTED) { to->prop_start = true; @@ -625,13 +625,13 @@ bool service_record::open_socket() noexcept if (stat(saddrname, &stat_buf) == 0) { if ((stat_buf.st_mode & S_IFSOCK) == 0) { // Not a socket - log(LogLevel::ERROR, service_name, ": Activation socket file exists (and is not a socket)"); + log(loglevel_t::ERROR, service_name, ": Activation socket file exists (and is not a socket)"); return false; } } else if (errno != ENOENT) { // Other error - log(LogLevel::ERROR, service_name, ": Error checking activation socket: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": Error checking activation socket: ", strerror(errno)); return false; } @@ -643,7 +643,7 @@ bool service_record::open_socket() noexcept uint sockaddr_size = offsetof(struct sockaddr_un, sun_path) + socket_path.length() + 1; struct sockaddr_un * name = static_cast(malloc(sockaddr_size)); if (name == nullptr) { - log(LogLevel::ERROR, service_name, ": Opening activation socket: out of memory"); + log(loglevel_t::ERROR, service_name, ": Opening activation socket: out of memory"); return false; } @@ -652,13 +652,13 @@ bool service_record::open_socket() noexcept int sockfd = dinit_socket(AF_UNIX, SOCK_STREAM, 0, SOCK_NONBLOCK | SOCK_CLOEXEC); if (sockfd == -1) { - log(LogLevel::ERROR, service_name, ": Error creating activation socket: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": Error creating activation socket: ", strerror(errno)); free(name); return false; } if (bind(sockfd, (struct sockaddr *) name, sockaddr_size) == -1) { - log(LogLevel::ERROR, service_name, ": Error binding activation socket: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": Error binding activation socket: ", strerror(errno)); close(sockfd); free(name); return false; @@ -669,19 +669,19 @@ bool service_record::open_socket() noexcept // POSIX (1003.1, 2013) says that fchown and fchmod don't necessarily work on sockets. We have to // use chown and chmod instead. if (chown(saddrname, socket_uid, socket_gid)) { - log(LogLevel::ERROR, service_name, ": Error setting activation socket owner/group: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": Error setting activation socket owner/group: ", strerror(errno)); close(sockfd); return false; } if (chmod(saddrname, socket_perms) == -1) { - log(LogLevel::ERROR, service_name, ": Error setting activation socket permissions: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": Error setting activation socket permissions: ", strerror(errno)); close(sockfd); return false; } if (listen(sockfd, 128) == -1) { // 128 "seems reasonable". - log(LogLevel::ERROR, ": Error listening on activation socket: ", strerror(errno)); + log(loglevel_t::ERROR, ": Error listening on activation socket: ", strerror(errno)); close(sockfd); return false; } @@ -738,7 +738,7 @@ bgproc_service::read_pid_file(int *exit_status) noexcept const char *pid_file_c = pid_file.c_str(); int fd = open(pid_file_c, O_CLOEXEC); if (fd == -1) { - log(LogLevel::ERROR, service_name, ": read pid file: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": read pid file: ", strerror(errno)); return pid_result_t::FAILED; } @@ -746,7 +746,7 @@ bgproc_service::read_pid_file(int *exit_status) noexcept int r = ss_read(fd, pidbuf, 20); if (r < 0) { // Could not read from PID file - log(LogLevel::ERROR, service_name, ": could not read from pidfile; ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": could not read from pidfile; ", strerror(errno)); close(fd); return pid_result_t::FAILED; } @@ -778,7 +778,7 @@ bgproc_service::read_pid_file(int *exit_status) noexcept return pid_result_t::OK; } else { - log(LogLevel::ERROR, service_name, ": pid read from pidfile (", pid, ") is not valid"); + log(loglevel_t::ERROR, service_name, ": pid read from pidfile (", pid, ") is not valid"); pid = -1; return pid_result_t::FAILED; } @@ -796,7 +796,7 @@ bgproc_service::read_pid_file(int *exit_status) noexcept } } - log(LogLevel::ERROR, service_name, ": pid read from pidfile (", pid, ") is not valid"); + log(loglevel_t::ERROR, service_name, ": pid read from pidfile (", pid, ") is not valid"); pid = -1; return pid_result_t::FAILED; } @@ -830,7 +830,7 @@ void service_record::started() noexcept (*i)->dependencyStarted(); } for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) { - (*i)->getFrom()->dependencyStarted(); + (*i)->get_from()->dependencyStarted(); } } @@ -862,7 +862,7 @@ void service_record::failed_to_start(bool depfailed) noexcept if ((*i)->waiting_on) { (*i)->holding_acq = false; (*i)->waiting_on = false; - (*i)->getFrom()->dependencyStarted(); + (*i)->get_from()->dependencyStarted(); release(); } } @@ -898,7 +898,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd int pipefd[2]; if (pipe2(pipefd, O_CLOEXEC)) { - log(LogLevel::ERROR, service_name, ": can't create status check pipe: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": can't create status check pipe: ", strerror(errno)); return false; } @@ -913,7 +913,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd int control_socket[2] = {-1, -1}; if (onstart_flags.pass_cs_fd) { if (dinit_socketpair(AF_UNIX, SOCK_STREAM, /* protocol */ 0, control_socket, SOCK_NONBLOCK)) { - log(LogLevel::ERROR, service_name, ": can't create control socket: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": can't create control socket: ", strerror(errno)); goto out_p; } @@ -925,7 +925,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd control_conn = new control_conn_t(&eventLoop, services, control_socket[0]); } catch (std::exception &exc) { - log(LogLevel::ERROR, service_name, ": can't launch process; out of memory"); + log(loglevel_t::ERROR, service_name, ": can't launch process; out of memory"); goto out_cs; } } @@ -946,7 +946,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd reserved_child_watch = true; } catch (std::exception &e) { - log(LogLevel::ERROR, service_name, ": Could not fork: ", e.what()); + log(loglevel_t::ERROR, service_name, ": Could not fork: ", e.what()); goto out_cs_h; } @@ -1227,7 +1227,7 @@ void base_process_service::kill_pg(int signo) noexcept pid_t pgid = getpgid(pid); if (pgid == -1) { // only should happen if pid is invalid, which should never happen... - log(LogLevel::ERROR, service_name, ": can't signal process: ", strerror(errno)); + log(loglevel_t::ERROR, service_name, ": can't signal process: ", strerror(errno)); return; } kill(-pgid, signo); @@ -1393,7 +1393,7 @@ bool base_process_service::restart_ps_process() noexcept time_val int_diff = current_time - restart_interval_time; if (int_diff < restart_interval) { if (restart_interval_count >= max_restart_interval_count) { - log(LogLevel::ERROR, "Service ", service_name, " restarting too quickly; stopping."); + log(loglevel_t::ERROR, "Service ", service_name, " restarting too quickly; stopping."); return false; } } @@ -1430,7 +1430,7 @@ void base_process_service::interrupt_start() noexcept void base_process_service::kill_with_fire() noexcept { if (pid != -1) { - log(LogLevel::WARN, "Service ", service_name, "with pid ", pid, " exceeded allowed stop time; killing."); + log(loglevel_t::WARN, "Service ", service_name, "with pid ", pid, " exceeded allowed stop time; killing."); kill_pg(SIGKILL); } } diff --git a/src/service.h b/src/service.h index a1eb686..46b08ea 100644 --- a/src/service.h +++ b/src/service.h @@ -178,12 +178,12 @@ class service_dep service_dep(service_record * from, service_record * to) noexcept : from(from), to(to), waiting_on(false), holding_acq(false) { } - service_record * getFrom() noexcept + service_record * get_from() noexcept { return from; } - service_record * getTo() noexcept + service_record * get_to() noexcept { return to; } @@ -482,43 +482,43 @@ class service_record 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) + 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 getTargetState() noexcept + service_state_t get_target_state() noexcept { return desired_state; } // Set logfile, should be done before service is started - void setLogfile(string logfile) + void set_log_file(string logfile) { this->logfile = logfile; } // Set whether this service should automatically restart when it dies - void setAutoRestart(bool auto_restart) noexcept + void set_auto_restart(bool auto_restart) noexcept { this->auto_restart = auto_restart; } - void setSmoothRecovery(bool smooth_recovery) noexcept + void set_smooth_recovery(bool smooth_recovery) noexcept { this->smooth_recovery = smooth_recovery; } // Set "on start" flags (commands) - void setOnstartFlags(onstart_flags_t flags) noexcept + void set_flags(onstart_flags_t flags) noexcept { this->onstart_flags = flags; } // Set an additional signal (other than SIGTERM) to be used to terminate the process - void setExtraTerminationSignal(int signo) noexcept + void set_extra_termination_signal(int signo) noexcept { this->term_signal = signo; } @@ -536,7 +536,7 @@ class service_record this->socket_gid = socket_gid; } - const std::string &getServiceName() const noexcept { return service_name; } + const std::string &get_service_name() const noexcept { return service_name; } service_state_t get_state() const noexcept { return service_state; } void start(bool activate = true) noexcept; // start the service @@ -545,13 +545,13 @@ class service_record 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 + void pin_start() noexcept { pinned_started = true; } // Pin the service in "stopped" state (when it reaches the state) - void pinStop() noexcept + void pin_stop() noexcept { pinned_stopped = true; } -- 2.25.1