From 9e34771bb349f76d54c461b86bc9d8a78215f693 Mon Sep 17 00:00:00 2001 From: gad Date: Wed, 23 Jun 2004 21:17:25 +0000 Subject: [PATCH] Add a check for defunct processes in saveuser(), so the output for "args" (aka "command") will display "", as does the output from "comm" for those processes. Also do better checking for malloc() failures. Submitted by: Cyrille Lefevre --- bin/ps/ps.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/bin/ps/ps.c b/bin/ps/ps.c index 55d1920ab031..f4b0208bb942 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(""); + 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; }