>From eec20b4e10a8f59a1880c2e05c2ed978ed3c5d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Mon, 19 May 2014 13:04:23 +0100 Subject: [PATCH] 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. --- ChangeLog | 6 ++++++ tests/test-getlogin_r.c | 29 ++++++++++++++++++++++++----- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index bcd414d..c91ac60 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 ed103c9..fb3f9bf 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__ -- 1.7.7.6