GPLONLY_ and PID-related stuff

This commit is contained in:
albert 2003-07-03 05:20:19 +00:00
parent edcc923657
commit 0db94e6a1a
11 changed files with 103 additions and 38 deletions

2
NEWS
View File

@ -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

2
pmap.c
View File

@ -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;

View File

@ -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 */
}

View File

@ -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;

View File

@ -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;

View File

@ -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 */ );

View File

@ -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;
}

View File

@ -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 */

View File

@ -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

View File

@ -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;

View File

@ -22,6 +22,7 @@
#include <grp.h>
#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;