From 94913b5d0c5687f19ed2a79f57a21a92e056eaa6 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 8 Oct 2023 21:01:26 -0500 Subject: [PATCH] SID can be 0 before PID 1 calls setsid() --- toys/posix/ps.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/toys/posix/ps.c b/toys/posix/ps.c index d0992619..e4a69a4f 100644 --- a/toys/posix/ps.c +++ b/toys/posix/ps.c @@ -981,7 +981,7 @@ static int get_ps(struct dirtree *new) // Store end of argv[0] so ARGS and CMDLINE can differ. // We do it for each file string slot but last is cmdline, which sticks. - slot[SLOT_argv0len] = temp ? temp : len; // Position of _first_ NUL + slot[SLOT_argv0len] = temp ? : len; // Position of _first_ NUL } // Each case above calculated/retained len, so we don't need to re-strlen. @@ -1166,8 +1166,9 @@ static char *parse_rest(void *data, char *str, int len) if (pl==&TT.ss && ll[pl->len]==0) ll[pl->len] = getsid(0); } + // PID can't be zero but SID can be 0 before the init task calls setsid(). if (pl==&TT.pp || pl==&TT.ss) { - if (num && ll[pl->len]>0) { + if (num && ll[pl->len]>-(pl==&TT.ss)) { pl->len++; return 0; -- 2.39.2