]> granicus.if.org Git - procps-ng/commitdiff
library: add PROCPS_PIDS_TTY_NAME to compliment number
authorJim Warner <james.warner@comcast.net>
Mon, 7 Sep 2015 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Wed, 9 Sep 2015 11:22:43 +0000 (21:22 +1000)
OK, ok, this was kind of a huge omission. So please do
not select the TTY field for display in top quite yet,
at least until a next patch has been pushed to GitLab.

And to produce a correct sort order for this new field
the GNU 'strverscmp' routine was a necessary addition.

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/pids.c
proc/pids.h

index ff66cede9cf7fde87469e75cc41a1e836aaba47d..091c2c18ba5b034b79fefe4edcd5cecb041724fa 100644 (file)
@@ -38,8 +38,9 @@
 #include <proc/pids.h>
 #include "procps-private.h"
 
-#include "readproc.h"                  // and two headers for bridged
-#include "wchan.h"                     // support (temporary include)
+#include "devname.h"                   // and a few headers for our
+#include "readproc.h"                  // bridged libprocps support
+#include "wchan.h"                     // ( maybe just temporary? )
 
 //#define UNREF_RPTHASH                // report on hashing, at uref time
 //#define FPRINT_STACKS                // enable validate_stacks output
@@ -210,6 +211,7 @@ REG_set(TICS_USER,        ull_int, utime)
 REG_set(TICS_USER_C,      ull_int, cutime)
 REG_set(TIME_START,       ull_int, start_time)
 REG_set(TTY,              s_int,   tty)
+setDECL(TTY_NAME)     { char buf[64]; (void)I; dev_to_tty(buf, sizeof(buf), P->tty, P->tid, ABBREV_DEV); R->result.str = strdup(buf); }
 REG_set(VM_DATA,          ul_int,  vm_data)
 REG_set(VM_EXE,           ul_int,  vm_exe)
 REG_set(VM_LIB,           ul_int,  vm_lib)
@@ -297,6 +299,13 @@ static int srtNAME(strv) (
     return P->order * strcoll((*b->result.strv), (*a->result.strv));
 }
 
+static int srtNAME(strvers) (
+  const struct pids_stack **A, const struct pids_stack **B, struct sort_parms *P) {
+    const struct pids_result *a = (*A)->head + P->offset;
+    const struct pids_result *b = (*B)->head + P->offset;
+    return P->order * strverscmp(b->result.str, a->result.str);
+}
+
 static int srtNAME(noop) (
   const struct pids_stack **A, const struct pids_stack **B, enum pids_item *O) {
     (void)A; (void)B; (void)O;
@@ -450,6 +459,7 @@ static struct {
     { RS(TICS_USER_C),       f_stat,     NULL,      QS(ull_int),  0       },
     { RS(TIME_START),        f_stat,     NULL,      QS(ull_int),  0       },
     { RS(TTY),               f_stat,     NULL,      QS(s_int),    0       },
+    { RS(TTY_NAME),          f_stat,     FF(str),   QS(strvers),  0       },
     { RS(VM_DATA),           f_status,   NULL,      QS(ul_int),   0       },
     { RS(VM_EXE),            f_status,   NULL,      QS(ul_int),   0       },
     { RS(VM_LIB),            f_status,   NULL,      QS(ul_int),   0       },
index 68d9ddcd0a337eebf96c4ee12debeb5c8d77b8b6..6b5fa76d3ffdebda0d66727f269b9614904d4313 100644 (file)
@@ -122,6 +122,7 @@ enum pids_item {
     PROCPS_PIDS_TICS_USER_C,           // ull_int
     PROCPS_PIDS_TIME_START,            // ull_int
     PROCPS_PIDS_TTY,                   // s_int
+    PROCPS_PIDS_TTY_NAME,              // str
     PROCPS_PIDS_VM_DATA,               // ul_int
     PROCPS_PIDS_VM_EXE,                // ul_int
     PROCPS_PIDS_VM_LIB,                // ul_int