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
This commit is contained in:
Garance A Drosehn 2004-06-23 21:17:25 +00:00
parent b950fbe67b
commit dd693acf27
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=130991

View File

@ -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;
}