diff --git a/src/analyze/analyze-unit-gdb.c b/src/analyze/analyze-unit-gdb.c index 7c5da0b948..4fe108f89b 100644 --- a/src/analyze/analyze-unit-gdb.c +++ b/src/analyze/analyze-unit-gdb.c @@ -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"); diff --git a/src/analyze/analyze-unit-shell.c b/src/analyze/analyze-unit-shell.c index 607c6af676..a5641fdd70 100644 --- a/src/analyze/analyze-unit-shell.c +++ b/src/analyze/analyze-unit-shell.c @@ -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(