diff options
author | gad <gad@FreeBSD.org> | 2004-06-23 21:17:25 +0000 |
---|---|---|
committer | gad <gad@FreeBSD.org> | 2004-06-23 21:17:25 +0000 |
commit | 9e34771bb349f76d54c461b86bc9d8a78215f693 (patch) | |
tree | e9721c63aa044e2e8fbcb62891c82f8b5778127e /bin/ps/ps.c | |
parent | 6c59c5fae62be57d80a248a7e17a2df5fff32afe (diff) | |
download | FreeBSD-src-9e34771bb349f76d54c461b86bc9d8a78215f693.zip FreeBSD-src-9e34771bb349f76d54c461b86bc9d8a78215f693.tar.gz |
Add a check for defunct processes in saveuser(), so the output for "args"
(aka "command") will display "<defunct>", as does the output from "comm"
for those processes. Also do better checking for malloc() failures.
Submitted by: Cyrille Lefevre
Diffstat (limited to 'bin/ps/ps.c')
-rw-r--r-- | bin/ps/ps.c | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 55d1920..f4b0208 100644 --- a/bin/ps/ps.c +++ b/bin/ps/ps.c @@ -977,19 +977,27 @@ saveuser(KINFO *ki) /* * save arguments if needed */ - if (needcomm && (UREADOK(ki) || (ki->ki_p->ki_args != NULL))) { - ki->ki_args = strdup(fmt(kvm_getargv, ki, ki->ki_p->ki_comm, - MAXCOMLEN)); - } else if (needcomm) { - asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); + if (needcomm) { + if (ki->ki_p->ki_stat == SZOMB) + ki->ki_args = strdup("<defunct>"); + else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL)) + ki->ki_args = strdup(fmt(kvm_getargv, ki, + ki->ki_p->ki_comm, MAXCOMLEN)); + else + asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm); + if (ki->ki_env == NULL) + errx(1, "malloc failed"); } else { ki->ki_args = NULL; } - if (needenv && UREADOK(ki)) { - ki->ki_env = strdup(fmt(kvm_getenvv, ki, (char *)NULL, 0)); - } else if (needenv) { - ki->ki_env = malloc(3); - strcpy(ki->ki_env, "()"); + if (needenv) { + if (UREADOK(ki)) + ki->ki_env = strdup(fmt(kvm_getenvv, ki, + (char *)NULL, 0)); + else + ki->ki_env = strdup("()"); + if (ki->ki_env == NULL) + errx(1, "malloc failed"); } else { ki->ki_env = NULL; } |