tls: prepare for ECDH_anon ciphers
[oweals/busybox.git] / procps / pstree.c
index 54a910f76f47da762e2acfbcde83b897a7e4aea3..4fda1c21c9d8e4b4ff603c223fd3a760e4d77825 100644 (file)
@@ -9,14 +9,13 @@
  *
  * Licensed under GPLv2, see file LICENSE in this source tree.
  */
-
 //config:config PSTREE
-//config:      bool "pstree"
+//config:      bool "pstree (9.4 kb)"
 //config:      default y
 //config:      help
-//config:        Display a tree of processes.
+//config:      Display a tree of processes.
 
-//applet:IF_PSTREE(APPLET(pstree, _BB_DIR_USR_BIN, _BB_SUID_DROP))
+//applet:IF_PSTREE(APPLET_NOEXEC(pstree, pstree, BB_DIR_USR_BIN, BB_SUID_DROP, pstree))
 
 //kbuild:lib-$(CONFIG_PSTREE) += pstree.o
 
@@ -24,7 +23,6 @@
 //usage:       "[-p] [PID|USER]"
 //usage:#define pstree_full_usage "\n\n"
 //usage:       "Display process tree, optionally start from USER or PID\n"
-//usage:     "\nOptions:"
 //usage:     "\n       -p      Show pids"
 
 #include "libbb.h"
 
 struct child;
 
+#if ENABLE_FEATURE_SHOW_THREADS
+/* For threads, we add {...} around the comm, so we need two extra bytes */
+# define COMM_DISP_LEN (COMM_LEN + 2)
+#else
+# define COMM_DISP_LEN COMM_LEN
+#endif
+
 typedef struct proc {
-       char comm[COMM_LEN + 1];
+       char comm[COMM_DISP_LEN + 1];
 //     char flags; - unused, delete?
        pid_t pid;
        uid_t uid;
@@ -76,7 +81,7 @@ struct globals {
 };
 #define G (*ptr_to_globals)
 #define INIT_G() do { \
-        SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
+       SET_PTR_TO_GLOBALS(xzalloc(sizeof(G))); \
 } while (0)
 
 
@@ -339,17 +344,21 @@ static void dump_by_user(PROC *current, uid_t uid)
                dump_by_user(walk->child, uid);
 }
 
+#if ENABLE_FEATURE_SHOW_THREADS
 static void handle_thread(const char *comm, pid_t pid, pid_t ppid, uid_t uid)
 {
-       char threadname[COMM_LEN + 2];
-       sprintf(threadname, "{%.*s}", COMM_LEN - 2, comm);
+       char threadname[COMM_DISP_LEN + 1];
+       sprintf(threadname, "{%.*s}", (int)sizeof(threadname) - 3, comm);
        add_proc(threadname, pid, ppid, uid/*, 1*/);
 }
+#endif
 
 static void mread_proc(void)
 {
        procps_status_t *p = NULL;
+#if ENABLE_FEATURE_SHOW_THREADS
        pid_t parent = 0;
+#endif
        int flags = PSSCAN_COMM | PSSCAN_PID | PSSCAN_PPID | PSSCAN_UIDGID | PSSCAN_TASKS;
 
        while ((p = procps_scan(p, flags)) != NULL) {
@@ -360,7 +369,9 @@ static void mread_proc(void)
 #endif
                {
                        add_proc(p->comm, p->pid, p->ppid, p->uid/*, 0*/);
+#if ENABLE_FEATURE_SHOW_THREADS
                        parent = p->pid;
+#endif
                }
        }
 }
@@ -373,10 +384,9 @@ int pstree_main(int argc UNUSED_PARAM, char **argv)
 
        INIT_G();
 
-       get_terminal_width_height(1, &G.output_width, NULL);
+       G.output_width = get_terminal_width(0);
 
-       opt_complementary = "?1";
-       getopt32(argv, "p");
+       getopt32(argv, "^" "p" "\0" "?1");
        argv += optind;
 
        if (argv[0]) {