From b9fadf2e2cb83d342342341b0edba4f519890634 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 19 Feb 2023 01:26:39 +0900 Subject: [PATCH 1/3] process-util: show requested process name in the log This is useful for debugging issues like #26474. --- src/basic/process-util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/process-util.c b/src/basic/process-util.c index be82d0ffe7..4df369dd2a 100644 --- a/src/basic/process-util.c +++ b/src/basic/process-util.c @@ -1185,7 +1185,7 @@ int safe_fork_full( else pid = fork(); if (pid < 0) - return log_full_errno(prio, errno, "Failed to fork: %m"); + return log_full_errno(prio, errno, "Failed to fork off '%s': %m", strna(name)); if (pid > 0) { /* We are in the parent process */ From 65cd9c7251384f7af934f8d928118b2d4829ee6c Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 19 Feb 2023 01:55:28 +0900 Subject: [PATCH 2/3] exec-util: propagate error in wait_for_terminate_and_check() Then, the two error handlings becomes consistent with the one in execute_directories(). --- src/shared/exec-util.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 7ed2cce76b..51234fd025 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -151,10 +151,9 @@ static int do_execute( t = NULL; } else { r = wait_for_terminate_and_check(t, pid, WAIT_LOG); - if (FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS)) { - if (r < 0) - continue; - } else if (r > 0) + if (r < 0) + return r; + if (!FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS) && r > 0) return r; if (callbacks) { @@ -186,6 +185,8 @@ static int do_execute( assert(t); r = wait_for_terminate_and_check(t, pid, WAIT_LOG); + if (r < 0) + return r; if (!FLAGS_SET(flags, EXEC_DIR_IGNORE_ERRORS) && r > 0) return r; } From ced30d69fa878b7132d818fa7cd6da163108c254 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 19 Feb 2023 02:09:22 +0900 Subject: [PATCH 3/3] exec-util: use TAKE_FD() --- src/shared/exec-util.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/shared/exec-util.c b/src/shared/exec-util.c index 51234fd025..2e8f5b8562 100644 --- a/src/shared/exec-util.c +++ b/src/shared/exec-util.c @@ -160,8 +160,7 @@ static int do_execute( if (lseek(fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to seek on serialization fd: %m"); - r = callbacks[STDOUT_GENERATE](fd, callback_args[STDOUT_GENERATE]); - fd = -EBADF; + r = callbacks[STDOUT_GENERATE](TAKE_FD(fd), callback_args[STDOUT_GENERATE]); if (r < 0) return log_error_errno(r, "Failed to process output from %s: %m", *path); } @@ -250,8 +249,7 @@ int execute_directories( if (lseek(fd, 0, SEEK_SET) < 0) return log_error_errno(errno, "Failed to rewind serialization fd: %m"); - r = callbacks[STDOUT_CONSUME](fd, callback_args[STDOUT_CONSUME]); - fd = -EBADF; + r = callbacks[STDOUT_CONSUME](TAKE_FD(fd), callback_args[STDOUT_CONSUME]); if (r < 0) return log_error_errno(r, "Failed to parse returned data: %m"); return 0;