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 {
for (int i = 0; i < (int) sizeof(handle); i++) {
rp_buf.push_back(*(((char *) &handle) + i));
}
- rp_buf.push_back(static_cast<char>(record->getTargetState()));
+ rp_buf.push_back(static_cast<char>(record->get_target_state()));
if (! queuePacket(std::move(rp_buf))) return false;
}
else {
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();
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;
for (auto sptr : slist) {
std::vector<char> 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<char>(sptr->get_state());
- pkt_buf[3] = static_cast<char>(sptr->getTargetState());
+ pkt_buf[3] = static_cast<char>(sptr->get_target_state());
pkt_buf[4] = 0; // reserved
pkt_buf[5] = 0;
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
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
// 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;
}
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);
}
// 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;
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
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: ;
}
}
// Variadic method to potentially log a sequence of strings as a single message with the given log level:
-template <typename ... T> static void do_log(LogLevel lvl, T ... args) noexcept
+template <typename ... T> 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];
}
// 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");
}
}
// 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];
class service_set;
-enum class LogLevel {
+enum class loglevel_t {
DEBUG,
INFO,
WARN,
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;
// 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];
}
// Variadic 'log' method.
-template <typename A, typename ...B> static inline void log(LogLevel lvl, A a, B ...b) noexcept
+template <typename A, typename ...B> static inline void log(loglevel_t lvl, A a, B ...b) noexcept
{
log_msg_begin(lvl, a);
dinit_log::log_parts(b...);
// 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;
}
}
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.");
}
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;
}
// 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) {
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);
}
}
struct sockaddr_un * name = static_cast<sockaddr_un *>(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;
}
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);
// 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;
}
}
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);
}
}
struct sockaddr_un * name = static_cast<sockaddr_un *>(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;
}
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;
}
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);
}
}
// 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...
}
}
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))
{
}
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.
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;
}
}
if (i == end) {
// String wasn't terminated
- throw SettingException("Unterminated quoted string");
+ throw setting_exception("Unterminated quoted string");
}
}
else if (c == '\\') {
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())) {
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) {
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;
}
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;
return rval;
}
- catch (SettingException &setting_exc)
+ catch (setting_exception &setting_exc)
{
// Must remove the dummy service record.
std::remove(records.begin(), records.end(), rval);
using std::list;
list<service_record *>::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;
}
}
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));
}
}
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));
}
}
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
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();
}
}
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();
}
}
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;
}
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;
}
}
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;
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;
}
uint sockaddr_size = offsetof(struct sockaddr_un, sun_path) + socket_path.length() + 1;
struct sockaddr_un * name = static_cast<sockaddr_un *>(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;
}
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;
// 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;
}
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;
}
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;
}
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;
}
}
}
- 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;
}
(*i)->dependencyStarted();
}
for (auto i = soft_dpts.begin(); i != soft_dpts.end(); i++) {
- (*i)->getFrom()->dependencyStarted();
+ (*i)->get_from()->dependencyStarted();
}
}
if ((*i)->waiting_on) {
(*i)->holding_acq = false;
(*i)->waiting_on = false;
- (*i)->getFrom()->dependencyStarted();
+ (*i)->get_from()->dependencyStarted();
release();
}
}
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;
}
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;
}
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;
}
}
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;
}
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);
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;
}
}
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);
}
}
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;
}
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)
+ void set_stop_command(std::string command, std::list<std::pair<unsigned,unsigned>> &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;
}
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
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;
}