From: Craig Small Date: Mon, 21 Jun 2021 12:11:36 +0000 (+1000) Subject: pstree: check pid with show parents X-Git-Tag: v23.5rc1~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=3e899a37bb717d3ac102c75a0f410cd06e6c73a3;p=psmisc pstree: check pid with show parents If the -s option was used then we didn't check the return of find_proc(). This meant if you used a pid that was for no process it returned NULL and the whole tree was shown. pstree checks for find_proc() returning NULL and errors out. References: #38 --- diff --git a/ChangeLog b/ChangeLog index df45ae3..601a918 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Changes in NEXT +=============== + * pstree: Check for process with show_parents #38 + Changes in 23.4 =============== * killall: Dynamically link to selinux and use security attributes diff --git a/src/pstree.c b/src/pstree.c index 1021b6c..5f68765 100644 --- a/src/pstree.c +++ b/src/pstree.c @@ -2,7 +2,7 @@ * pstree.c - display process tree * * Copyright (C) 1993-2002 Werner Almesberger - * Copyright (C) 2002-2020 Craig Small + * Copyright (C) 2002-2021 Craig Small * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1263,7 +1263,7 @@ void print_version() fprintf(stderr, _("pstree (PSmisc) %s\n"), VERSION); fprintf(stderr, _ - ("Copyright (C) 1993-2020 Werner Almesberger and Craig Small\n\n")); + ("Copyright (C) 1993-2021 Werner Almesberger and Craig Small\n\n")); fprintf(stderr, _("PSmisc comes with ABSOLUTELY NO WARRANTY.\n" "This is free software, and you are welcome to redistribute it under\n" @@ -1462,7 +1462,13 @@ int main(int argc, char **argv) current->flags |= PFLAG_HILIGHT; if(show_parents && pid_set == 1) { - trim_tree_by_parent(find_proc(pid)); + PROC *child_proc; + + if ( (child_proc = find_proc(pid)) == NULL) { + fprintf(stderr, _("Process %d not found.\n"), pid); + return 1; + } + trim_tree_by_parent(child_proc); pid = ROOT_PID; }