Only check errno if getpwnam() fails

This commit is contained in:
sin 2014-08-18 21:49:22 +01:00
parent e4677f290b
commit 6af24e35f9
1 changed files with 7 additions and 5 deletions

12
login.c
View File

@ -74,13 +74,15 @@ main(int argc, char *argv[])
if (isatty(STDIN_FILENO) == 0)
eprintf("stdin is not a tty\n");
errno = 0;
user = argv[0];
errno = 0;
pw = getpwnam(user);
if (errno)
eprintf("getpwnam: %s:", user);
else if (!pw)
eprintf("who are you?\n");
if (!pw) {
if (errno)
eprintf("getpwnam: %s:", user);
else
eprintf("who are you?\n");
}
uid = pw->pw_uid;
gid = pw->pw_gid;