]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
analyze: fix unit-shell/unit-gdb when target unit has exited
authorLuca Boccassi <luca.boccassi@gmail.com>
Wed, 27 Aug 2025 19:16:11 +0000 (20:16 +0100)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 28 Aug 2025 11:11:45 +0000 (12:11 +0100)
Follow-up for 9a08000d186396bc8bcb8fe057720417543c3bf0
Follow-up for ad6e02e7b42db35178305614e643be7a62568d87

src/analyze/analyze-unit-gdb.c
src/analyze/analyze-unit-shell.c

index 7c5da0b948db6b20889b1e37aa17af018edfbc97..4fe108f89b57e32b97246a50a8bebad67b3e2ab2 100644 (file)
@@ -62,6 +62,8 @@ int verb_unit_gdb(int argc, char *argv[], void *userdata) {
         r = sd_bus_message_read(reply, "u", &pid);
         if (r < 0)
                 return log_error_errno(r, "Failed to read the main PID of %s from reply: %m", unit);
+        if (pid == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Unit %s has no MainPID (hint: inactive?)", unit);
 
         if (!arg_debugger) {
                 arg_debugger = strdup(secure_getenv("SYSTEMD_DEBUGGER") ?: "gdb");
index 607c6af6763381e925a34fc33d303660ff799726..a5641fdd70b5f9e373191eb0885afa22257ec09f 100644 (file)
@@ -58,6 +58,8 @@ int verb_unit_shell(int argc, char *argv[], void *userdata) {
         r = sd_bus_message_read(reply, "u", &pid);
         if (r < 0)
                 return log_error_errno(r, "Failed to read the main PID of %s from reply: %m", unit);
+        if (pid == 0)
+                return log_error_errno(SYNTHETIC_ERRNO(ESRCH), "Unit %s has no MainPID (hint: inactive?)", unit);
 
         _cleanup_close_ int mntns_fd = -EBADF, root_fd = -EBADF, pidns_fd = -EBADF, netns_fd = -EBADF, userns_fd = -EBADF;
         r = namespace_open(