aboutsummaryrefslogtreecommitdiff
path: root/toys/posix/ps.c
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2017-03-21 19:25:33 -0500
committerRob Landley <rob@landley.net>2017-03-21 19:25:33 -0500
commite97aeb6dea6ed654d599527c1f1d521e576743b4 (patch)
tree577c38f71fa2ae0da453cfebb2e7c0b755a240f4 /toys/posix/ps.c
parent47d07dc1554348b3b3a920627a538bd7164aeb8e (diff)
downloadtoybox-e97aeb6dea6ed654d599527c1f1d521e576743b4.tar.gz
dirtree_flagread() returns DIRTREE_ABORTVAL when the initial node doesn't
exist, which can hit ps when /proc isn't there or /proc/$PID/task isn't there (because process exited between the time we checked its contents and the time we looked for its threads).
Diffstat (limited to 'toys/posix/ps.c')
-rw-r--r--toys/posix/ps.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 41ddf6a4..0d79b5cb 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -896,6 +896,7 @@ static int get_threads(struct dirtree *new)
kcount = TT.kcount;
sprintf(toybuf, "/proc/%u/task", pid);
new->child = dirtree_flagread(toybuf, DIRTREE_SHUTUP|DIRTREE_PROC, get_ps);
+ if (new->child == DIRTREE_ABORTVAL) new->child = 0;
TT.threadparent = 0;
kcount = TT.kcount-kcount+1;
tb = (void *)new->extra;
@@ -1236,7 +1237,7 @@ void ps_main(void)
((toys.optflags&FLAG_T) || (TT.bits&(_PS_TID|_PS_TCNT)))
? get_threads : get_ps);
- if (toys.optflags&(FLAG_k|FLAG_M)) {
+ if ((dt != DIRTREE_ABORTVAL) && toys.optflags&(FLAG_k|FLAG_M)) {
struct carveup **tbsort = collate(TT.kcount, dt);
if (toys.optflags&FLAG_M) {
@@ -1365,6 +1366,7 @@ static void top_common(
dt = dirtree_flagread("/proc", DIRTREE_SHUTUP|DIRTREE_PROC,
((toys.optflags&FLAG_H) || (TT.bits&(_PS_TID|_PS_TCNT)))
? get_threads : get_ps);
+ if (dt == DIRTREE_ABORTVAL) error_exit("no /proc");
plnew->tb = collate(plnew->count = TT.kcount, dt);
TT.kcount = 0;