From 56def1cbac629dce2a664af4f3f4eeaba1f77a0f Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Sat, 14 May 2016 00:00:00 -0500 Subject: [PATCH] misc: adapt others to changes in interface, api I've got nothing to add to the commit message but that doesn't mean I won't produce perfectly justified text. Signed-off-by: Jim Warner --- pgrep.c | 16 ++++++--------- pidof.c | 6 ++---- pmap.c | 10 +++++----- ps/common.h | 2 +- ps/display.c | 56 ++++++++++++++++++++++++++-------------------------- ps/global.c | 6 +++--- ps/output.c | 6 +++--- skill.c | 2 +- top/top.c | 27 ++++++++++++------------- w.c | 6 +++--- 10 files changed, 65 insertions(+), 72 deletions(-) diff --git a/pgrep.c b/pgrep.c index dc782875..7527891b 100644 --- a/pgrep.c +++ b/pgrep.c @@ -487,7 +487,7 @@ static struct el * select_procs (int *num) char cmdsearch[CMDSTRSIZE]; char cmdoutput[CMDSTRSIZE]; char *task_cmdline; - enum pids_reap_type which; + enum pids_fetch_type which; preg = do_regcomp(); @@ -501,18 +501,14 @@ static struct el * select_procs (int *num) _("Error reading reference namespace information\n")); } - if (procps_pids_new(&info, 12, Items) < 0) + if (procps_pids_new(&info, Items, 12) < 0) xerrx(EXIT_FATAL, _("Unable to create pid info structure")); + which = PROCPS_FETCH_TASKS_ONLY; if (opt_threads && !i_am_pkill) - which = PROCPS_REAP_THREADS_TOO; - else - which = PROCPS_REAP_TASKS_ONLY; - if (procps_pids_read_open(info, which) < 0) - xerrx(EXIT_FATAL, - _("Unable to open pids information")); + which = PROCPS_FETCH_THREADS_TOO; - while ((stack = procps_pids_read_next(info))) { + while ((stack = procps_pids_get(info, which))) { int match = 1; if (PIDS_GETINT(PID) == myself) @@ -591,7 +587,7 @@ static struct el * select_procs (int *num) } } } - procps_pids_read_shut(info); + procps_pids_unref(&info); *num = matches; return list; diff --git a/pidof.c b/pidof.c index e4c085b6..b73195a0 100644 --- a/pidof.c +++ b/pidof.c @@ -147,11 +147,10 @@ static void select_procs (void) /* get the input base name */ program_base = get_basename(program); - procps_pids_new(&info, 3, items); - procps_pids_read_open(info, PROCPS_REAP_TASKS_ONLY); + procps_pids_new(&info, items, 3); exe_link = root_link = NULL; - while ((stack = procps_pids_read_next(info))) { + while ((stack = procps_pids_get(info, PROCPS_FETCH_TASKS_ONLY))) { char *p_cmd = PROCPS_PIDS_VAL(rel_cmd, str, stack), **p_cmdline = PROCPS_PIDS_VAL(rel_cmdline, strv, stack); int tid = PROCPS_PIDS_VAL(rel_pid, s_int, stack); @@ -240,7 +239,6 @@ static void select_procs (void) } - procps_pids_read_shut(info); procps_pids_unref(&info); } diff --git a/pmap.c b/pmap.c index ed266e3e..19e9f1c0 100644 --- a/pmap.c +++ b/pmap.c @@ -988,7 +988,7 @@ static char *get_default_rc_filename(void) int main(int argc, char **argv) { struct procps_pidsinfo *info = NULL; - struct pids_reap *pids_reap; + struct pids_fetch *pids_fetch; unsigned *pidlist; int reap_count, user_count; int ret = 0, c, conf_ret; @@ -1128,7 +1128,7 @@ int main(int argc, char **argv) } } } - if (procps_pids_new(&info, 4, Pid_items)) + if (procps_pids_new(&info, Pid_items, 4)) xerrx(EXIT_FAILURE, _("library failed pids statistics")); pidlist = xmalloc(sizeof(pid_t) * argc); @@ -1153,11 +1153,11 @@ int main(int argc, char **argv) discover_shm_minor(); - if (!(pids_reap = procps_pids_select(info, pidlist, user_count, PROCPS_SELECT_PID))) + if (!(pids_fetch = procps_pids_select(info, pidlist, user_count, PROCPS_SELECT_PID))) xerrx(EXIT_FAILURE, _("library failed pids statistics")); - for (reap_count = 0; reap_count < pids_reap->counts.total; reap_count++) { - ret |= one_proc(pids_reap->stacks[reap_count]); + for (reap_count = 0; reap_count < pids_fetch->counts.total; reap_count++) { + ret |= one_proc(pids_fetch->stacks[reap_count]); } free(pidlist); diff --git a/ps/common.h b/ps/common.h index 5c862dc9..c7b8f078 100644 --- a/ps/common.h +++ b/ps/common.h @@ -142,7 +142,7 @@ makEXT(TTY) makEXT(TTY_NAME) makEXT(TTY_NUMBER) makEXT(VM_DATA) -makEXT(VM_LOCK) +makEXT(VM_RSS_LOCKED) makEXT(VM_RSS) makEXT(VM_SIZE) makEXT(VM_STACK) diff --git a/ps/display.c b/ps/display.c index 2c94a0c5..662365d6 100644 --- a/ps/display.c +++ b/ps/display.c @@ -273,7 +273,7 @@ static void value_this_proc_pcpu(proc_t *buf){ /***** just display */ static void simple_spew(void){ - struct pids_reap *pidreap; + struct pids_fetch *pidread; proc_t *buf; int i; @@ -282,48 +282,48 @@ static void simple_spew(void){ unsigned *pidlist = xcalloc(selection_list->n, sizeof(unsigned)); for (i = 0; i < selection_list->n; i++) pidlist[i] = selection_list->u[selection_list->n-i-1].pid; - pidreap = procps_pids_select(Pids_info, pidlist, selection_list->n, PROCPS_SELECT_PID); + pidread = procps_pids_select(Pids_info, pidlist, selection_list->n, PROCPS_SELECT_PID); free(pidlist); } else { - enum pids_reap_type which; + enum pids_fetch_type which; which = (thread_flags & (TF_loose_tasks|TF_show_task)) - ? PROCPS_REAP_THREADS_TOO : PROCPS_REAP_TASKS_ONLY; - pidreap = procps_pids_reap(Pids_info, which); + ? PROCPS_FETCH_THREADS_TOO : PROCPS_FETCH_TASKS_ONLY; + pidread = procps_pids_reap(Pids_info, which); } - if (!pidreap) { + if (!pidread) { fprintf(stderr, _("fatal library error, reap\n")); exit(EXIT_FAILURE); } switch(thread_flags & (TF_show_proc|TF_loose_tasks|TF_show_task)){ case TF_show_proc: // normal non-thread output - for (i = 0; i < pidreap->counts.total; i++) { - buf = pidreap->stacks[i]; + for (i = 0; i < pidread->counts.total; i++) { + buf = pidread->stacks[i]; if (want_this_proc(buf)) show_one_proc(buf, proc_format_list); } break; case TF_show_task: // -L and -T options case TF_show_proc|TF_loose_tasks: // H option - for (i = 0; i < pidreap->counts.total; i++) { - buf = pidreap->stacks[i]; + for (i = 0; i < pidread->counts.total; i++) { + buf = pidread->stacks[i]; if (want_this_proc(buf)) show_one_proc(buf, task_format_list); } break; case TF_show_proc|TF_show_task: // m and -m options - procps_pids_sort(Pids_info, pidreap->stacks - , pidreap->counts.total, PROCPS_PIDS_TIME_START, PROCPS_SORT_ASCEND); - procps_pids_sort(Pids_info, pidreap->stacks - , pidreap->counts.total, PROCPS_PIDS_ID_TGID, PROCPS_SORT_ASCEND); - for (i = 0; i < pidreap->counts.total; i++) { - buf = pidreap->stacks[i]; + procps_pids_sort(Pids_info, pidread->stacks + , pidread->counts.total, PROCPS_PIDS_TIME_START, PROCPS_SORT_ASCEND); + procps_pids_sort(Pids_info, pidread->stacks + , pidread->counts.total, PROCPS_PIDS_ID_TGID, PROCPS_SORT_ASCEND); + for (i = 0; i < pidread->counts.total; i++) { + buf = pidread->stacks[i]; next_proc: if (want_this_proc(buf)) { int self = rSv(ID_PID, s_int, buf); show_one_proc(buf, proc_format_list); - for (; i < pidreap->counts.total; i++) { - buf = pidreap->stacks[i]; + for (; i < pidread->counts.total; i++) { + buf = pidread->stacks[i]; if (rSv(ID_TGID, s_int, buf) != self) goto next_proc; show_one_proc(buf, task_format_list); } @@ -439,22 +439,22 @@ static int want_this_proc_nop(proc_t *dummy){ /***** sorted or forest */ static void fancy_spew(void){ - struct pids_reap *pidreap; - enum pids_reap_type which; + struct pids_fetch *pidread; + enum pids_fetch_type which; proc_t *buf; int i, n = 0; which = (thread_flags & TF_loose_tasks) - ? PROCPS_REAP_THREADS_TOO : PROCPS_REAP_TASKS_ONLY; + ? PROCPS_FETCH_THREADS_TOO : PROCPS_FETCH_TASKS_ONLY; - pidreap = procps_pids_reap(Pids_info, which); - if (!pidreap || !pidreap->counts.total) { + pidread = procps_pids_reap(Pids_info, which); + if (!pidread || !pidread->counts.total) { fprintf(stderr, _("fatal library error, reap\n")); exit(EXIT_FAILURE); } - processes = xcalloc(pidreap->counts.total, sizeof(void*)); - for (i = 0; i < pidreap->counts.total; i++) { - buf = pidreap->stacks[i]; + processes = xcalloc(pidread->counts.total, sizeof(void*)); + for (i = 0; i < pidread->counts.total; i++) { + buf = pidread->stacks[i]; value_this_proc_pcpu(buf); if (want_this_proc(buf)) processes[n++] = buf; @@ -553,7 +553,7 @@ static void finalize_stacks (void) chkREL(NICE) chkREL(NLWP) chkREL(RSS) - chkREL(VM_LOCK) + chkREL(VM_RSS_LOCKED) // needed with 's' switch, previously assured chkREL(SIGBLOCKED) chkREL(SIGCATCH) @@ -579,7 +579,7 @@ static void finalize_stacks (void) s_node = s_node->next; } - procps_pids_reset(Pids_info, Pids_index, Pids_items); + procps_pids_reset(Pids_info, Pids_items, Pids_index); } /***** no comment */ diff --git a/ps/global.c b/ps/global.c index 733b924f..d4c82125 100644 --- a/ps/global.c +++ b/ps/global.c @@ -131,7 +131,7 @@ makREL(TTY) makREL(TTY_NAME) makREL(TTY_NUMBER) makREL(VM_DATA) -makREL(VM_LOCK) +makREL(VM_RSS_LOCKED) makREL(VM_RSS) makREL(VM_SIZE) makREL(VM_STACK) @@ -467,14 +467,14 @@ void reset_global(void){ Pids_items[i] = PROCPS_PIDS_noop; if (!Pids_info) { - if (procps_pids_new(&Pids_info, i, Pids_items)) { + if (procps_pids_new(&Pids_info, Pids_items, i)) { fprintf(stderr, _("fatal library error, context\n")); exit(EXIT_FAILURE); } } Pids_items[0] = PROCPS_PIDS_TTY; - procps_pids_reset(Pids_info, 1, Pids_items); + procps_pids_reset(Pids_info, Pids_items, 1); if (!(p = fatal_proc_unmounted(Pids_info, 1))) { fprintf(stderr, _("fatal library error, lookup self\n")); exit(EXIT_FAILURE); diff --git a/ps/output.c b/ps/output.c index f7ac3cee..835e8698 100644 --- a/ps/output.c +++ b/ps/output.c @@ -688,7 +688,7 @@ static int pr_stat(char *restrict const outbuf, const proc_t *restrict const pp) if (!outbuf) { chkREL(STATE) chkREL(NICE) - chkREL(VM_LOCK) + chkREL(VM_RSS_LOCKED) chkREL(ID_SESSION) chkREL(ID_TGID) chkREL(NLWP) @@ -706,7 +706,7 @@ static int pr_stat(char *restrict const outbuf, const proc_t *restrict const pp) // exiting 'E' (not printed for zombies) // vforked 'V' // system 'K' (and do not print 'L' too) - if(rSv(VM_LOCK, ul_int, pp)) outbuf[end++] = 'L'; + if(rSv(VM_RSS_LOCKED, sl_int, pp)) outbuf[end++] = 'L'; if(rSv(ID_SESSION, s_int, pp) == rSv(ID_TGID, s_int, pp)) outbuf[end++] = 's'; // session leader if(rSv(NLWP, s_int, pp) > 1) outbuf[end++] = 'l'; // multi-threaded if(rSv(ID_PGRP, s_int, pp) == rSv(ID_TPGID, s_int, pp)) outbuf[end++] = '+'; // in foreground process group @@ -1618,7 +1618,7 @@ static const format_struct format_array[] = { /* {"vm_data", "DATA", pr_nop, PROCPS_PIDS_VM_DATA, 5, LNx, PO|RIGHT}, {"vm_exe", "EXE", pr_nop, PROCPS_PIDS_VM_EXE, 5, LNx, PO|RIGHT}, {"vm_lib", "LIB", pr_nop, PROCPS_PIDS_VM_LIB, 5, LNx, PO|RIGHT}, -{"vm_lock", "LCK", pr_nop, PROCPS_PIDS_VM_LOCK, 3, LNx, PO|RIGHT}, +{"vm_lock", "LCK", pr_nop, PROCPS_PIDS_VM_RSS_LOCKED, 3, LNx, PO|RIGHT}, {"vm_stack", "STACK", pr_nop, PROCPS_PIDS_VM_STACK, 5, LNx, PO|RIGHT}, {"vsize", "VSZ", pr_vsz, PROCPS_PIDS_VSIZE_PGS, 6, DEC, PO|RIGHT}, /*vsz*/ {"vsz", "VSZ", pr_vsz, PROCPS_PIDS_VM_SIZE, 6, U98, PO|RIGHT}, /*vsize*/ diff --git a/skill.c b/skill.c index 7becbd0d..3d73d29b 100644 --- a/skill.c +++ b/skill.c @@ -271,7 +271,7 @@ static void scan_procs(struct run_time_conf_t *run_time) if (procps_pids_new(&info, 6, items) < 0) xerrx(EXIT_FAILURE, _("Unable to create pid info structure")); - if ((reap = procps_pids_reap(info, PROCPS_REAP_TASKS_ONLY)) == NULL) + if ((reap = procps_pids_reap(info, PROCPS_FETCH_TASKS_ONLY)) == NULL) xerrx(EXIT_FAILURE, _("Unable to load process information")); diff --git a/top/top.c b/top/top.c index c5e01d4a..d19f326e 100644 --- a/top/top.c +++ b/top/top.c @@ -108,8 +108,7 @@ static char Scroll_fmts [SMLBUFSIZ]; static int Batch = 0, // batch mode, collect no input, dumb output Loops = -1, // number of iterations, -1 loops forever Secure_mode = 0, // set if some functionality restricted - Width_mode = 0; // set w/ 'w' - potential output override -enum pids_reap_type + Width_mode = 0, // set w/ 'w' - potential output override Thread_mode = 0; // set w/ 'H' - show threads vs. tasks /* Unchangeable cap's stuff built just once (if at all) and @@ -214,8 +213,8 @@ enum Rel_memitems { static struct procps_pidsinfo *Pids_ctx; static int Pids_itms_cur; // 'current' max (<= Fieldstab) static enum pids_item *Pids_itms; // allocated as MAXTBL(Fieldstab) -static struct pids_reap *Pids_reap; // for reap or select -#define PIDSmaxt Pids_reap->counts.total // just a little less wordy +static struct pids_fetch *Pids_read; // for reap or select +#define PIDSmaxt Pids_read->counts.total // just a little less wordy // pid stack results extractor macro, where e=our EU enum, t=type, s=stack // ( we'll exploit that provided macro as much as possible ) // ( but many functions use their own unique tailored version for access ) @@ -1860,7 +1859,7 @@ static void calibrate_fields (void) { build_headers(); - if (procps_pids_reset(Pids_ctx, Pids_itms_cur, Pids_itms)) + if (procps_pids_reset(Pids_ctx, Pids_itms, Pids_itms_cur)) error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); if (CHKw(Curwin, View_SCROLL)) @@ -2188,7 +2187,7 @@ static void cpus_refresh (void) { static void procs_refresh (void) { #define nALIGN(n,m) (((n + m - 1) / m) * m) // unconditionally align #define nALGN2(n,m) ((n + m - 1) & ~(m - 1)) // with power of 2 align - #define n_reap Pids_reap->counts.total + #define n_reap Pids_read->counts.total static double uptime_sav; static int n_alloc = -1; // size of windows stacks arrays double uptime_cur; @@ -2202,9 +2201,9 @@ static void procs_refresh (void) { // if in Solaris mode, adjust our scaling for all cpus Frame_etscale = 100.0f / ((float)Hertz * (float)et * (Rc.mode_irixps ? 1 : Cpu_cnt)); - if (!Monpidsidx) Pids_reap = procps_pids_reap(Pids_ctx, Thread_mode); - else Pids_reap = procps_pids_select(Pids_ctx, Monpids, Monpidsidx, PROCPS_SELECT_PID); - if (!Pids_reap) + if (Monpidsidx) Pids_read = procps_pids_select(Pids_ctx, Monpids, Monpidsidx, PROCPS_SELECT_PID); + else Pids_read = procps_pids_reap(Pids_ctx, Thread_mode ? PROCPS_FETCH_THREADS_TOO : PROCPS_FETCH_TASKS_ONLY); + if (!Pids_read) error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); // now refresh each window's stack heads pointers table... @@ -2213,11 +2212,11 @@ static void procs_refresh (void) { n_alloc = nALGN2(n_reap, 128); for (i = 0; i < GROUPSMAX; i++) { Winstk[i].ppt = alloc_r(Winstk[i].ppt, sizeof(void*) * n_alloc); - memcpy(Winstk[i].ppt, Pids_reap->stacks, sizeof(void*) * PIDSmaxt); + memcpy(Winstk[i].ppt, Pids_read->stacks, sizeof(void*) * PIDSmaxt); } } else { for (i = 0; i < GROUPSMAX; i++) - memcpy(Winstk[i].ppt, Pids_reap->stacks, sizeof(void*) * PIDSmaxt); + memcpy(Winstk[i].ppt, Pids_read->stacks, sizeof(void*) * PIDSmaxt); } #undef n_reap #undef nALGN2 @@ -2831,7 +2830,7 @@ static void before (char *me) { Pids_itms[i] = PROCPS_PIDS_noop; Pids_itms_cur = i; // we will identify specific items in the build_headers() function - if (procps_pids_new(&Pids_ctx, Pids_itms_cur, Pids_itms)) + if (procps_pids_new(&Pids_ctx, Pids_itms, Pids_itms_cur)) error_exit(fmtmk(N_fmt(LIB_errorpid_fmt),__LINE__)); #ifndef SIGRTMAX // not available on hurd, maybe others too @@ -4678,8 +4677,8 @@ static void summary_show (void) { if (isROOM(View_STATES, 2)) { show_special(0, fmtmk(N_unq(STATE_line_1_fmt) , Thread_mode ? N_txt(WORD_threads_txt) : N_txt(WORD_process_txt) - , PIDSmaxt, Pids_reap->counts.running, Pids_reap->counts.sleeping - , Pids_reap->counts.stopped, Pids_reap->counts.zombied)); + , PIDSmaxt, Pids_read->counts.running, Pids_read->counts.sleeping + , Pids_read->counts.stopped, Pids_read->counts.zombied)); Msg_row += 1; cpus_refresh(); diff --git a/w.c b/w.c index 934e5e73..f9eafc68 100644 --- a/w.c +++ b/w.c @@ -353,7 +353,7 @@ static int find_best_proc( unsigned long long secondbest_time = 0; struct procps_pidsinfo *info=NULL; - struct pids_reap *reap; + struct pids_fetch *reap; enum pids_item items[] = { PROCPS_PIDS_ID_TGID, PROCPS_PIDS_TIME_START, @@ -383,10 +383,10 @@ static int find_best_proc( line = get_tty_device(tty); - if (procps_pids_new(&info, 9, items) < 0) + if (procps_pids_new(&info, items, 9) < 0) xerrx(EXIT_FAILURE, _("Unable to create pid info structure")); - if ((reap = procps_pids_reap(info, PROCPS_REAP_TASKS_ONLY)) == NULL) + if ((reap = procps_pids_reap(info, PROCPS_FETCH_TASKS_ONLY)) == NULL) xerrx(EXIT_FAILURE, _("Unable to load process information")); total_procs = reap->counts.total; -- 2.40.0