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:
parent
6c59c5fae6
commit
9e34771bb3
28
bin/ps/ps.c
28
bin/ps/ps.c
@ -977,19 +977,27 @@ saveuser(KINFO *ki)
|
|||||||
/*
|
/*
|
||||||
* save arguments if needed
|
* save arguments if needed
|
||||||
*/
|
*/
|
||||||
if (needcomm && (UREADOK(ki) || (ki->ki_p->ki_args != NULL))) {
|
if (needcomm) {
|
||||||
ki->ki_args = strdup(fmt(kvm_getargv, ki, ki->ki_p->ki_comm,
|
if (ki->ki_p->ki_stat == SZOMB)
|
||||||
MAXCOMLEN));
|
ki->ki_args = strdup("<defunct>");
|
||||||
} else if (needcomm) {
|
else if (UREADOK(ki) || (ki->ki_p->ki_args != NULL))
|
||||||
asprintf(&ki->ki_args, "(%s)", ki->ki_p->ki_comm);
|
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 {
|
} else {
|
||||||
ki->ki_args = NULL;
|
ki->ki_args = NULL;
|
||||||
}
|
}
|
||||||
if (needenv && UREADOK(ki)) {
|
if (needenv) {
|
||||||
ki->ki_env = strdup(fmt(kvm_getenvv, ki, (char *)NULL, 0));
|
if (UREADOK(ki))
|
||||||
} else if (needenv) {
|
ki->ki_env = strdup(fmt(kvm_getenvv, ki,
|
||||||
ki->ki_env = malloc(3);
|
(char *)NULL, 0));
|
||||||
strcpy(ki->ki_env, "()");
|
else
|
||||||
|
ki->ki_env = strdup("()");
|
||||||
|
if (ki->ki_env == NULL)
|
||||||
|
errx(1, "malloc failed");
|
||||||
} else {
|
} else {
|
||||||
ki->ki_env = NULL;
|
ki->ki_env = NULL;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user