From 06a771fcfb511d2fab024d5970c9f4495abab8c3 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Sun, 2 Jan 2022 19:28:06 +0100 Subject: fix -p flag Regression from c0e8a5424d, also fix error reporting of processes we don't care about. --- extrace.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/extrace.c b/extrace.c index 4848a6f..9f5f166 100644 --- a/extrace.c +++ b/extrace.c @@ -140,7 +140,7 @@ pid_depth(pid_t pid) char *s; int fd, d, i; - if (pid == 1) + if (pid == 1 && parent == 1) return 0; snprintf(name, sizeof name, "/proc/%d/stat", pid); @@ -345,14 +345,16 @@ handle_msg(struct cn_msg *cn_hdr) d = pid_depth(pid); if (d < 0) { - if (*cmdline) { - print_runtime_error( - "extrace: process vanished before we found its parent: pid %d: %s\n", - pid, cmdline); - } else { - print_runtime_error( - "extrace: process vanished without a name: pid %d\n", - pid); + if (parent == 1) { + if (*cmdline) { + print_runtime_error( + "extrace: process vanished before we found its parent: pid %d: %s\n", + pid, cmdline); + } else { + print_runtime_error( + "extrace: process vanished without a name: pid %d\n", + pid); + } } close(proc_dir_fd); return; -- cgit 1.4.1