X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fdinit-log.cc;h=e0ee69a369e635ba374f05f05312a9d185db1b19;hb=8fc3058147d2a0efc32d40ca4a738b26fd246b4f;hp=dbdf868760c34a99e41348292263b81a279a189f;hpb=e859cf54f99a9bc1835ae08768d4a5fd1701a55c;p=oweals%2Fdinit.git diff --git a/src/dinit-log.cc b/src/dinit-log.cc index dbdf868..e0ee69a 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -1,4 +1,3 @@ -#include #include #include @@ -26,13 +25,16 @@ // message (if any) and then assigns the console to a waiting service. extern eventloop_t event_loop; +extern bool external_log_open; 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; @@ -45,7 +47,7 @@ class buffered_log_stream : public eventloop_t::fd_watcher_impl= 0) { if (start + r > end) { // All written: go on to next message in queue @@ -234,7 +239,7 @@ rearm buffered_log_stream::fd_event(eventloop_t &loop, int fd, int flags) noexce iovs_to_write = 2; } - ssize_t r = writev(fd, logiov, iovs_to_write); + ssize_t r = bp_sys::writev(fd, logiov, iovs_to_write); if (r >= 0) { bool complete = (r == len) && will_complete; @@ -259,6 +264,21 @@ rearm buffered_log_stream::fd_event(eventloop_t &loop, int fd, int flags) noexce return rearm::REARM; } +void buffered_log_stream::watch_removed() noexcept +{ + if (fd > STDERR_FILENO) { + close(fd); + fd = -1; + } + // Here we rely on there only being two logs, console and "main"; we can check if we are the + // main log via identity: + if (&log_stream[DLOG_MAIN] == this) { + external_log_open = false; + } +} + +} // end namespace + // Initialise the logging subsystem // Potentially throws std::bad_alloc or std::system_error void init_log(service_set *sset, bool syslog_format) @@ -282,7 +302,8 @@ void setup_main_log(int fd) bool is_log_flushed() noexcept { - return log_stream[DLOG_CONS].current_index == 0; + return log_stream[DLOG_CONS].current_index == 0 && + (log_stream[DLOG_MAIN].fd == -1 || log_stream[DLOG_MAIN].current_index == 0); } // Enable or disable console logging. If disabled, console logging will be disabled on the @@ -389,9 +410,11 @@ template 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 @@ -422,7 +445,7 @@ void log(loglevel_t lvl, bool to_cons, const char *msg) noexcept } // Log part of a message. A series of calls to do_log_part must be followed by a call to do_log_commit. -template static void do_log_part(int idx, T arg) noexcept +static void do_log_part(int idx, const char *arg) noexcept { if (log_current_line[idx]) { int amount = sum_length(arg);