> > I'm trying to debug status2proc() function but I'm not able to find input 
> > options to force this function to execute.
> I would say you're not using gdb correctly.

Correct, I had a problem with ldconfig. Thanks very much for your help.

> Not simple, if anyone reading this actually understands gperf (or wants
> to) they can have a crack at it. I can write the code that then copies
> the value in the status file and fiddles with the ps flags but that
> hashing has got me stuck.

I wrote the code to modify hash function and read the new field
"Groups:". I'm sending the patch.

Some comments:

1.- The number of supplementary groups depends on the process. The
field of proc_t to save them can be managed with static or dynamic
memory. I thought time and simplicity is more important than memory so
I chose to manage it statically. I can modify it if you think it is
not suitable.

2.- Related to point 1. I chose 32 as maximum number of supplementary
groups. In my desktop computer the max I found was 16 but I don't know
whether 32 is enough in most cases.

3.- I create a field in proc_t to save the number of supplementary
groups. I initialize it to 0 into status2proc function. Should it be
necessary initialize it in other places or status2proc is visited for
all processes ?
Index: proc/readproc.c
===================================================================
RCS file: /cvsroot/procps/procps/proc/readproc.c,v
retrieving revision 1.56
diff -u -d -r1.56 readproc.c
--- proc/readproc.c	17 Jun 2006 04:13:26 -0000	1.56
+++ proc/readproc.c	20 Jan 2009 10:32:08 -0000
@@ -85,63 +85,68 @@
     long Threads = 0;
     long Tgid = 0;
     long Pid = 0;
+    int hash = 0;
+    int isupgid = 0;
 
-  static const unsigned char asso[] =
+    static const unsigned char asso[] =
     {
-      61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61, 61, 15, 61,
-      61, 61, 61, 61, 61, 61, 30,  3,  5,  5,
-      61,  5, 61,  8, 61, 61,  3, 61, 10, 61,
-       6, 61, 13,  0, 30, 25,  0, 61, 61, 61,
-      61, 61, 61, 61, 61, 61, 61,  3, 61, 13,
-       0,  0, 61, 30, 61, 25, 61, 61, 61,  0,
-      61, 61, 61, 61,  5, 61,  0, 61, 61, 61,
-       0, 61, 61, 61, 61, 61, 61, 61
+      66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66, 66,  0, 66,
+      66, 66, 66, 66, 66, 66,  3, 30, 20, 30,
+      66, 25, 66, 20, 66, 66, 30, 66, 25, 66,
+       0, 66,  8, 10,  3, 18,  5, 66, 66, 66,
+      66, 66, 66, 66, 66, 66, 66,  3, 66, 10,
+       0,  0, 66, 25, 66,  5, 66, 66, 66, 25,
+      66,  5, 66, 66,  0, 66,  0,  0, 66, 66,
+      25, 66, 66, 66, 66, 66, 66, 66
     };
 
     static const status_table_struct table[] = {
-      F(VmStk)
+      F(Pid)
       NUL NUL
-      F(State)
+      F(Threads)
+      NUL
+      F(PPid)
+      NUL NUL
+      F(Tgid)
       NUL
-      F(VmExe)
       F(ShdPnd)
+      NUL NUL
+      F(State)
       NUL
-      F(VmData)
+      F(VmStk)
+      NUL NUL
+      F(Uid)
       NUL
-      F(Name)
+      F(VmSize)
       NUL NUL
       F(VmRSS)
-      NUL NUL
-      F(VmLck)
-      NUL NUL NUL
+      NUL
       F(Gid)
-      F(Pid)
-      NUL NUL NUL
-      F(VmSize)
       NUL NUL
-      F(VmLib)
-      NUL NUL
-      F(PPid)
-      NUL
-      F(SigCgt)
+      F(VmData)
       NUL
-      F(Threads)
+      F(Groups)
+      NUL NUL NUL NUL
       F(SigPnd)
+      NUL NUL
+      F(SigBlk)
       NUL
+      F(VmLib)
+      NUL NUL NUL NUL
+      F(VmLck)
+      NUL NUL NUL NUL
+      F(Name)
+      NUL NUL NUL NUL
       F(SigIgn)
-      NUL
-      F(Uid)
-      NUL NUL NUL NUL NUL NUL NUL NUL NUL
-      NUL NUL NUL NUL NUL
-      F(Tgid)
       NUL NUL NUL NUL
-      F(SigBlk)
-      NUL NUL NUL
+      F(VmExe)
+      NUL NUL NUL NUL
+      F(SigCgt)
     };
 
 #undef F
@@ -157,6 +162,7 @@
     P->vm_exe  = 0;
     P->vm_lib  = 0;
     P->nlwp    = 0;
+    P->nsupgid = 0;
     P->signal[0] = '\0';  // so we can detect it as missing for very old kernels
 
     goto base;
@@ -173,7 +179,9 @@
         // examine a field name (hash and compare)
     base:
         if(unlikely(!*S)) break;
-        entry = table[63 & (asso[S[3]] + asso[S[2]] + asso[S[0]])];
+        hash = asso[S[3]] + asso[S[2]] + asso[S[0]];
+        if (hash > 65) continue;
+        entry = table[hash];
         colon = strchr(S, ':');
         if(unlikely(!colon)) break;
         if(unlikely(colon[1]!='\t')) break;
@@ -271,6 +279,15 @@
         P->sgid = strtol(S,&S,10);
         P->fgid = strtol(S,&S,10);
         continue;
+    case_Groups:
+        isupgid = 0;
+        if (*S != '\n') // Is there any supplementary group ?
+            while (S[1] != '\n' && likely(isupgid != MAX_NUM_SUP_GROUPS)) // There is a blank before '\n'
+            {
+                P->supgid[isupgid++] = strtol(S,&S,10);
+                P->nsupgid++;
+            }
+        continue;
     case_VmData:
         P->vm_data = strtol(S,&S,10);
         continue;
Index: proc/readproc.h
===================================================================
RCS file: /cvsroot/procps/procps/proc/readproc.h,v
retrieving revision 1.37
diff -u -d -r1.37 readproc.h
--- proc/readproc.h	17 Jun 2006 04:13:26 -0000	1.37
+++ proc/readproc.h	20 Jan 2009 10:32:09 -0000
@@ -14,6 +14,7 @@
 #include "pwcache.h"
 
 #define SIGNAL_STRING
+#define MAX_NUM_SUP_GROUPS 32
 
 EXTERN_C_BEGIN
 
@@ -137,6 +138,8 @@
         suid, sgid,     // status          saved
         fuid, fgid,     // status          fs (used for file access only)
 	tpgid,		// stat            terminal process group id
+	nsupgid,		// status        number of supplementary groups
+    supgid[MAX_NUM_SUP_GROUPS],	// status        supplementary groups
 	exit_signal,	// stat            might not be SIGCHLD
 	processor;      // stat            current (or most recent?) CPU
 } proc_t;

Reply via email to