mirror of
https://github.com/opnsense/src.git
synced 2026-06-09 00:32:25 -04:00
ps(1): Have parsefmt() take the list of columns to update
This is in preparation for changing the behavior of the '-O' option.
While here, reformat the definition of 'struct varent', fix formatting
of that of 'struct var' and expand slightly their herald comments.
More reformatting/commenting in 'ps.h'.
No functional change intended.
Reviewed by: kib
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D49607
(cherry picked from commit 07a7557add)
This commit is contained in:
parent
57ed17ed2c
commit
b90923b63b
4 changed files with 28 additions and 25 deletions
|
|
@ -41,7 +41,7 @@ extern int cflag, eval, fscale, nlistread, rawcpu;
|
|||
extern unsigned long mempages;
|
||||
extern time_t now;
|
||||
extern int showthreads, sumrusage, termwidth;
|
||||
extern STAILQ_HEAD(velisthead, varent) varlist;
|
||||
extern struct velisthead varlist;
|
||||
|
||||
__BEGIN_DECLS
|
||||
char *arguments(KINFO *, VARENT *);
|
||||
|
|
@ -67,7 +67,7 @@ char *lockname(KINFO *, VARENT *);
|
|||
char *mwchan(KINFO *, VARENT *);
|
||||
char *nwchan(KINFO *, VARENT *);
|
||||
char *pagein(KINFO *, VARENT *);
|
||||
void parsefmt(const char *, int);
|
||||
void parsefmt(const char *, struct velisthead *, int);
|
||||
char *pcpu(KINFO *, VARENT *);
|
||||
char *pmem(KINFO *, VARENT *);
|
||||
char *pri(KINFO *, VARENT *);
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ static char sccsid[] = "@(#)keyword.c 8.5 (Berkeley) 4/2/94";
|
|||
|
||||
#include "ps.h"
|
||||
|
||||
static VAR *findvar(char *, int, char **header);
|
||||
static VAR *findvar(char *, struct velisthead *, int, char **header);
|
||||
static int vcmp(const void *, const void *);
|
||||
|
||||
/* Compute offset in common structures. */
|
||||
|
|
@ -260,7 +260,8 @@ showkey(void)
|
|||
}
|
||||
|
||||
void
|
||||
parsefmt(const char *p, int user)
|
||||
parsefmt(const char *p, struct velisthead *const var_list,
|
||||
const int user)
|
||||
{
|
||||
char *tempstr, *tempstr1;
|
||||
|
||||
|
|
@ -284,7 +285,7 @@ parsefmt(const char *p, int user)
|
|||
cp = tempstr;
|
||||
tempstr = NULL;
|
||||
}
|
||||
if (cp == NULL || !(v = findvar(cp, user, &hp)))
|
||||
if (cp == NULL || !(v = findvar(cp, var_list, user, &hp)))
|
||||
continue;
|
||||
if (!user) {
|
||||
/*
|
||||
|
|
@ -308,10 +309,10 @@ parsefmt(const char *p, int user)
|
|||
if (vent->var == NULL)
|
||||
xo_errx(1, "malloc failed");
|
||||
memcpy(vent->var, v, sizeof(*vent->var));
|
||||
STAILQ_INSERT_TAIL(&varlist, vent, next_ve);
|
||||
STAILQ_INSERT_TAIL(var_list, vent, next_ve);
|
||||
}
|
||||
free(tempstr1);
|
||||
if (STAILQ_EMPTY(&varlist)) {
|
||||
if (STAILQ_EMPTY(var_list)) {
|
||||
xo_warnx("no valid keywords; valid keywords:");
|
||||
showkey();
|
||||
exit(1);
|
||||
|
|
@ -319,7 +320,7 @@ parsefmt(const char *p, int user)
|
|||
}
|
||||
|
||||
static VAR *
|
||||
findvar(char *p, int user, char **header)
|
||||
findvar(char *p, struct velisthead *const var_list, int user, char **header)
|
||||
{
|
||||
size_t rflen;
|
||||
VAR *v, key;
|
||||
|
|
@ -340,7 +341,7 @@ findvar(char *p, int user, char **header)
|
|||
* process the alias.
|
||||
*/
|
||||
if (hp == NULL)
|
||||
parsefmt(v->alias, user);
|
||||
parsefmt(v->alias, var_list, user);
|
||||
else {
|
||||
/*
|
||||
* XXX - This processing will not be correct for
|
||||
|
|
@ -353,7 +354,7 @@ findvar(char *p, int user, char **header)
|
|||
if (realfmt == NULL)
|
||||
xo_errx(1, "malloc failed");
|
||||
snprintf(realfmt, rflen, "%s=%s", v->alias, hp);
|
||||
parsefmt(realfmt, user);
|
||||
parsefmt(realfmt, var_list, user);
|
||||
free(realfmt);
|
||||
}
|
||||
return ((VAR *)NULL);
|
||||
|
|
|
|||
20
bin/ps/ps.c
20
bin/ps/ps.c
|
|
@ -318,7 +318,7 @@ main(int argc, char *argv[])
|
|||
nselectors++;
|
||||
break;
|
||||
case 'j':
|
||||
parsefmt(jfmt, 0);
|
||||
parsefmt(jfmt, &varlist, 0);
|
||||
_fmt = 1;
|
||||
jfmt[0] = '\0';
|
||||
break;
|
||||
|
|
@ -326,7 +326,7 @@ main(int argc, char *argv[])
|
|||
showkey();
|
||||
exit(0);
|
||||
case 'l':
|
||||
parsefmt(lfmt, 0);
|
||||
parsefmt(lfmt, &varlist, 0);
|
||||
_fmt = 1;
|
||||
lfmt[0] = '\0';
|
||||
break;
|
||||
|
|
@ -340,14 +340,14 @@ main(int argc, char *argv[])
|
|||
nlistf = optarg;
|
||||
break;
|
||||
case 'O':
|
||||
parsefmt(o1, 1);
|
||||
parsefmt(optarg, 1);
|
||||
parsefmt(o2, 1);
|
||||
parsefmt(o1, &varlist, 1);
|
||||
parsefmt(optarg, &varlist, 1);
|
||||
parsefmt(o2, &varlist, 1);
|
||||
o1[0] = o2[0] = '\0';
|
||||
_fmt = 1;
|
||||
break;
|
||||
case 'o':
|
||||
parsefmt(optarg, 1);
|
||||
parsefmt(optarg, &varlist, 1);
|
||||
_fmt = 1;
|
||||
break;
|
||||
case 'p':
|
||||
|
|
@ -409,13 +409,13 @@ main(int argc, char *argv[])
|
|||
nselectors++;
|
||||
break;
|
||||
case 'u':
|
||||
parsefmt(ufmt, 0);
|
||||
parsefmt(ufmt, &varlist, 0);
|
||||
sortby = SORTCPU;
|
||||
_fmt = 1;
|
||||
ufmt[0] = '\0';
|
||||
break;
|
||||
case 'v':
|
||||
parsefmt(vfmt, 0);
|
||||
parsefmt(vfmt, &varlist, 0);
|
||||
sortby = SORTMEM;
|
||||
_fmt = 1;
|
||||
vfmt[0] = '\0';
|
||||
|
|
@ -445,7 +445,7 @@ main(int argc, char *argv[])
|
|||
xkeep = 1;
|
||||
break;
|
||||
case 'Z':
|
||||
parsefmt(Zfmt, 0);
|
||||
parsefmt(Zfmt, &varlist, 0);
|
||||
Zfmt[0] = '\0';
|
||||
break;
|
||||
case '?':
|
||||
|
|
@ -479,7 +479,7 @@ main(int argc, char *argv[])
|
|||
xo_errx(1, "%s", errbuf);
|
||||
|
||||
if (!_fmt)
|
||||
parsefmt(dfmt, 0);
|
||||
parsefmt(dfmt, &varlist, 0);
|
||||
|
||||
if (!all && nselectors == 0) {
|
||||
uidlist.l.ptr = malloc(sizeof(uid_t));
|
||||
|
|
|
|||
12
bin/ps/ps.h
12
bin/ps/ps.h
|
|
@ -55,13 +55,15 @@ typedef struct kinfo {
|
|||
STAILQ_HEAD(, kinfo_str) ki_ks;
|
||||
} KINFO;
|
||||
|
||||
/* Variables. */
|
||||
/* Keywords/variables to be printed. */
|
||||
typedef struct varent {
|
||||
STAILQ_ENTRY(varent) next_ve;
|
||||
const char *header;
|
||||
struct var *var;
|
||||
STAILQ_ENTRY(varent) next_ve;
|
||||
const char *header;
|
||||
struct var *var;
|
||||
} VARENT;
|
||||
STAILQ_HEAD(velisthead, varent);
|
||||
|
||||
/* Structure representing one available keyword. */
|
||||
typedef struct var {
|
||||
const char *name; /* name(s) of variable */
|
||||
const char *header; /* default header */
|
||||
|
|
@ -73,7 +75,7 @@ typedef struct var {
|
|||
#define INF127 0x10 /* values >127 displayed as 127 */
|
||||
u_int flag;
|
||||
/* output routine */
|
||||
char *(*oproc)(struct kinfo *, struct varent *);
|
||||
char *(*oproc)(struct kinfo *, struct varent *);
|
||||
/*
|
||||
* The following (optional) elements are hooks for passing information
|
||||
* to the generic output routine pvar (which prints simple elements
|
||||
|
|
|
|||
Loading…
Reference in a new issue