Only check errno if getpwuid() fails

Checking errno otherwise is unspecified.
This commit is contained in:
Hiltjo Posthuma 2014-07-09 15:42:54 +00:00 committed by sin
parent 291aedb875
commit e45e64491e
1 changed files with 6 additions and 2 deletions

8
ps.c
View File

@ -136,8 +136,12 @@ psout(struct procstat *ps)
} else {
errno = 0;
pw = getpwuid(pstatus.uid);
if (errno || !pw)
eprintf("getpwuid %d:", pstatus.uid);
if (!pw) {
if (errno)
eprintf("getpwuid %d:", pstatus.uid);
else
eprintf("getpwuid %d: no such user\n", id);
}
if (sysinfo(&info) < 0)
eprintf("sysinfo:");