summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorjmallett <jmallett@FreeBSD.org>2003-01-19 00:22:34 +0000
committerjmallett <jmallett@FreeBSD.org>2003-01-19 00:22:34 +0000
commit0c8d64a2c4ed9577970bc064bd9354ec7fa78297 (patch)
tree2986fc8ec7518040f3f7cba46759c64c32ef7920 /bin/ps
parent6f344674a0af04f9a80844d7e0495643cfd96161 (diff)
downloadFreeBSD-src-0c8d64a2c4ed9577970bc064bd9354ec7fa78297.zip
FreeBSD-src-0c8d64a2c4ed9577970bc064bd9354ec7fa78297.tar.gz
When inserting a non-user-specified (e.g. not via -o or -O) format, don't dupe
one that is already there. This is consistent with GNU ps(1)'s BSD mode, and POLA. Reported by: Andy Farkas <andyf@speednet.com.au> Tested by: Andy Farkas <andyf@speednet.com.au>
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/extern.h3
-rw-r--r--bin/ps/keyword.c20
-rw-r--r--bin/ps/ps.c32
3 files changed, 39 insertions, 16 deletions
diff --git a/bin/ps/extern.h b/bin/ps/extern.h
index ea603a4..54747a2 100644
--- a/bin/ps/extern.h
+++ b/bin/ps/extern.h
@@ -52,6 +52,7 @@ void command(KINFO *, VARENT *);
void cputime(KINFO *, VARENT *);
int donlist(void);
void elapsed(KINFO *, VARENT *);
+VARENT *find_varentry(VAR *);
const char *fmt_argv(char **, char *, size_t);
double getpcpu(const KINFO *);
void kvar(KINFO *, VARENT *);
@@ -63,7 +64,7 @@ void maxrss(KINFO *, VARENT *);
void lockname(KINFO *, VARENT *);
void mwchan(KINFO *, VARENT *);
void pagein(KINFO *, VARENT *);
-void parsefmt(const char *);
+void parsefmt(const char *, int);
void pcpu(KINFO *, VARENT *);
void pmem(KINFO *, VARENT *);
void pri(KINFO *, VARENT *);
diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c
index 82a3674..045a7b0 100644
--- a/bin/ps/keyword.c
+++ b/bin/ps/keyword.c
@@ -54,7 +54,7 @@ __FBSDID("$FreeBSD$");
#include "ps.h"
-static VAR *findvar(char *);
+static VAR *findvar(char *, int);
static int vcmp(const void *, const void *);
/* Compute offset in common structures. */
@@ -223,7 +223,7 @@ showkey(void)
}
void
-parsefmt(const char *p)
+parsefmt(const char *p, int user)
{
static struct varent *vtail;
char *tempstr, *tempstr1;
@@ -248,8 +248,18 @@ parsefmt(const char *p)
cp = tempstr;
tempstr = NULL;
}
- if (cp == NULL || !(v = findvar(cp)))
+ if (cp == NULL || !(v = findvar(cp, user)))
continue;
+ if (!user) {
+ /*
+ * If the user is NOT adding this field manually,
+ * get on with our lives if this VAR is already
+ * represented in the list.
+ */
+ vent = find_varentry(v);
+ if (vent != NULL)
+ continue;
+ }
if ((vent = malloc(sizeof(struct varent))) == NULL)
errx(1, "malloc failed");
vent->var = malloc(sizeof(*vent->var));
@@ -273,7 +283,7 @@ parsefmt(const char *p)
}
static VAR *
-findvar(char *p)
+findvar(char *p, int user)
{
VAR *v, key;
char *hp;
@@ -290,7 +300,7 @@ findvar(char *p)
warnx("%s: illegal keyword specification", p);
eval = 1;
}
- parsefmt(v->alias);
+ parsefmt(v->alias, user);
return ((VAR *)NULL);
}
if (!v) {
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index acdade0..24e47eb 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -193,7 +193,7 @@ main(int argc, char *argv[])
prtheader = ws.ws_row > 5 ? ws.ws_row : 22;
break;
case 'j':
- parsefmt(jfmt);
+ parsefmt(jfmt, 0);
_fmt = 1;
jfmt[0] = '\0';
break;
@@ -201,7 +201,7 @@ main(int argc, char *argv[])
showkey();
exit(0);
case 'l':
- parsefmt(lfmt);
+ parsefmt(lfmt, 0);
_fmt = 1;
lfmt[0] = '\0';
break;
@@ -217,14 +217,14 @@ main(int argc, char *argv[])
dropgid = 1;
break;
case 'O':
- parsefmt(o1);
- parsefmt(optarg);
- parsefmt(o2);
+ parsefmt(o1, 1);
+ parsefmt(optarg, 1);
+ parsefmt(o2, 1);
o1[0] = o2[0] = '\0';
_fmt = 1;
break;
case 'o':
- parsefmt(optarg);
+ parsefmt(optarg, 1);
_fmt = 1;
break;
#if defined(LAZY_PS)
@@ -270,13 +270,13 @@ main(int argc, char *argv[])
xflg++; /* XXX: intuitive? */
break;
case 'u':
- parsefmt(ufmt);
+ parsefmt(ufmt, 0);
sortby = SORTCPU;
_fmt = 1;
ufmt[0] = '\0';
break;
case 'v':
- parsefmt(vfmt);
+ parsefmt(vfmt, 0);
sortby = SORTMEM;
_fmt = 1;
vfmt[0] = '\0';
@@ -292,7 +292,7 @@ main(int argc, char *argv[])
xflg = 1;
break;
case 'Z':
- parsefmt(Zfmt);
+ parsefmt(Zfmt, 0);
Zfmt[0] = '\0';
break;
case '?':
@@ -325,7 +325,7 @@ main(int argc, char *argv[])
errx(1, "%s", errbuf);
if (!_fmt)
- parsefmt(dfmt);
+ parsefmt(dfmt, 0);
/* XXX - should be cleaner */
if (!all && ttydev == NODEV && pid == -1 && !nuids) {
@@ -456,6 +456,18 @@ getuids(const char *arg, int *nuids)
return uids;
}
+VARENT *
+find_varentry(VAR *v)
+{
+ struct varent *vent;
+
+ for (vent = vhead; vent; vent = vent->next) {
+ if (strcmp(vent->var->name, v->name) == 0)
+ return vent;
+ }
+ return NULL;
+}
+
static void
scanvars(void)
{
OpenPOWER on IntegriCloud