Fix systemctl start --verbose off-by-one logs (#39927)

This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-12-05 11:09:14 +01:00
committed by GitHub
3 changed files with 13 additions and 9 deletions

View File

@@ -362,7 +362,9 @@ static int on_first_event(sd_event_source *s, void *userdata) {
return log_error_errno(r, "Failed to get cursor: %m");
}
/* Setup and initial processing are done, we're ready to wait for more data. */
(void) sd_notify(/* unset_environment= */ false, "READY=1");
return 0;
}
@@ -472,11 +474,9 @@ static int setup_event(Context *c, int fd) {
else if (r < 0)
return log_error_errno(r, "Failed to add io event source for stdout: %m");
if (arg_lines != 0 || arg_since_set) {
r = sd_event_add_defer(e, NULL, on_first_event, c);
if (r < 0)
return log_error_errno(r, "Failed to add defer event source: %m");
}
r = sd_event_add_defer(e, NULL, on_first_event, c);
if (r < 0)
return log_error_errno(r, "Failed to add defer event source: %m");
c->event = TAKE_PTR(e);
return 0;
@@ -583,6 +583,7 @@ int action_show(char **matches) {
return 0;
}
/* Setup is done, we'll start processing data. */
(void) sd_notify(/* unset_environment= */ false, "READY=1");
r = show(&c);

View 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;
}

View File

@@ -219,7 +219,7 @@ int journal_fork(RuntimeScope scope, char * const* units, PidRef *ret_pidref) {
"-q",
"--follow",
"--no-pager",
"--lines=1",
"--lines=0",
"--synchronize-on-exit=yes");
if (!argv)
return log_oom_debug();