From: Pádraig Brady
Date: Mon, 19 May 2014 12:04:23 +0000 (+0100) Subject: getlogin_r-tests: avoid false failure under sudo/ssh etc. X-Git-Tag: v1.0~7384 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=eec20b4e;p=gnulib.git getlogin_r-tests: avoid false failure under sudo/ssh etc. * tests/test-getlogin_r.c (main): Sync up with test-getlogin.c changes from commit 97249cf29 to not depend on environment variables. --- diff --git a/ChangeLog b/ChangeLog index bcd414de92..c91ac60ce7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2014-05-19 Pádraig Brady
+ + getlogin_r-tests: avoid false failure under sudo/ssh etc. + * tests/test-getlogin_r.c (main): Sync up with test-getlogin.c + changes from commit 97249cf29 to not depend on environment variables. + 2014-05-18 Pádraig Brady
getlogin-tests: avoid false failure under cron diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c index ed103c9fc7..fb3f9bffb1 100644 --- a/tests/test-getlogin_r.c +++ b/tests/test-getlogin_r.c @@ -63,11 +63,30 @@ main (void) #if !((defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__) /* Unix platform */ { - const char *name = getenv ("LOGNAME"); - if (name == NULL || name[0] == '\0') - name = getenv ("USER"); - if (name != NULL && name[0] != '\0') - ASSERT (strcmp (buf, name) == 0); +# if HAVE_TTYNAME + const char *tty; + struct stat stat_buf; + struct passwd *pwd; + + tty = ttyname (STDIN_FILENO); + if (tty == NULL) + { + fprintf (stderr, "Skipping test: stdin is not a tty.\n"); + return 77; + } + + ASSERT (stat (tty, &stat_buf) == 0); + + pwd = getpwuid (stat_buf.st_uid); + if (! pwd) + { + fprintf (stderr, "Skipping test: no name found for uid %d\n", + stat_buf.st_uid); + return 77; + } + + ASSERT (strcmp (pwd->pw_name, buf) == 0); +# endif } #endif #if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__