c6d234
commit ccb729df47188874401c655dda8d47b55cddd3b7
c6d234
Author: Joseph Myers <joseph@codesourcery.com>
c6d234
Date:   Wed Aug 19 00:50:17 2015 +0000
c6d234
c6d234
    Fix -Wundef warnings in login/tst-utmp.c.
c6d234
    
c6d234
    To remove -Wno-error=undef, we need to fix the remaining cases where
c6d234
    there are -Wundef warnings in the testsuite.  One of those places is
c6d234
    in login/tst-utmp.c.
c6d234
    
c6d234
    When included from tst-utmpx.c, <utmpx.h> is included instead of
c6d234
    <utmp.h>, meaning the _HAVE_UT_* macros are not defined.  The test is
c6d234
    prepared for them not being defined, in that all the relevant
c6d234
    conditionals also include "defined UTMPX".  However, they test the
c6d234
    _HAVE_UT_* macros first, so resulting in -Wundef warnings.
c6d234
    
c6d234
    This patch does the minimal fix of swapping the || operands.  This is
c6d234
    logically correct - avoiding checking a macro we know will not be
c6d234
    defined in the case where it is not defined.  It won't fix such
c6d234
    warnings for the case where the toplevel bits/utmp.h is used and most
c6d234
    _HAVE_UT_* aren't defined at all even when <utmp.h> is included, but
c6d234
    that case doesn't apply to any current glibc configuration.  Fixing it
c6d234
    would also be tricky in that, while glibc itself consistently uses
c6d234
    _HAVE_UT_* in ways that would work with 0 instead of undefined,
c6d234
    external packages that use the macros expect defined / undefined
c6d234
    instead of 1 / 0 (codesearch.debian.net shows uses by util-linux,
c6d234
    python-utmp, libsys-utmp-perl).
c6d234
    
c6d234
    Tested for x86_64.
c6d234
    
c6d234
            * login/tst-utmp.c [_HAVE_UT_TYPE || defined UTMPX]: Change
c6d234
            conditional to [defined UTMPX || _HAVE_UT_TYPE].
c6d234
            [_HAVE_UT_TV || defined UTMPX]: Change conditional to [defined
c6d234
            UTMPX || _HAVE_UT_TV].
c6d234
            [_HAVE_UT_TV - 0 || defined UTMPX]: Change conditional to [defined
c6d234
            UTMPX || _HAVE_UT_TV - 0].
c6d234
c6d234
diff --git a/login/tst-utmp.c b/login/tst-utmp.c
c6d234
index 7cc39cb2b7ff2dba..84945934e249ca25 100644
c6d234
--- a/login/tst-utmp.c
c6d234
+++ b/login/tst-utmp.c
c6d234
@@ -39,7 +39,7 @@
c6d234
 #endif
c6d234
 
c6d234
 
c6d234
-#if _HAVE_UT_TYPE || defined UTMPX
c6d234
+#if defined UTMPX || _HAVE_UT_TYPE
c6d234
 
c6d234
 /* Prototype for our test function.  */
c6d234
 static int do_test (int argc, char *argv[]);
c6d234
@@ -75,7 +75,7 @@ do_prepare (int argc, char *argv[])
c6d234
 
c6d234
 struct utmp entry[] =
c6d234
 {
c6d234
-#if _HAVE_UT_TV || defined UTMPX
c6d234
+#if defined UTMPX || _HAVE_UT_TV
c6d234
 #define UT(a)  .ut_tv = { .tv_sec = (a)}
c6d234
 #else
c6d234
 #define UT(a)  .ut_time = (a)
c6d234
@@ -167,7 +167,7 @@ simulate_login (const char *line, const char *user)
c6d234
 	    entry[n].ut_pid = (entry_pid += 27);
c6d234
 	  entry[n].ut_type = USER_PROCESS;
c6d234
 	  strncpy (entry[n].ut_user, user, sizeof (entry[n].ut_user));
c6d234
-#if _HAVE_UT_TV - 0 || defined UTMPX
c6d234
+#if defined UTMPX || _HAVE_UT_TV - 0
c6d234
 	  entry[n].ut_tv.tv_sec = (entry_time += 1000);
c6d234
 #else
c6d234
           entry[n].ut_time = (entry_time += 1000);
c6d234
@@ -201,7 +201,7 @@ simulate_logout (const char *line)
c6d234
 	{
c6d234
 	  entry[n].ut_type = DEAD_PROCESS;
c6d234
 	  strncpy (entry[n].ut_user, "", sizeof (entry[n].ut_user));
c6d234
-#if _HAVE_UT_TV - 0 || defined UTMPX
c6d234
+#if defined UTMPX || _HAVE_UT_TV - 0
c6d234
           entry[n].ut_tv.tv_sec = (entry_time += 1000);
c6d234
 #else
c6d234
           entry[n].ut_time = (entry_time += 1000);