]> granicus.if.org Git - psmisc/commitdiff
real tty and child threads for pstree
authorCraig Small <csmall@users.sourceforge.net>
Sun, 4 Sep 2005 23:12:15 +0000 (23:12 +0000)
committerCraig Small <csmall@users.sourceforge.net>
Sun, 4 Sep 2005 23:12:15 +0000 (23:12 +0000)
ChangeLog
doc/pstree.1
src/pstree.c

index 71e8b80674f973596b734a2da128d224ce97240c..6ba7be3918069040c622f08cc5f7bd4a47a00ce0 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -8,6 +8,8 @@ Changes in 21.7
        * pstree works better with uClibc, thanks Mike Frysinger
        * fuser rewritten: possibly fixes Debian #312560
        * fuser prints F instead of f is access is write, thanks to Tet.
+       * pstree checks to see it is a real tty Debian #326500
+       * pstree shows child threads with {commandname} Debian #230924
 
 Changes in 21.6
 ===============
index a7c2ccfb69353c007acadec47382d8fd2a7549be..c7b122c65c071b648e4f6ad6fdb0444171820f97 100644 (file)
@@ -41,6 +41,15 @@ becomes
 .sp
 .fi
 .PP
+.PP
+Child threads of a process are found under the parent process and are shown
+with the process name in curly braces, e.g.
+.nf
+.sp
+    icecast2\-\-\-13*[{icecast2}]
+.sp
+.fi
+.PP
 If \fBpstree\fR is called as \fBpstree.x11\fR then it will prompt the user
 at the end of the line to press return and will not return until that
 has happened. This is useful for when \fBpstree\fR is run in a xterminal.
index f11816162ac660d07e4c0b677b62eef76845a4d5..ee78422b905231dfea211589b6d984f99ad2e637 100644 (file)
@@ -624,6 +624,41 @@ read_proc (void)
                (file, "%d (%s) %c %d", &dummy, comm, (char *) &dummy,
                 &ppid) == 4)
  */
+               {
+                  DIR *taskdir;
+                  struct dirent *dt;
+                  char *taskpath;
+                  char *threadname;
+                  int thread;
+                  
+                  if (!(taskpath = malloc(strlen(path) + 10))) {
+                     exit (2);
+                  }
+                  sprintf (taskpath, "%s/task", path);
+                  
+                  if ((taskdir=opendir(taskpath))!=0) {
+                     /* if we have this dir, we're on 2.6 */
+                     if (!(threadname = malloc(strlen(comm) + 3))) {
+                        exit (2);
+                     }
+                     sprintf(threadname,"{%s}",comm);
+                     while ((dt = readdir(taskdir)) != NULL) {
+                        if ((thread=atoi(dt->d_name)) !=0) {
+                           if (thread != pid) {
+#ifdef FLASK_LINUX
+                              add_proc(threadname, thread, pid, st.st_uid, NULL, 0, sid);
+#else  /*FLASK_LINUX*/
+                              add_proc(threadname, thread, pid, st.st_uid, NULL, 0);
+#endif /*FLASK_LINUX*/
+                           }
+                        }
+                     }
+                     free(threadname);
+                     (void) closedir(taskdir);
+                  }
+                  free(taskpath);
+               }
+
                if (!print_args)
 #ifdef WITH_SELINUX
                  add_proc(comm, pid, ppid, st.st_uid, NULL, 0, scontext);
@@ -779,10 +814,10 @@ main (int argc, char **argv)
    * command-line options, if given.
    */
 
-  if (!strcmp(nl_langinfo(CODESET), "UTF-8")) {
+  if (isatty(1) && !strcmp(nl_langinfo(CODESET), "UTF-8")) {
     /* Use UTF-8 symbols if the locale's character set is UTF-8. */
     sym = &sym_utf;
-  } else if ((termname = getenv ("TERM")) && \
+  } else if (isatty (1) && (termname = getenv ("TERM")) && \
              (strlen (termname) > 0) && \
              (setupterm (NULL, 1 /* stdout */, NULL) == OK) && \
              (tigetstr ("acsc") > 0)) {