]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
logging: add function to send message to foreground process
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2024 14:08:46 +0000 (16:08 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 4 Jul 2024 14:50:22 +0000 (16:50 +0200)
logging.c
logging.h

index ec9ec53882c0305ad23144517c8a635f056af0a6..732165e9d96f8cd9f1be981cd27e7233b455ae7c 100644 (file)
--- a/logging.c
+++ b/logging.c
@@ -185,7 +185,7 @@ void LOG_Message(LOG_Severity severity,
       /* Send the message also to the foreground process if it is
          still running, or stderr if it is still open */
       if (parent_fd > 0) {
-        if (write(parent_fd, buf, strlen(buf) + 1) < 0)
+        if (!LOG_NotifyParent(buf))
           ; /* Not much we can do here */
       } else if (system_log && parent_fd == 0) {
         system_log = 0;
@@ -291,6 +291,17 @@ LOG_SetParentFd(int fd)
 
 /* ================================================== */
 
+int
+LOG_NotifyParent(const char *message)
+{
+  if (parent_fd <= 0)
+    return 1;
+
+  return write(parent_fd, message, strlen(message) + 1) > 0;
+}
+
+/* ================================================== */
+
 void
 LOG_CloseParentFd()
 {
index ff2e30e7c68b3f5575fc4a8da1b7812afb08411e..4dfef0b7fa66c6971c7b847e8cc7793c26ee397b 100644 (file)
--- a/logging.h
+++ b/logging.h
@@ -126,7 +126,10 @@ extern void LOG_OpenSystemLog(void);
 /* Stop using stderr and send fatal message to the foreground process */
 extern void LOG_SetParentFd(int fd);
 
-/* Close the pipe to the foreground process so it can exit */
+/* Send a message to the foreground process */
+extern int LOG_NotifyParent(const char *message);
+
+/* Close the pipe to the foreground process */
 extern void LOG_CloseParentFd(void);
 
 /* File logging functions */