git: b90923b63bf3 - stable/14 - ps(1): Have parsefmt() take the list of columns to update
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 01 May 2025 19:51:30 UTC
The branch stable/14 has been updated by olce:
URL: https://cgit.FreeBSD.org/src/commit/?id=b90923b63bf3fc6827ddcf555a722fc0da959c5a
commit b90923b63bf3fc6827ddcf555a722fc0da959c5a
Author: Olivier Certner <olce@FreeBSD.org>
AuthorDate: 2025-02-27 17:15:14 +0000
Commit: Olivier Certner <olce@FreeBSD.org>
CommitDate: 2025-05-01 19:37:02 +0000
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 07a7557addc03acd28aaae55b90419c4ef9d9ad1)
---
bin/ps/extern.h | 4 ++--
bin/ps/keyword.c | 17 +++++++++--------
bin/ps/ps.c | 20 ++++++++++----------
bin/ps/ps.h | 12 +++++++-----
4 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index 6b07a79fbc20..45485c77732e 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -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 *);
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 7e37217f0219..9b733e0416ba 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -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);
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index 0d6365b22b3c..deb24c4785cb 100644
--- a/bin/ps/ps.c
+++ b/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));
diff --git a/bin/ps/ps.h b/bin/ps/ps.h
index 429dff632872..d21bf016bcca 100644
--- a/bin/ps/ps.h
+++ b/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