From: Davin McCall Date: Tue, 9 Jan 2018 17:37:34 +0000 (+0000) Subject: Big rename/namespace cleanup. X-Git-Tag: v0.08~60 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0ffc42b97d30777a53d7d14f5df5e9d78f6060c4;p=oweals%2Fdinit.git Big rename/namespace cleanup. --- diff --git a/src/control.cc b/src/control.cc index a5c1e13..395ae49 100644 --- a/src/control.cc +++ b/src/control.cc @@ -1,6 +1,11 @@ #include "control.h" #include "service.h" +namespace { + constexpr auto OUT_EVENTS = dasynq::OUT_EVENTS; + constexpr auto IN_EVENTS = dasynq::IN_EVENTS; +} + bool control_conn_t::process_packet() { using std::string; diff --git a/src/control.h b/src/control.h index efcd72a..7111d5f 100644 --- a/src/control.h +++ b/src/control.h @@ -18,14 +18,13 @@ // Control connection for dinit -using namespace dasynq; -using eventloop_t = event_loop; +using eventloop_t = dasynq::event_loop; class control_conn_t; class control_conn_watcher; // forward-declaration of callback: -static rearm control_conn_cb(eventloop_t *loop, control_conn_watcher *watcher, int revents); +static dasynq::rearm control_conn_cb(eventloop_t *loop, control_conn_watcher *watcher, int revents); // Pointer to the control connection that is listening for rollback completion extern control_conn_t * rollback_handler_conn; @@ -49,6 +48,7 @@ class service_record; class control_conn_watcher : public eventloop_t::bidi_fd_watcher_impl { + using rearm = dasynq::rearm; inline rearm receive_event(eventloop_t &loop, int fd, int flags) noexcept; eventloop_t * event_loop; @@ -61,12 +61,12 @@ class control_conn_watcher : public eventloop_t::bidi_fd_watcher_impl(cc_addr); _Pragma ("GCC diagnostic pop") - if (revents & IN_EVENTS) { + if (revents & dasynq::IN_EVENTS) { if (conn->data_ready()) { delete conn; - return rearm::REMOVED; + return dasynq::rearm::REMOVED; } } - if (revents & OUT_EVENTS) { + if (revents & dasynq::OUT_EVENTS) { if (conn->send_data()) { delete conn; - return rearm::REMOVED; + return dasynq::rearm::REMOVED; } } - return rearm::NOOP; + return dasynq::rearm::NOOP; } #endif diff --git a/src/dinit-log.cc b/src/dinit-log.cc index a67e5d3..f2c39e0 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -12,13 +12,15 @@ #include "dinit-log.h" #include "cpbuffer.h" -extern eventloop_t eventLoop; +extern eventloop_t event_loop; static bool log_current_line[2]; // Whether the current line is being logged (for console, main log) loglevel_t log_level[2] = { loglevel_t::WARN, loglevel_t::WARN }; static service_set *services = nullptr; // Reference to service set +using rearm = dasynq::rearm; + namespace { class BufferedLogStream : public eventloop_t::fd_watcher_impl { @@ -63,7 +65,7 @@ class BufferedLogStream : public eventloop_t::fd_watcher_impl bool was_first = current_index == 0; current_index = log_buffer.get_length(); if (was_first && ! release) { - set_enabled(eventLoop, true); + set_enabled(event_loop, true); } } @@ -119,9 +121,9 @@ void BufferedLogStream::flushForRelease() // Try to flush any messages that are currently buffered. (Console is non-blocking // so it will fail gracefully). - if (fd_event(eventLoop, fd, OUT_EVENTS) == rearm::DISARM) { + if (fd_event(event_loop, fd, dasynq::OUT_EVENTS) == rearm::DISARM) { // Console has already been released at this point. - set_enabled(eventLoop, false); + set_enabled(event_loop, false); } // fd_event didn't want to disarm, so must be partway through a message; will // release when it's finished. @@ -237,7 +239,7 @@ rearm BufferedLogStream::fd_event(eventloop_t &loop, int fd, int flags) noexcept void init_log(service_set *sset) { services = sset; - log_stream[DLOG_CONS].add_watch(eventLoop, STDOUT_FILENO, OUT_EVENTS, false); + log_stream[DLOG_CONS].add_watch(event_loop, STDOUT_FILENO, dasynq::OUT_EVENTS, false); enable_console_log(true); } @@ -246,7 +248,7 @@ void init_log(service_set *sset) void setup_main_log(int fd) { log_stream[DLOG_MAIN].init(fd); - log_stream[DLOG_MAIN].add_watch(eventLoop, fd, OUT_EVENTS); + log_stream[DLOG_MAIN].add_watch(event_loop, fd, dasynq::OUT_EVENTS); } bool is_log_flushed() noexcept @@ -267,7 +269,7 @@ void enable_console_log(bool enable) noexcept fcntl(1, F_SETFL, flags | O_NONBLOCK); // Activate watcher: log_stream[DLOG_CONS].init(STDOUT_FILENO); - log_stream[DLOG_CONS].set_enabled(eventLoop, true); + log_stream[DLOG_CONS].set_enabled(event_loop, true); } else if (! enable && log_to_console) { log_stream[DLOG_CONS].flushForRelease(); diff --git a/src/dinit.cc b/src/dinit.cc index 52c51c8..fd946e7 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -37,10 +37,9 @@ * services even if the halt/reboot commands are unavailable for some reason. */ -using namespace dasynq; -using eventloop_t = event_loop; +using eventloop_t = dasynq::event_loop; -eventloop_t eventLoop; +eventloop_t event_loop; static void sigint_reboot_cb(eventloop_t &eloop) noexcept; static void sigquit_cb(eventloop_t &eloop) noexcept; @@ -94,6 +93,8 @@ const char * get_user_home() namespace { class callback_signal_handler : public eventloop_t::signal_watcher_impl { + using rearm = dasynq::rearm; + public: typedef void (*cb_func_t)(eventloop_t &); @@ -118,6 +119,8 @@ namespace { class control_socket_watcher : public eventloop_t::fd_watcher_impl { + using rearm = dasynq::rearm; + public: rearm fd_event(eventloop_t &loop, int fd, int flags) noexcept { @@ -278,12 +281,12 @@ int dinit_main(int argc, char **argv) sigint_watcher.setCbFunc(sigterm_cb); } - sigint_watcher.add_watch(eventLoop, SIGINT); - sigterm_watcher.add_watch(eventLoop, SIGTERM); + sigint_watcher.add_watch(event_loop, SIGINT); + sigterm_watcher.add_watch(event_loop, SIGTERM); if (am_system_init) { // PID 1: SIGQUIT exec's shutdown - sigquit_watcher.add_watch(eventLoop, SIGQUIT); + sigquit_watcher.add_watch(event_loop, SIGQUIT); // As a user process, we instead just let SIGQUIT perform the default action. } @@ -332,7 +335,7 @@ int dinit_main(int argc, char **argv) // Process events until all services have terminated. while (services->count_active_services() != 0) { - eventLoop.run(); + event_loop.run(); } shutdown_type_t shutdown_type = services->getShutdownType(); @@ -355,7 +358,7 @@ int dinit_main(int argc, char **argv) } while (! is_log_flushed()) { - eventLoop.run(); + event_loop.run(); } close_control_socket(); @@ -395,7 +398,7 @@ int dinit_main(int argc, char **argv) // PID 1 must not actually exit, although we should never reach this point: while (true) { - eventLoop.run(); + event_loop.run(); } } else if (shutdown_type == shutdown_type_t::REBOOT) { @@ -496,7 +499,7 @@ void open_control_socket(bool report_ro_failure) noexcept } try { - control_socket_io.add_watch(eventLoop, sockfd, IN_EVENTS); + control_socket_io.add_watch(event_loop, sockfd, dasynq::IN_EVENTS); control_socket_open = true; } catch (std::exception &e) @@ -511,7 +514,7 @@ static void close_control_socket() noexcept { if (control_socket_open) { int fd = control_socket_io.get_watched_fd(); - control_socket_io.deregister(eventLoop); + control_socket_io.deregister(event_loop); close(fd); // Unlink the socket: diff --git a/src/service.cc b/src/service.cc index 6fb72d1..16af9f3 100644 --- a/src/service.cc +++ b/src/service.cc @@ -27,7 +27,11 @@ // from dinit.cc: void open_control_socket(bool report_ro_failure = true) noexcept; void setup_external_log() noexcept; -extern eventloop_t eventLoop; +extern eventloop_t event_loop; + +using clock_type = dasynq::clock_type; +using rearm = dasynq::rearm; +using time_val = dasynq::time_val; // Find the requested service by name static service_record * find_service(const std::list & records, @@ -128,7 +132,7 @@ dasynq::rearm service_child_watcher::status_change(eventloop_t &loop, pid_t chil if (sr->waiting_for_execstat) { // We still don't have an exec() status from the forked child, wait for that // before doing any further processing. - return rearm::NOOP; // hold watch reservation + return dasynq::rearm::NOOP; // hold watch reservation } // Must stop watch now since handle_exit_status might result in re-launch: @@ -141,7 +145,7 @@ dasynq::rearm service_child_watcher::status_change(eventloop_t &loop, pid_t chil } sr->handle_exit_status(status); - return rearm::NOOP; + return dasynq::rearm::NOOP; } bool service_record::do_auto_restart() noexcept @@ -432,7 +436,7 @@ rearm exec_status_pipe_watcher::fd_event(eventloop_t &loop, int fd, int flags) n if (r > 0) { // We read an errno code; exec() failed, and the service startup failed. if (sr->pid != -1) { - sr->child_listener.deregister(eventLoop, sr->pid); + sr->child_listener.deregister(event_loop, sr->pid); sr->reserved_child_watch = false; if (sr->stop_timer_armed) { sr->restart_timer.stop_timer(loop); @@ -829,7 +833,7 @@ bgproc_service::read_pid_file(int *exit_status) noexcept } else if (wait_r == 0) { // We can track the child - child_listener.add_reserved(eventLoop, pid, DEFAULT_PRIORITY - 10); + child_listener.add_reserved(event_loop, pid, dasynq::DEFAULT_PRIORITY - 10); tracking_child = true; reserved_child_watch = true; return pid_result_t::OK; @@ -927,15 +931,15 @@ bool base_process_service::bring_up() noexcept return true; } else { - eventLoop.get_time(restart_interval_time, clock_type::MONOTONIC); + event_loop.get_time(restart_interval_time, clock_type::MONOTONIC); restart_interval_count = 0; if (start_ps_process(exec_arg_parts, onstart_flags.starts_on_console)) { if (start_timeout != time_val(0,0)) { - restart_timer.arm_timer_rel(eventLoop, start_timeout); + restart_timer.arm_timer_rel(event_loop, start_timeout); stop_timer_armed = true; } else if (stop_timer_armed) { - restart_timer.stop_timer(eventLoop); + restart_timer.stop_timer(event_loop); stop_timer_armed = false; } return true; @@ -951,10 +955,10 @@ bool base_process_service::start_ps_process(const std::vector &cmd // exec closes the pipe, and the parent sees EOF. If the exec is unsuccessful, the errno // is written to the pipe, and the parent can read it. - eventLoop.get_time(last_start_time, clock_type::MONOTONIC); + event_loop.get_time(last_start_time, clock_type::MONOTONIC); int pipefd[2]; - if (pipe2(pipefd, O_CLOEXEC)) { + if (dasynq::pipe2(pipefd, O_CLOEXEC)) { log(loglevel_t::ERROR, get_name(), ": can't create status check pipe: ", strerror(errno)); return false; } @@ -979,7 +983,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd fcntl(control_socket[0], F_SETFD, fdflags | FD_CLOEXEC); try { - control_conn = new control_conn_t(eventLoop, services, control_socket[0]); + control_conn = new control_conn_t(event_loop, services, control_socket[0]); } catch (std::exception &exc) { log(loglevel_t::ERROR, get_name(), ": can't launch process; out of memory"); @@ -992,14 +996,14 @@ bool base_process_service::start_ps_process(const std::vector &cmd pid_t forkpid; try { - child_status_listener.add_watch(eventLoop, pipefd[0], IN_EVENTS); + child_status_listener.add_watch(event_loop, pipefd[0], dasynq::IN_EVENTS); child_status_registered = true; // We specify a high priority (i.e. low priority value) so that process termination is // handled early. This means we have always recorded that the process is terminated by the // time that we handle events that might otherwise cause us to signal the process, so we // avoid sending a signal to an invalid (and possibly recycled) process ID. - forkpid = child_listener.fork(eventLoop, reserved_child_watch, DEFAULT_PRIORITY - 10); + forkpid = child_listener.fork(event_loop, reserved_child_watch, dasynq::DEFAULT_PRIORITY - 10); reserved_child_watch = true; } catch (std::exception &e) { @@ -1026,7 +1030,7 @@ bool base_process_service::start_ps_process(const std::vector &cmd out_cs_h: if (child_status_registered) { - child_status_listener.deregister(eventLoop); + child_status_listener.deregister(event_loop); } if (onstart_flags.pass_cs_fd) { @@ -1315,7 +1319,7 @@ void base_process_service::bring_down() noexcept stopped(); } else if (stop_timeout != time_val(0,0)) { - restart_timer.arm_timer_rel(eventLoop, stop_timeout); + restart_timer.arm_timer_rel(event_loop, stop_timeout); stop_timer_armed = true; } } @@ -1352,7 +1356,7 @@ void process_service::bring_down() noexcept stopped(); } else if (stop_timeout != time_val(0,0)) { - restart_timer.arm_timer_rel(eventLoop, stop_timeout); + restart_timer.arm_timer_rel(event_loop, stop_timeout); stop_timer_armed = true; } } @@ -1375,7 +1379,7 @@ void scripted_service::bring_down() noexcept else { // successfully started stop script: start kill timer: if (stop_timeout != time_val(0,0)) { - restart_timer.arm_timer_rel(eventLoop, stop_timeout); + restart_timer.arm_timer_rel(event_loop, stop_timeout); stop_timer_armed = true; } } @@ -1438,7 +1442,7 @@ base_process_service::base_process_service(service_set *sset, string name, restart_interval_count = 0; restart_interval_time = {0, 0}; restart_timer.service = this; - restart_timer.add_timer(eventLoop); + restart_timer.add_timer(event_loop); // By default, allow a maximum of 3 restarts within 10.0 seconds: restart_interval.seconds() = 10; @@ -1490,7 +1494,7 @@ bool base_process_service::restart_ps_process() noexcept using time_val = dasynq::time_val; time_val current_time; - eventLoop.get_time(current_time, clock_type::MONOTONIC); + event_loop.get_time(current_time, clock_type::MONOTONIC); if (max_restart_interval_count != 0) { // Check whether we're still in the most recent restart check interval: @@ -1515,7 +1519,7 @@ bool base_process_service::restart_ps_process() noexcept } else { time_val timeout = restart_delay - tdiff; - restart_timer.arm_timer_rel(eventLoop, timeout); + restart_timer.arm_timer_rel(event_loop, timeout); waiting_restart_timer = true; } return true; @@ -1524,7 +1528,7 @@ bool base_process_service::restart_ps_process() noexcept bool base_process_service::interrupt_start() noexcept { if (waiting_restart_timer) { - restart_timer.stop_timer(eventLoop); + restart_timer.stop_timer(event_loop); waiting_restart_timer = false; return service_record::interrupt_start(); } @@ -1532,11 +1536,11 @@ bool base_process_service::interrupt_start() noexcept log(loglevel_t::WARN, "Interrupting start of service ", get_name(), " with pid ", pid, " (with SIGINT)."); kill_pg(SIGINT); if (stop_timeout != time_val(0,0)) { - restart_timer.arm_timer(eventLoop, stop_timeout); + restart_timer.arm_timer(event_loop, stop_timeout); stop_timer_armed = true; } else if (stop_timer_armed) { - restart_timer.stop_timer(eventLoop); + restart_timer.stop_timer(event_loop); stop_timer_armed = false; } set_state(service_state_t::STOPPING); diff --git a/src/service.h b/src/service.h index 8e10a21..2e77a79 100644 --- a/src/service.h +++ b/src/service.h @@ -241,7 +241,7 @@ class service_child_watcher : public eventloop_t::child_proc_watcher_impl