std::vector<char> rp_buf;
rp_buf.reserve(7);
rp_buf.push_back(DINIT_RP_SERVICERECORD);
- rp_buf.push_back(static_cast<char>(record->getState()));
+ rp_buf.push_back(static_cast<char>(record->get_state()));
for (int i = 0; i < (int) sizeof(handle); i++) {
rp_buf.push_back(*(((char *) &handle) + i));
}
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;
}
pkt_buf[0] = DINIT_RP_SVCINFO;
pkt_buf[1] = nameLen;
- pkt_buf[2] = static_cast<char>(sptr->getState());
+ pkt_buf[2] = static_cast<char>(sptr->get_state());
pkt_buf[3] = static_cast<char>(sptr->getTargetState());
pkt_buf[4] = 0; // reserved
}
// 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];
}
// 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);
}
}
-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");
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
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 <typename A> static inline void logParts(A a) noexcept
+ template <typename A> static inline void log_parts(A a) noexcept
{
- logMsgEnd(a);
+ log_msg_end(a);
}
- template <typename A, typename ...B> static inline void logParts(A a, B... b) noexcept
+ template <typename A, typename ...B> 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 <typename A, typename ...B> 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
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.");
}
}
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) {
}
}
- logServiceStopped(service_name);
+ log_service_stopped(service_name);
notify_listeners(service_event::STOPPED);
}
start_explicit = false;
release();
}
- forceStop();
+ forced_stop();
stop_dependents();
stopped();
}
start_explicit = false;
release();
}
- forceStop();
+ forced_stop();
stop_dependents();
stopped();
}
if (required_by++ == 0) {
prop_require = !prop_release;
prop_release = false;
- services->addToPropQueue(this);
+ services->add_prop_queue(this);
}
}
// 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);
waiting_for_deps = true;
if (start_check_dependencies(true)) {
- services->addToStartQueue(this);
+ services->add_transition_queue(this);
}
}
{
if ((service_state == service_state_t::STARTING || service_state == service_state_t::STARTED)
&& waiting_for_deps) {
- services->addToStartQueue(this);
+ services->add_transition_queue(this);
}
}
if (start_deps) {
all_deps_started = false;
(*i)->prop_start = true;
- services->addToPropQueue(*i);
+ services->add_prop_queue(*i);
}
else {
return false;
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;
}
}
}
-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.
release_console();
}
- logServiceStarted(service_name);
+ log_service_started(service_name);
service_state = service_state_t::STARTED;
notify_listeners(service_event::STARTED);
release_console();
}
- logServiceFailed(service_name);
+ log_service_failed(service_name);
service_state = service_state_t::STOPPED;
if (start_explicit) {
start_explicit = false;
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++) {
}
// 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);
}
}
service_state = service_state_t::STOPPING;
waiting_for_deps = true;
if (stop_dependents()) {
- services->addToStopQueue(this);
+ services->add_transition_queue(this);
}
}
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;
}
else {
desired_state = service_state_t::STOPPED;
- forceStop();
+ forced_stop();
}
services->process_queues();
}
}
}
- // 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;
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,
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<std::pair<unsigned,unsigned>> &stop_command_offsets)
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
{
}
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
// 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);
}
else {
service_record * front = console_queue.pop_front();
- front->acquiredConsole();
+ front->acquired_console();
}
}