analyze: fix unit-shell/unit-gdb when target unit has exited

Follow-up for 9a08000d18
Follow-up for ad6e02e7b4
This commit is contained in:
Luca Boccassi
2025-08-28 12:11:45 +01:00
parent 1be088c299
commit e91bfad241
2 changed files with 4 additions and 0 deletions
+2
View 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");
+2
View 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(