# HG changeset patch # User Pádraig Brady # Date 1400501063 -3600 # Node ID 59df01cdab26c5edc62eb6116bffdf58b0c3d10a # Parent 9454e10c1c1eaf94696072fabe7c82e15893187f 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 -r 9454e10c1c1e -r 59df01cdab26 ChangeLog --- a/ChangeLog Sun May 18 02:48:03 2014 +0100 +++ b/ChangeLog Mon May 19 13:04:23 2014 +0100 @@ -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 -r 9454e10c1c1e -r 59df01cdab26 tests/test-getlogin_r.c --- a/tests/test-getlogin_r.c Sun May 18 02:48:03 2014 +0100 +++ b/tests/test-getlogin_r.c Mon May 19 13:04:23 2014 +0100 @@ -63,11 +63,30 @@ #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__