From a760a2c22d2a1c1e5f25b024aa6cac98e549e8e2 Mon Sep 17 00:00:00 2001 From: albert <> Date: Wed, 28 Jan 2004 21:53:44 +0000 Subject: [PATCH] "top -p1" then hit "=" did SIGSEGV; flags not regenerated right --- NEWS | 1 + pmap.c | 21 +++++++++++++++++---- ps/display.c | 20 +++----------------- top.c | 1 + 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/NEWS b/NEWS index 7c70a745..9cf43648 100644 --- a/NEWS +++ b/NEWS @@ -4,6 +4,7 @@ ps: also handle SELinux on the 2.4.xx kernels top: during a ^Z, the terminal was messed up #228822 future-proof the tty handling (thanks to Zhou Wei) slabtop (Chris Rivera and Robert Love) #226778 rh114012a +pmap: detect the primary stack procps-3.1.14 --> procps-3.1.15 diff --git a/pmap.c b/pmap.c index 38a60d39..32462d69 100644 --- a/pmap.c +++ b/pmap.c @@ -79,7 +79,9 @@ static const char *get_args(unsigned pid){ static const char *anon_name(int pid, unsigned KLONG addr, unsigned KLONG len){ const char *cp = " [ anon ]"; proc_t proc; - if (get_proc_stats(pid, &proc)){ + static int oldpid = -1; + if (pid==oldpid || get_proc_stats(pid, &proc)){ + oldpid = pid; if( (proc.start_stack >= addr) && (proc.start_stack <= addr+len) ) cp = " [ stack ]"; } return cp; @@ -111,6 +113,12 @@ static int one_proc(unsigned pid){ tmp++; } + diff = end-start; + if(flags[3]=='s') total_shared += diff; + if(flags[3]=='p') total_private += diff; + +#if 1 + // format used by Solaris 7 and old procps if(flags[0]=='r'){ if(flags[1]=='w'){ if(flags[2]=='x') perms = "read/write/exec"; @@ -128,9 +136,14 @@ static int one_proc(unsigned pid){ else perms = "none "; } } - diff = end-start; - if(flags[3]=='s') total_shared += diff; - if(flags[3]=='p') total_private += diff; +#else + // format used by Solaris 9 and future procps + perms = flags; + if(flags[3] == 'p') flags[3] = '-'; + flags[4] = '-'; // an 'R' if swap not reserved (MAP_NORESERVE, SysV ISM shared mem, etc.) + flags[5] = '\0'; +#endif + if(x_option){ const char *cp = strrchr(mapbuf,'/'); if(cp && cp[1]) cp++; diff --git a/ps/display.c b/ps/display.c index a52769b4..d313c273 100644 --- a/ps/display.c +++ b/ps/display.c @@ -516,27 +516,13 @@ static void fancy_spew(void){ proc_data_t *pd = NULL; PROCTAB *restrict ptp; int n = 0; /* number of processes & index into array */ -#if 0 - if(thread_flags){ - fprintf(stderr, "can't have threads with sorting or forest output\n"); - exit(49); - } -#endif + ptp = openproc(needs_for_format | needs_for_sort | needs_for_select | needs_for_threads); if(!ptp) { fprintf(stderr, "Error: can not access /proc.\n"); exit(1); } -#if 0 - while((retbuf = readproc(ptp,retbuf))){ - if(want_this_proc_pcpu(retbuf)){ -// fill_pcpu(retbuf); // in case we might sort by %cpu - processes[n++] = retbuf; - retbuf = NULL; // NULL asks readproc to allocate - } - } - if(retbuf) free(retbuf); -#else + if(thread_flags & TF_loose_tasks){ pd = readproctab2(want_this_proc_nop, want_this_proc_pcpu, ptp); }else{ @@ -544,7 +530,7 @@ static void fancy_spew(void){ } n = pd->n; processes = pd->tab; -#endif + if(!n) return; /* no processes */ if(forest_type) prep_forest_sort(); qsort(processes, n, sizeof(proc_t*), compare_two_procs); diff --git a/top.c b/top.c index 2446d04e..bbf23a92 100644 --- a/top.c +++ b/top.c @@ -2718,6 +2718,7 @@ static void do_key (unsigned c) Curwin->rc.maxtasks = 0; SETw(Curwin, Show_IDLEPS | VISIBLE_tsk); Monpidsidx = 0; + selection_type = '\0'; break; case '+':