From 0db94e6a1aa54474f0ba9b41c62f2af612882f90 Mon Sep 17 00:00:00 2001 From: albert <> Date: Thu, 3 Jul 2003 05:20:19 +0000 Subject: [PATCH] GPLONLY_ and PID-related stuff --- NEWS | 2 ++ pmap.c | 2 +- proc/ksym.c | 30 +++++++++++++++++++++------- proc/library.map | 2 +- proc/readproc.c | 4 ++-- proc/readproc.h | 4 ++-- proc/sysinfo.c | 29 +++++++++++++++++++++++++++ proc/sysinfo.h | 2 ++ ps/display.c | 1 + ps/output.c | 51 +++++++++++++++++++++++++----------------------- ps/sortformat.c | 14 ++++++++++++- 11 files changed, 103 insertions(+), 38 deletions(-) diff --git a/NEWS b/NEWS index ec573346..507fc391 100644 --- a/NEWS +++ b/NEWS @@ -1,7 +1,9 @@ procps-3.1.9 --> procps-3.1.10 +handle GPLONLY_ symbols #143549 #188374 kill: better man page skill: better man page +ps: PID-like columns change width as needed top: COMMAND instead of Command vmstat: -m displays slabinfo vmstat: -d displays disk stats diff --git a/pmap.c b/pmap.c index bb8ef368..48dc33a9 100644 --- a/pmap.c +++ b/pmap.c @@ -93,7 +93,7 @@ static int one_proc(unsigned pid){ char *tmp; // to clean up unprintables unsigned long start, end, diff; unsigned long long pgoff; - sscanf(mapbuf,"%lx-%lx %s %Lx", &start, &end, flags, &pgoff); + sscanf(mapbuf,"%lx-%lx %31s %Lx", &start, &end, flags, &pgoff); tmp = strchr(mapbuf,'\n'); if(tmp) *tmp='\0'; tmp = mapbuf; diff --git a/proc/ksym.c b/proc/ksym.c index 8f3d4920..dd4d52e1 100644 --- a/proc/ksym.c +++ b/proc/ksym.c @@ -140,7 +140,7 @@ static unsigned idx_room; * /proc/ksyms and System.map data files. */ #if 0 -static void chop_version(char *arg){ +static char *chop_version(char *arg){ char *cp; cp = strchr(arg,'\t'); if(cp) *cp = '\0'; /* kill trailing module name first */ @@ -152,7 +152,7 @@ static void chop_version(char *arg){ for(p=cp; *++p; ){ switch(*p){ default: - return; + goto out; case '0' ... '9': case 'a' ... 'f': len++; @@ -166,9 +166,18 @@ static void chop_version(char *arg){ if(len<8) break; cp[-1] = '\0'; } +out: + if(*arg=='G'){ + int len = strlen(arg); + while( len>8 && !memcmp(arg,"GPLONLY_",8) ){ + arg += 8; + len -= 8; + } + } + return arg; } #endif -static void chop_version(char *arg){ +static char *chop_version(char *arg){ char *cp; cp = strchr(arg,'\t'); if(cp) *cp = '\0'; /* kill trailing module name first */ @@ -182,6 +191,14 @@ static void chop_version(char *arg){ if(strspn(cp+len-8,"0123456789abcdef")!=8) break; cp[-1] = '\0'; } + if(*arg=='G'){ + int len = strlen(arg); + while( len>8 && !memcmp(arg,"GPLONLY_",8) ){ + arg += 8; + len -= 8; + } + } + return arg; } /***********************************/ @@ -293,12 +310,11 @@ bypass: ksyms_index[ksyms_count].addr = STRTOUKL(endp, &endp, 16); if(endp==saved || *endp != ' ') goto bad_parse; endp++; - ksyms_index[ksyms_count].name = endp; saved = endp; endp = strchr(endp,'\n'); if(!endp) goto bad_parse; /* no newline */ *endp = '\0'; - chop_version(saved); + ksyms_index[ksyms_count].name = chop_version(saved); ++endp; if(++ksyms_count >= idx_room) break; /* need more space */ } @@ -400,13 +416,13 @@ good_match:; endp++; if(*endp != ' ') goto bad_parse; endp++; - sysmap_index[sysmap_count].name = endp; vstart = endp; endp = strchr(endp,'\n'); if(!endp) goto bad_parse; /* no newline */ *endp = '\0'; ++endp; - chop_version(vstart); + vstart = chop_version(vstart); + sysmap_index[sysmap_count].name = vstart; if(*vstart=='V' && *Version && !strcmp(Version,vstart)) *Version='\0'; if(++sysmap_count >= sysmap_room) break; /* need more space */ } diff --git a/proc/library.map b/proc/library.map index 4433b227..557d5ac8 100644 --- a/proc/library.map +++ b/proc/library.map @@ -10,7 +10,7 @@ global: Hertz; smp_num_cpus; sprint_uptime; uptime; user_from_uid; print_uptime; loadavg; pretty_print_signals; print_given_signals; unix_print_signals; signal_name_to_number; signal_number_to_name; - meminfo; vminfo; getstat; getdiskstat; getslabinfo; + meminfo; vminfo; getstat; getdiskstat; getslabinfo; get_pid_digits; kb_active; kb_inactive; kb_main_buffers; kb_main_cached; kb_main_free; kb_main_total; kb_main_used; kb_swap_free; kb_swap_total; kb_swap_used; kb_main_shared; diff --git a/proc/readproc.c b/proc/readproc.c index 6eefc09e..dada3a3b 100644 --- a/proc/readproc.c +++ b/proc/readproc.c @@ -734,8 +734,8 @@ HIDDEN_ALIAS(readproc); /* Convenient wrapper around openproc and readproc to slurp in the whole process * table subset satisfying the constraints of flags and the optional PID list. - * Free allocated memory with freeproctab(). Access via tab[N]->member. The - * pointer list is NULL terminated. + * Free allocated memory with exit(). Access via tab[N]->member. The pointer + * list is NULL terminated. */ proc_t** readproctab(int flags, ...) { PROCTAB* PT = NULL; diff --git a/proc/readproc.h b/proc/readproc.h index 2ac033b5..5529d467 100644 --- a/proc/readproc.h +++ b/proc/readproc.h @@ -166,8 +166,8 @@ extern PROCTAB* openproc(int flags, ... /* pid_t*|uid_t*|dev_t*|char* [, int n] /* Convenient wrapper around openproc and readproc to slurp in the whole process * table subset satisfying the constraints of flags and the optional PID list. - * Free allocated memory with freeproctab(). Access via tab[N]->member. The - * pointer list is NULL terminated. + * Free allocated memory with exit(). Access via tab[N]->member. The pointer + * list is NULL terminated. */ extern proc_t** readproctab(int flags, ... /* same as openproc */ ); diff --git a/proc/sysinfo.c b/proc/sysinfo.c index f7a65893..60032bd6 100644 --- a/proc/sysinfo.c +++ b/proc/sysinfo.c @@ -757,3 +757,32 @@ unsigned int getslabinfo (struct slab_cache **slab){ return cSlab; } +/////////////////////////////////////////////////////////////////////////// + +unsigned get_pid_digits(void){ + char buf[24]; + char *endp; + long rc; + int fd; + static unsigned ret; + + if(ret) goto out; + ret = 5; + fd = open("/proc/sys/kernel/pid_max", O_RDONLY); + if(fd==-1) goto out; + rc = read(fd, buf, sizeof buf); + close(fd); + if(rc<3) goto out; + buf[rc] = '\0'; + rc = strtol(buf,&endp,10); + if(rc<42) goto out; + if(*endp && *endp!='\n') goto out; + rc--; // the pid_max value is really the max PID plus 1 + ret = 0; + while(rc){ + rc /= 10; + ret++; + } +out: + return ret; +} diff --git a/proc/sysinfo.h b/proc/sysinfo.h index b58ba557..e34712b1 100644 --- a/proc/sysinfo.h +++ b/proc/sysinfo.h @@ -127,5 +127,7 @@ typedef struct slab_cache{ extern unsigned int getslabinfo (struct slab_cache**); +extern unsigned get_pid_digits(void) FUNCTION; + EXTERN_C_END #endif /* SYSINFO_H */ diff --git a/ps/display.c b/ps/display.c index 7ea75d64..d9a39a7f 100644 --- a/ps/display.c +++ b/ps/display.c @@ -29,6 +29,7 @@ #include "../proc/version.h" #include "../proc/readproc.h" #include "../proc/sysinfo.h" +#include "../proc/sig.h" #ifndef SIGCHLD #define SIGCHLD SIGCLD diff --git a/ps/output.c b/ps/output.c index d7ff933f..e20114ad 100644 --- a/ps/output.c +++ b/ps/output.c @@ -85,17 +85,20 @@ static unsigned max_rightward = 0x12345678; /* space for RIGHT stuff */ static unsigned max_leftward = 0x12345678; /* space for LEFT stuff */ -/* Justification control for flags field. */ -#define JUST_MASK 0x0f - /* AIXHACK 0 */ -#define USER 1 /* left if text, right if numeric */ -#define LEFT 2 -#define RIGHT 3 -#define UNLIMITED 4 -#define WCHAN 5 /* left if text, right if numeric */ -#define SIGNAL 6 /* right in 9, or 16 if screen_cols>107 */ -#define CUMUL 16 /* mark cumulative (Summed) headers with 'C' */ +/* Justification control for flags field. */ +#define JUST_MASK 0x0f +// AIXHACK 0 +#define USER 1 // left if text, right if numeric +#define LEFT 2 +#define RIGHT 3 +#define UNLIMITED 4 +#define WCHAN 5 // left if text, right if numeric +#define SIGNAL 6 // right in 9, or 16 if screen_cols>107 + +#define CUMUL 0x10 // mark cumulative (Summed) headers with 'C' */ +#define PIDMAX 0x20 // react to pid_max + static int wide_signals; /* true if we have room */ @@ -1212,7 +1215,7 @@ static const format_struct format_array[] = { {"lstart", "STARTED", pr_lstart, sr_nop, 24, 0, XXX, RIGHT}, {"luid", "LUID", pr_nop, sr_nop, 5, 0, LNX, RIGHT}, /* login ID */ {"luser", "LUSER", pr_nop, sr_nop, 8, USR, LNX, USER}, /* login USER */ -{"lwp", "LWP", pr_thread, sr_nop, 5, 0, SUN, RIGHT}, +{"lwp", "LWP", pr_thread, sr_nop, 5, 0, SUN, PIDMAX|RIGHT}, {"m_drs", "DRS", pr_drs, sr_drs, 5, MEM, LNx, RIGHT}, {"m_dt", "DT", pr_nop, sr_dt, 4, MEM, LNx, RIGHT}, {"m_lrs", "LRS", pr_nop, sr_lrs, 5, MEM, LNx, RIGHT}, @@ -1245,13 +1248,13 @@ static const format_struct format_array[] = { {"pagein", "PAGEIN", pr_majflt, sr_nop, 6, 0, XXX, RIGHT}, {"pcpu", "%CPU", pr_pcpu, sr_pcpu, 4, 0, U98, RIGHT}, /*%cpu*/ {"pending", "PENDING", pr_sig, sr_nop, 9, 0, BSD, SIGNAL}, /*sig*/ -{"pgid", "PGID", pr_pgid, sr_pgrp, 5, 0, U98, RIGHT}, -{"pgrp", "PGRP", pr_pgid, sr_pgrp, 5, 0, LNX, RIGHT}, -{"pid", "PID", pr_pid, sr_pid, 5, 0, U98, RIGHT}, +{"pgid", "PGID", pr_pgid, sr_pgrp, 5, 0, U98, PIDMAX|RIGHT}, +{"pgrp", "PGRP", pr_pgid, sr_pgrp, 5, 0, LNX, PIDMAX|RIGHT}, +{"pid", "PID", pr_pid, sr_pid, 5, 0, U98, PIDMAX|RIGHT}, {"pmem", "%MEM", pr_pmem, sr_nop, 4, 0, XXX, RIGHT}, /*%mem*/ {"poip", "-", pr_nop, sr_nop, 1, 0, BSD, RIGHT}, {"policy", "POL", pr_class, sr_sched, 3, 0, DEC, LEFT}, -{"ppid", "PPID", pr_ppid, sr_ppid, 5, 0, U98, RIGHT}, +{"ppid", "PPID", pr_ppid, sr_ppid, 5, 0, U98, PIDMAX|RIGHT}, {"pri", "PRI", pr_pri, sr_nop, 3, 0, XXX, RIGHT}, {"priority", "PRI", pr_priority, sr_priority, 3, 0, LNX, RIGHT}, /*ni,nice*/ /* from Linux sorting names */ {"prmgrp", "-", pr_nop, sr_nop, 1, 0, HPU, RIGHT}, @@ -1275,14 +1278,14 @@ static const format_struct format_array[] = { {"scnt", "SCNT", pr_nop, sr_nop, 4, 0, DEC, RIGHT}, /* man page misspelling of scount? */ {"scount", "SC", pr_nop, sr_nop, 4, 0, AIX, RIGHT}, /* scnt==scount, DEC claims both */ {"secsid", "SID", pr_secsid, sr_secsid, 6, 0, LNX, RIGHT}, /* Flask Linux */ -{"sess", "SESS", pr_sess, sr_session, 5, 0, XXX, RIGHT}, -{"session", "SESS", pr_sess, sr_session, 5, 0, LNX, RIGHT}, +{"sess", "SESS", pr_sess, sr_session, 5, 0, XXX, PIDMAX|RIGHT}, +{"session", "SESS", pr_sess, sr_session, 5, 0, LNX, PIDMAX|RIGHT}, {"sgi_p", "P", pr_sgi_p, sr_nop, 1, 0, LNX, RIGHT}, /* "cpu" number */ {"sgi_rss", "RSS", pr_rss, sr_nop, 4, 0, LNX, LEFT}, /* SZ:RSS */ {"sgid", "SGID", pr_sgid, sr_sgid, 5, 0, LNX, RIGHT}, {"sgroup", "SGROUP", pr_sgroup, sr_sgroup, 8, GRP, LNX, USER}, {"share", "-", pr_nop, sr_share, 1, MEM, LNX, RIGHT}, -{"sid", "SID", pr_sess, sr_session, 5, 0, XXX, RIGHT}, /* Sun & HP */ +{"sid", "SID", pr_sess, sr_session, 5, 0, XXX, PIDMAX|RIGHT}, /* Sun & HP */ {"sig", "PENDING", pr_sig, sr_nop, 9, 0, XXX, SIGNAL}, /*pending*/ {"sig_block", "BLOCKED", pr_sigmask, sr_nop, 9, 0, LNX, SIGNAL}, {"sig_catch", "CATCHED", pr_sigcatch, sr_nop, 9, 0, LNX, SIGNAL}, @@ -1293,7 +1296,7 @@ static const format_struct format_array[] = { {"sigmask", "BLOCKED", pr_sigmask, sr_nop, 9, 0, XXX, SIGNAL}, /*blocked*/ {"size", "SZ", pr_swapable, sr_swapable, 1, 0, SCO, RIGHT}, {"sl", "SL", pr_nop, sr_nop, 3, 0, XXX, RIGHT}, -{"spid", "SPID", pr_thread, sr_nop, 5, 0, SGI, RIGHT}, +{"spid", "SPID", pr_thread, sr_nop, 5, 0, SGI, PIDMAX|RIGHT}, {"stackp", "STACKP", pr_stackp, sr_nop, 8, 0, LNX, RIGHT}, /*start_stack*/ {"start", "STARTED", pr_start, sr_nop, 8, 0, XXX, RIGHT}, {"start_code", "S_CODE", pr_nop, sr_start_code, 8, 0, LNx, RIGHT}, @@ -1313,16 +1316,16 @@ static const format_struct format_array[] = { {"sz", "SZ", pr_sz, sr_nop, 5, 0, HPU, RIGHT}, {"tdev", "TDEV", pr_nop, sr_nop, 4, 0, XXX, RIGHT}, {"thcount", "THCNT", pr_nlwp, sr_nop, 5, 0, AIX, RIGHT}, -{"tid", "TID", pr_thread, sr_nop, 5, 0, AIX, RIGHT}, +{"tid", "TID", pr_thread, sr_nop, 5, 0, AIX, PIDMAX|RIGHT}, {"time", "TIME", pr_time, sr_nop, 8, 0, U98, CUMUL|RIGHT}, /*cputime*/ /* was 6 wide */ {"timeout", "TMOUT", pr_timeout, sr_timeout, 5, 0, LNX, RIGHT}, {"tmout", "TMOUT", pr_timeout, sr_timeout, 5, 0, LNX, RIGHT}, {"tname", "TTY", pr_tty8, sr_tty, 8, 0, DEC, LEFT}, -{"tpgid", "TPGID", pr_tpgid, sr_tpgid, 5, 0, XXX, RIGHT}, +{"tpgid", "TPGID", pr_tpgid, sr_tpgid, 5, 0, XXX, PIDMAX|RIGHT}, {"trs", "TRS", pr_trs, sr_trs, 4, MEM, AIX, RIGHT}, {"trss", "TRSS", pr_trs, sr_trs, 4, MEM, BSD, RIGHT}, /* 4.3BSD NET/2 */ -{"tsess", "TSESS", pr_nop, sr_nop, 5, 0, BSD, RIGHT}, -{"tsession", "TSESS", pr_nop, sr_nop, 5, 0, DEC, RIGHT}, +{"tsess", "TSESS", pr_nop, sr_nop, 5, 0, BSD, PIDMAX|RIGHT}, +{"tsession", "TSESS", pr_nop, sr_nop, 5, 0, DEC, PIDMAX|RIGHT}, {"tsiz", "TSIZ", pr_tsiz, sr_nop, 4, 0, BSD, RIGHT}, {"tt", "TT", pr_tty8, sr_tty, 8, 0, BSD, LEFT}, {"tty", "TT", pr_tty8, sr_tty, 8, 0, U98, LEFT}, /* Unix98 requires "TT" but has "TTY" too. :-( */ /* was 3 wide */ @@ -1596,7 +1599,7 @@ static void check_header_width(void){ /********** show one process (NULL proc prints header) **********/ //#define SPACE_AMOUNT page_size -#define SPACE_AMOUNT 128 +#define SPACE_AMOUNT 144 static char *saved_outbuf; diff --git a/ps/sortformat.c b/ps/sortformat.c index f67f749c..736bea52 100644 --- a/ps/sortformat.c +++ b/ps/sortformat.c @@ -22,6 +22,7 @@ #include #include "../proc/readproc.h" +#include "../proc/sysinfo.h" #include "common.h" static sf_node *sf_list = NULL; /* deferred sorting and formatting */ @@ -34,6 +35,11 @@ static int already_parsed_format = 0; #define parse_sort_opt <-- arrgh! do not use this --> #define gnusort_parse <-- arrgh! do not use this --> +#ifndef COL_PIDMAX +#warning Ugly wart needs fixing, use common.h to sync w/ output.c +#define COL_PIDMAX 0x20 +#endif + /**************** Parse single format specifier *******************/ static format_node *do_one_spec(const char *spec, const char *override){ @@ -45,7 +51,13 @@ static format_node *do_one_spec(const char *spec, const char *override){ int w1, w2; format_node *thisnode; thisnode = malloc(sizeof(format_node)); - w1 = fs->width; + if(fs->flags & COL_PIDMAX){ + w1 = (int)get_pid_digits(); + w2 = strlen(fs->head); + if(w2>w1) w1=w2; // FIXME w/ separate header/body column sizing + }else{ + w1 = fs->width; + } if(override){ w2 = strlen(override); thisnode->width = (w1>w2)?w1:w2;