From: Davin McCall Date: Sun, 29 Dec 2019 04:16:12 +0000 (+1000) Subject: Mark main log closed on write failure X-Git-Tag: v0.8.1~10 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=d48b25fec7303580c573e688820514844e5e0e39;p=oweals%2Fdinit.git Mark main log closed on write failure Record the main log as being closed (external_log_open false) if there is a write failure while trying to write the log buffer. This allows the log to be re-opened by restarting the logging service. Also we avoid waiting for the log buffer to flush if it has failed. --- diff --git a/src/dinit-log.cc b/src/dinit-log.cc index 89c9f05..9d86913 100644 --- a/src/dinit-log.cc +++ b/src/dinit-log.cc @@ -25,6 +25,7 @@ // 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) static bool log_format_syslog[2] = { false, true }; @@ -46,7 +47,7 @@ class buffered_log_stream : public eventloop_t::fd_watcher_impl 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) diff --git a/src/dinit.cc b/src/dinit.cc index 1c78278..2942a0a 100644 --- a/src/dinit.cc +++ b/src/dinit.cc @@ -73,7 +73,7 @@ static bool am_system_init = false; // true if we are the system init process static bool did_log_boot = false; static bool control_socket_open = false; -static bool external_log_open = false; +bool external_log_open = false; int active_control_conns = 0; // Control socket path. We maintain a string (control_socket_str) in case we need diff --git a/src/tests/test-dinit.cc b/src/tests/test-dinit.cc index ab22ab6..6fc3442 100644 --- a/src/tests/test-dinit.cc +++ b/src/tests/test-dinit.cc @@ -6,6 +6,7 @@ eventloop_t event_loop; int active_control_conns = 0; +bool external_log_open = false; /* These are provided in header instead: diff --git a/src/tests/test-includes/dinit.h b/src/tests/test-includes/dinit.h index 5901346..a689da7 100644 --- a/src/tests/test-includes/dinit.h +++ b/src/tests/test-includes/dinit.h @@ -109,6 +109,8 @@ class eventloop_t } virtual rearm fd_event(eventloop_t & loop, int fd, int flags) = 0; + + virtual void watch_removed() noexcept { } }; template class fd_watcher_impl : public fd_watcher