summaryrefslogtreecommitdiffstats
path: root/bin/ps
diff options
context:
space:
mode:
authorgad <gad@FreeBSD.org>2004-03-18 01:28:23 +0000
committergad <gad@FreeBSD.org>2004-03-18 01:28:23 +0000
commitabf08cd271727dac4862860ec2d4ebffeb015ce6 (patch)
tree8c703715388d617999beb72351507e01aee3bb92 /bin/ps
parent5ddc04cafb528c82697d84d3df3b90e35c5d869f (diff)
downloadFreeBSD-src-abf08cd271727dac4862860ec2d4ebffeb015ce6.zip
FreeBSD-src-abf08cd271727dac4862860ec2d4ebffeb015ce6.tar.gz
Fix 'ps -p proclist' and 'ps -u userlist' so the command returns non-zero
if no processes were matched. Also sorts the list of 'int's in main, as long as I had to add another one... Noticed by: Nate Lawson MFC after: 10 days
Diffstat (limited to 'bin/ps')
-rw-r--r--bin/ps/ps.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c
index d458d46..d5417a3 100644
--- a/bin/ps/ps.c
+++ b/bin/ps/ps.c
@@ -129,8 +129,9 @@ main(int argc, char *argv[])
dev_t ttydev;
pid_t *pids;
uid_t *uids;
- int all, ch, flag, i, _fmt, lineno, nentries, nocludge, dropgid;
- int prtheader, wflag, what, xflg, pid, uid, npids, nuids, showthreads;
+ int all, ch, dropgid, flag, _fmt, i, lineno;
+ int nentries, nocludge, noutput, npids, nuids, pid;
+ int prtheader, showthreads, uid, wflag, what, xflg;
char *cols;
char errbuf[_POSIX2_LINE_MAX];
const char *cp, *nlistf, *memf;
@@ -395,6 +396,7 @@ main(int argc, char *argv[])
/*
* for each proc, call each variable output function.
*/
+ noutput = 0;
for (i = lineno = 0; i < nentries; i++) {
if (xflg == 0 && ((&kinfo[i])->ki_p->ki_tdev == NODEV ||
((&kinfo[i])->ki_p->ki_flag & P_CONTROLT ) == 0))
@@ -419,13 +421,21 @@ main(int argc, char *argv[])
(void)putchar(' ');
}
(void)putchar('\n');
+ noutput++;
if (prtheader && lineno++ == prtheader - 4) {
(void)putchar('\n');
printheader();
lineno = 0;
}
}
- free(uids);
+ if (pids != NULL)
+ free(pids);
+ if (uids != NULL)
+ free(uids);
+
+ /* Check if '-p proclist' or '-u userlist' matched zero processes */
+ if (noutput == 0)
+ eval = 1;
exit(eval);
}
OpenPOWER on IntegriCloud