From: Davin McCall Date: Wed, 3 Jul 2019 09:50:52 +0000 (+1000) Subject: Add -q/--quiet option for supressing console output. X-Git-Tag: v0.6.0~16 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=522efc0618a538b61a40bcaa4876e3449ffd7632;p=oweals%2Fdinit.git Add -q/--quiet option for supressing console output. --- diff --git a/doc/manpages/dinit.8 b/doc/manpages/dinit.8 index d8b2d53..91f2556 100644 --- a/doc/manpages/dinit.8 +++ b/doc/manpages/dinit.8 @@ -71,6 +71,10 @@ socket path. Run as a user. This is the opposite of \fB\-\-system\fR, and is the default if not invoked as the root user. .TP +\fB\-q\fR, \fB\-\-quiet\fR +Run with no output to the terminal/console. This disables service status messages +and sets the log level for the console log to \fBNONE\fR. +.TP \fB\-\-help\fR display this help and exit .TP diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 09e4e78..fd15e22 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -28,11 +28,13 @@ 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::INFO, loglevel_t::WARN }; static bool log_format_syslog[2] = { false, true }; static service_set *services = nullptr; // Reference to service set +loglevel_t log_level[2] = { loglevel_t::INFO, loglevel_t::WARN }; +bool console_service_status = true; // show service status messages to console? + dasynq::time_val release_time; // time the log was released using rearm = dasynq::rearm; @@ -121,9 +123,6 @@ class buffered_log_stream : public eventloop_t::fd_watcher_impl static void do_log(loglevel_t lvl, bool to_cons, T ... template static void do_log_cons(T ... args) noexcept { - log_current_line[DLOG_CONS] = true; - log_current_line[DLOG_MAIN] = false; - push_to_log(DLOG_CONS, args...); + if (console_service_status) { + log_current_line[DLOG_CONS] = true; + log_current_line[DLOG_MAIN] = false; + push_to_log(DLOG_CONS, args...); + } } // Log to the main facility at NOTICE level diff --git a/src/dinit.cc b/src/dinit.cc index d9e2836..5e87ccc 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -260,6 +260,10 @@ int dinit_main(int argc, char **argv) return 1; } } + else if (strcmp(argv[i], "--quiet") == 0 || strcmp(argv[i], "-q") == 0) { + console_service_status = false; + log_level[DLOG_CONS] = loglevel_t::ZERO; + } else if (strcmp(argv[i], "--help") == 0) { cout << "dinit, an init with dependency management\n" " --help display help\n" @@ -272,6 +276,7 @@ int dinit_main(int argc, char **argv) " --user, -u run as a user service manager\n" " --socket-path , -p \n" " path to control socket\n" + " --quiet, -q disable output to standard output\n" " start service with name \n"; return 0; } diff --git a/src/includes/dinit-log.h b/src/includes/dinit-log.h index bcc3c18..ccff5e7 100644 --- a/src/includes/dinit-log.h +++ b/src/includes/dinit-log.h @@ -25,8 +25,13 @@ enum class loglevel_t { ZERO // log absolutely nothing }; +constexpr static int DLOG_MAIN = 0; // main log facility +constexpr static int DLOG_CONS = 1; // console + // These are defined in dinit-log.cc: extern loglevel_t log_level[2]; +extern bool console_service_status; // show service status messages to console? + void enable_console_log(bool do_enable) noexcept; void init_log(service_set *sset, bool syslog_format); void setup_main_log(int fd);