the u arg, U arg, u key, and U key
This commit is contained in:
parent
6b50c0cb8a
commit
36ff49a29e
138
top.c
138
top.c
@ -793,7 +793,51 @@ static const char *scale_tics (TIC_t tics, const int width)
|
|||||||
#undef WW
|
#undef WW
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <pwd.h>
|
||||||
|
|
||||||
|
static int selection_type;
|
||||||
|
static uid_t selection_uid;
|
||||||
|
|
||||||
|
// FIXME: this is "temporary" code we hope
|
||||||
|
static int good_uid(const proc_t *restrict const pp){
|
||||||
|
switch(selection_type){
|
||||||
|
case 'p':
|
||||||
|
return 1;
|
||||||
|
case 0:
|
||||||
|
return 1;
|
||||||
|
case 'U':
|
||||||
|
if (pp->ruid == selection_uid) return 1;
|
||||||
|
if (pp->suid == selection_uid) return 1;
|
||||||
|
if (pp->fuid == selection_uid) return 1;
|
||||||
|
// FALLTHROUGH
|
||||||
|
case 'u':
|
||||||
|
if (pp->euid == selection_uid) return 1;
|
||||||
|
// FALLTHROUGH
|
||||||
|
default:
|
||||||
|
; // don't know what it is; find bugs fast
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// swiped from ps, and ought to be in libproc
|
||||||
|
static const char *parse_uid(const char *restrict const str, uid_t *restrict const ret){
|
||||||
|
struct passwd *passwd_data;
|
||||||
|
char *endp;
|
||||||
|
unsigned long num;
|
||||||
|
static const char uidrange[] = "User ID out of range.";
|
||||||
|
static const char uidexist[] = "User name does not exist.";
|
||||||
|
num = strtoul(str, &endp, 0);
|
||||||
|
if(*endp != '\0'){ /* hmmm, try as login name */
|
||||||
|
passwd_data = getpwnam(str);
|
||||||
|
if(!passwd_data) return uidexist;
|
||||||
|
num = passwd_data->pw_uid;
|
||||||
|
}
|
||||||
|
if(num > 0xfffffffeUL) return uidrange;
|
||||||
|
*ret = num;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*###### Library Alternatives ##########################################*/
|
/*###### Library Alternatives ##########################################*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1721,6 +1765,8 @@ static void parse_args (char **args)
|
|||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
do {
|
do {
|
||||||
|
if (selection_type) std_err("conflicting process selection");
|
||||||
|
selection_type = 'p';
|
||||||
if (cp[1]) cp++;
|
if (cp[1]) cp++;
|
||||||
else if (*args) cp = *args++;
|
else if (*args) cp = *args++;
|
||||||
else std_err("-p argument missing");
|
else std_err("-p argument missing");
|
||||||
@ -1743,12 +1789,32 @@ static void parse_args (char **args)
|
|||||||
case 'S':
|
case 'S':
|
||||||
TOGw(Curwin, Show_CTIMES);
|
TOGw(Curwin, Show_CTIMES);
|
||||||
break;
|
break;
|
||||||
// case 'u':
|
case 'u':
|
||||||
// if (cp[1]) cp++;
|
do {
|
||||||
// else if (*args) cp = *args++;
|
const char *errmsg;
|
||||||
// else std_err("-u missing name");
|
if (selection_type) std_err("conflicting process selection");
|
||||||
// cp += snprintf(Curwin->colusrnam, USRNAMSIZ-1, "%s", cp);
|
if (cp[1]) cp++;
|
||||||
// break;
|
else if (*args) cp = *args++;
|
||||||
|
else std_err("-u missing name");
|
||||||
|
errmsg = parse_uid(cp, &selection_uid);
|
||||||
|
if (errmsg) std_err(errmsg);
|
||||||
|
selection_type = 'u';
|
||||||
|
cp += snprintf(Curwin->colusrnam, USRNAMSIZ-1, "%s", cp); // FIXME: junk
|
||||||
|
} while(0);
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
do {
|
||||||
|
const char *errmsg;
|
||||||
|
if (selection_type) std_err("conflicting process selection");
|
||||||
|
if (cp[1]) cp++;
|
||||||
|
else if (*args) cp = *args++;
|
||||||
|
else std_err("-u missing name");
|
||||||
|
errmsg = parse_uid(cp, &selection_uid);
|
||||||
|
if (errmsg) std_err(errmsg);
|
||||||
|
selection_type = 'U';
|
||||||
|
cp += snprintf(Curwin->colusrnam, USRNAMSIZ-1, "%s", cp); // FIXME: junk
|
||||||
|
} while(0);
|
||||||
|
break;
|
||||||
default :
|
default :
|
||||||
std_err(fmtmk("unknown argument '%c'\nusage:\t%s%s"
|
std_err(fmtmk("unknown argument '%c'\nusage:\t%s%s"
|
||||||
, *cp, Myname, usage));
|
, *cp, Myname, usage));
|
||||||
@ -2027,6 +2093,9 @@ static void reframewins (void)
|
|||||||
PSDBopen = 1;
|
PSDBopen = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (selection_type=='U') Frames_libflags |= L_status;
|
||||||
|
|
||||||
if (Frames_libflags & L_EITHER) {
|
if (Frames_libflags & L_EITHER) {
|
||||||
Frames_libflags &= ~L_EITHER;
|
Frames_libflags &= ~L_EITHER;
|
||||||
if (!(Frames_libflags & L_stat)) Frames_libflags |= L_status;
|
if (!(Frames_libflags & L_stat)) Frames_libflags |= L_status;
|
||||||
@ -2503,9 +2572,53 @@ static void do_key (unsigned c)
|
|||||||
TOGw(Curwin, View_STATES);
|
TOGw(Curwin, View_STATES);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// case 'u':
|
||||||
|
// if (VIZCHKc)
|
||||||
|
// strcpy(Curwin->colusrnam, ask4str("Which user (blank for all)"));
|
||||||
|
// break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
if (VIZCHKc)
|
// if (!VIZCHKc) break;
|
||||||
strcpy(Curwin->colusrnam, ask4str("Which user (blank for all)"));
|
do {
|
||||||
|
const char *errmsg;
|
||||||
|
const char *answer;
|
||||||
|
answer = ask4str("Which user (blank for all)");
|
||||||
|
// FIXME: do this better:
|
||||||
|
if (!answer || *answer=='\0' || *answer=='\n' || *answer=='\r' || *answer=='\t' || *answer==' ') {
|
||||||
|
selection_type = 0;
|
||||||
|
selection_uid = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
errmsg = parse_uid(answer, &selection_uid);
|
||||||
|
if (errmsg) {
|
||||||
|
show_msg(errmsg);
|
||||||
|
// Change settings here? I guess not.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selection_type = 'u';
|
||||||
|
} while(0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'U':
|
||||||
|
// if (!VIZCHKc) break;
|
||||||
|
do {
|
||||||
|
const char *errmsg;
|
||||||
|
const char *answer;
|
||||||
|
answer = ask4str("Which user (blank for all)");
|
||||||
|
// FIXME: do this better:
|
||||||
|
if (!answer || *answer=='\0' || *answer=='\n' || *answer=='\r' || *answer=='\t' || *answer==' ') {
|
||||||
|
selection_type = 0;
|
||||||
|
selection_uid = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
errmsg = parse_uid(answer, &selection_uid);
|
||||||
|
if (errmsg) {
|
||||||
|
show_msg(errmsg);
|
||||||
|
// Change settings here? I guess not.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
selection_type = 'U';
|
||||||
|
} while(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'w':
|
case 'w':
|
||||||
@ -2798,7 +2911,7 @@ static void task_show (const WIN_t *q, const proc_t *p)
|
|||||||
} while (p->cmdline[++j]);
|
} while (p->cmdline[++j]);
|
||||||
strim_1(tmp);
|
strim_1(tmp);
|
||||||
} else
|
} else
|
||||||
strcpy(tmp, fmtmk(CMDLINE_FMTS, p->cmd));
|
strcpy(tmp, fmtmk("[%s]", p->cmd));
|
||||||
cp = tmp;
|
cp = tmp;
|
||||||
} else
|
} else
|
||||||
cp = p->cmd;
|
cp = p->cmd;
|
||||||
@ -2964,10 +3077,9 @@ static void window_show (proc_t **ppt, WIN_t *q, int *lscr)
|
|||||||
lwin = 1;
|
lwin = 1;
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while ( -1 != ppt[i]->pid && *lscr < Max_lines
|
while ( -1 != ppt[i]->pid && *lscr < Max_lines && (!q->winlines || (lwin <= q->winlines)) ) {
|
||||||
&& (!q->winlines || (lwin <= q->winlines)) ) {
|
|
||||||
if ((CHKw(q, Show_IDLEPS) || ('S' != ppt[i]->state && 'Z' != ppt[i]->state))
|
if ((CHKw(q, Show_IDLEPS) || ('S' != ppt[i]->state && 'Z' != ppt[i]->state))
|
||||||
&& ((!q->colusrnam[0]) || (!strcmp(q->colusrnam, ppt[i]->euser)))) {
|
&& good_uid(ppt[i]) ) {
|
||||||
/*
|
/*
|
||||||
** Display a process Row */
|
** Display a process Row */
|
||||||
task_show(q, ppt[i]);
|
task_show(q, ppt[i]);
|
||||||
|
15
top.h
15
top.h
@ -24,7 +24,6 @@
|
|||||||
//#define CASEUP_HEXES /* show any hex values in upper case */
|
//#define CASEUP_HEXES /* show any hex values in upper case */
|
||||||
//#define CASEUP_SCALE /* show scaled time/num suffix upper case */
|
//#define CASEUP_SCALE /* show scaled time/num suffix upper case */
|
||||||
//#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */
|
//#define CASEUP_SUMMK /* show memory summary kilobytes with 'K' */
|
||||||
//#define POSIX_CMDLIN /* use '[ ]' for kernel threads, not '( )' */
|
|
||||||
//#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */
|
//#define SORT_SUPRESS /* *attempt* to reduce qsort overhead */
|
||||||
//#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */
|
//#define USE_LIB_STA3 /* use lib status (3 ch) vs. proc_t (1 ch) */
|
||||||
//#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */
|
//#define WARN_NOT_SMP /* restrict '1' & 'I' commands to true smp */
|
||||||
@ -326,9 +325,9 @@ typedef struct WIN_t {
|
|||||||
if nothing is specified by the loser, oops user */
|
if nothing is specified by the loser, oops user */
|
||||||
#define DEF_FIELDS "AEHIOQTWKNMbcdfgjplrsuvyzX"
|
#define DEF_FIELDS "AEHIOQTWKNMbcdfgjplrsuvyzX"
|
||||||
/* Pre-configured field groupss */
|
/* Pre-configured field groupss */
|
||||||
#define JOB_FIELDS "ABXcefgjlrstuvyzMKNHIWOPQD"
|
#define JOB_FIELDS "ABcefgjlrstuvyzMKNHIWOPQDX"
|
||||||
#define MEM_FIELDS "ANOPQRSTUVXbcdefgjlmyzWHIK"
|
#define MEM_FIELDS "ANOPQRSTUVbcdefgjlmyzWHIKX"
|
||||||
#define USR_FIELDS "DECGABXfhijlopqrstuvyzMKNW"
|
#define USR_FIELDS "ABDECGfhijlopqrstuvyzMKNWX"
|
||||||
/* Used by fields_sort, placed here for peace-of-mind */
|
/* Used by fields_sort, placed here for peace-of-mind */
|
||||||
#define NUL_FIELDS "abcdefghijklmnopqrstuvwxyz"
|
#define NUL_FIELDS "abcdefghijklmnopqrstuvwxyz"
|
||||||
|
|
||||||
@ -358,14 +357,6 @@ typedef struct WIN_t {
|
|||||||
#define CPU_FMTS_MULTI CPU_FMTS_JUST1
|
#define CPU_FMTS_MULTI CPU_FMTS_JUST1
|
||||||
#else
|
#else
|
||||||
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu"
|
#define CPU_FMTS_MULTI "cpu%*d %Lu %Lu %Lu %Lu %Lu"
|
||||||
#endif
|
|
||||||
|
|
||||||
/* This is the format for 'command line' display in the absence
|
|
||||||
of a command line (kernel thread). */
|
|
||||||
#ifdef POSIX_CMDLIN
|
|
||||||
#define CMDLINE_FMTS "[%s]"
|
|
||||||
#else
|
|
||||||
#define CMDLINE_FMTS "( %s )"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Summary Lines specially formatted string(s) --
|
/* Summary Lines specially formatted string(s) --
|
||||||
|
1
watch.c
1
watch.c
@ -21,6 +21,7 @@
|
|||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
|
#include "proc/procps.h"
|
||||||
|
|
||||||
static struct option longopts[] = {
|
static struct option longopts[] = {
|
||||||
{"differences", optional_argument, 0, 'd'},
|
{"differences", optional_argument, 0, 'd'},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user