Make sure we don't try to enable log watcher after deregistration
authorDavin McCall <davmac@davmac.org>
Wed, 1 Jan 2020 05:46:49 +0000 (15:46 +1000)
committerDavin McCall <davmac@davmac.org>
Wed, 1 Jan 2020 05:46:49 +0000 (15:46 +1000)
If the watcher for the log has been deregistered (log closed), set the
release flag to prevent attempts to enable the watcher.

src/dinit-log.cc

index 60c447a54c1317f8c019e20dadb47ad64a5f547e..d9e733a76c2bfe8221053e26b2b643956aec6d3e 100644 (file)
@@ -140,6 +140,8 @@ void buffered_log_stream::release_console()
 
 void buffered_log_stream::flush_for_release()
 {
+    if (release) return;
+
     release = true;
     
     // Try to flush any messages that are currently buffered. (Console is non-blocking
@@ -268,8 +270,10 @@ void buffered_log_stream::watch_removed() noexcept
 {
     if (fd > STDERR_FILENO) {
         bp_sys::close(fd);
-        fd = -1;
     }
+    fd = -1;
+    release = true; // prevent attempt to enable watch
+
     // 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) {