]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-notify: print a debug message when sd_notify() succeds 39927/head
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Nov 2025 14:04:48 +0000 (15:04 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 27 Nov 2025 19:03:00 +0000 (20:03 +0100)
… and also when it fails, in the few cases where this wasn't done already.
When I was debugging https://github.com/systemd/systemd/issues/39048, it
was quite confusing that we print copious information about D-Bus messages
and all other steps we're undertaking, but nothing about the sd-notify
messages which are much more important. Add some debug messages for the
cases where we didn't print anything. (The case where $NOTIFY_SOCKET is
not set in left unchanged. The variable is often left unset and we don't
need to spam logs in that trivial case.)

src/libsystemd/sd-daemon/sd-daemon.c

index b5fe6dfc120f4eac3844eec00d43482f550bd98d..4455f7d543e9b0734475550cbdade4a6d6446c9e 100644 (file)
@@ -505,13 +505,14 @@ static int pid_notify_with_fds_internal(
         if (r == -EPROTO)
                 r = socket_address_parse_vsock(&address, e);
         if (r < 0)
-                return r;
+                return log_debug_errno(r, "Address NOTIFY_SOCKET='%s' is neither UNIX nor VSOCK, refusing: %m", e);
         msghdr.msg_namelen = address.size;
 
         /* If we didn't get an address (which is a normal pattern when specifying VSOCK tuples) error out,
          * we always require a specific CID. */
         if (address.sockaddr.vm.svm_family == AF_VSOCK && address.sockaddr.vm.svm_cid == VMADDR_CID_ANY)
-                return -EINVAL;
+                return log_debug_errno(SYNTHETIC_ERRNO(EINVAL),
+                                       "VSOCK address in NOTIFY_SOCKET='%s' doesn't have CID, refusing.", e);
 
         type = address.type == 0 ? SOCK_DGRAM : address.type;
 
@@ -610,7 +611,8 @@ static int pid_notify_with_fds_internal(
                 } else {
                         /* Unless we're using SOCK_STREAM, we expect to write all the contents immediately. */
                         if (type != SOCK_STREAM && (size_t) n < iovec_total_size(msghdr.msg_iov, msghdr.msg_iovlen))
-                                return -EIO;
+                                return log_debug_errno(SYNTHETIC_ERRNO(EIO),
+                                                       "Incomplete notify message sent to '%s': %m", e);
 
                         /* Make sure we only send fds and ucred once, even if we're using SOCK_STREAM. */
                         msghdr.msg_control = NULL;
@@ -631,6 +633,7 @@ static int pid_notify_with_fds_internal(
                         return log_debug_errno(SYNTHETIC_ERRNO(EPROTO), "Unexpectedly received data on notify socket.");
         }
 
+        log_debug("Notify message sent to '%s': \"%s\"", e, state);
         return 1;
 }