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
This commit is contained in:
parent
273ac7b968
commit
2e6c6ac4d7
16
bin/ps/ps.c
16
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user