]> granicus.if.org Git - psmisc/commitdiff
pstree: check pid with show parents
authorCraig Small <csmall@dropbear.xyz>
Mon, 21 Jun 2021 12:11:36 +0000 (22:11 +1000)
committerCraig Small <csmall@dropbear.xyz>
Mon, 21 Jun 2021 12:11:36 +0000 (22:11 +1000)
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

ChangeLog
src/pstree.c

index df45ae3323bb60beb5a8a68ed1cd34b46f1a5491..601a918f09f0934f91747a4b0f0986116cae0365 100644 (file)
--- 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
index 1021b6c15c3a3b4994904a6cf3d59cbe6df636dd..5f687657b34dda09310d95697c1ada8cbd18dd40 100644 (file)
@@ -2,7 +2,7 @@
  * pstree.c - display process tree
  *
  * Copyright (C) 1993-2002 Werner Almesberger
- * Copyright (C) 2002-2020 Craig Small <csmall@dropbear.xyz>
+ * Copyright (C) 2002-2021 Craig Small <csmall@dropbear.xyz>
  *
  * 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;
     }