This is the mail archive of the libc-alpha@sources.redhat.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] utmp again


Found this looking into some compiler warnings.

For PowerPC64 time_t is 64-bit but to maintain compatibility with
PowerPC32 applications struct utmp field ut_tv uses 32-bit fields to
match the 32-bit struct timeval.  This was part of the fix for
getlogin(). 

But I missed the usage of utmp in ./login/logout.c and ./login/logwtmp.c
which pass the address of ut_tv as the first parm to gettimeofday(). 
This causes a compiler warning since for [__WORDSIZE == 64 && defined
__WORDSIZE_COMPAT32], ut_tv is not compatible with struct timeval as
required by gettimeofday. 

2002-09-30  Steven Munroe  <sjmunroe@us.ibm.com>

	* login/logout.c [__WORDSIZE_COMPAT32]: Don't assume ut_tv has the
	same size as struct timeval for gettimeofday().
	* login/logwtpm.c [__WORDSIZE_COMPAT32]: Don't assume ut_tv has the
	same size as struct timeval for gettimeofday().

-- 
Steven Munroe
sjmunroe@us.ibm.com
Linux on PowerPC-64 Development
GLIBC for PowerPC-64 Development
diff -rupPN -xCVS -xmanual -x'*orig' glibc-2.3.1/login/logout.c libc231/login/logout.c
--- glibc-2.3.1/login/logout.c	2002-09-20 19:28:20.000000000 -0500
+++ libc231/login/logout.c	2002-10-23 15:48:43.000000000 -0500
@@ -51,7 +51,22 @@ logout (const char *line)
       bzero (ut->ut_host, sizeof ut->ut_host);
 #endif
 #if _HAVE_UT_TV - 0
+# if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
+      {
+        /* 64-bit systems that have 64-bit time_t may need to maintain
+           compatibility with 32-bit code that reads and writes utmp files.
+           In this case ut_tv is not compatible with the struct timeval 
+           required by gettimeofday().  So allocate a temporary struct
+           timeval for the gettimeofday call then copy the fields into
+           ut_tv.  */
+      	struct timeval temp;
+        gettimeofday (&temp, NULL);
+        ut->ut_tv.tv_sec = temp.tv_sec;	
+        ut->ut_tv.tv_usec = temp.tv_usec;
+      }
+# else
       gettimeofday (&ut->ut_tv, NULL);
+# endif
 #else
       ut->ut_time = time (NULL);
 #endif
diff -rupPN -xCVS -xmanual -x'*orig' glibc-2.3.1/login/logwtmp.c libc231/login/logwtmp.c
--- glibc-2.3.1/login/logwtmp.c	2002-09-20 19:28:20.000000000 -0500
+++ libc231/login/logwtmp.c	2002-10-23 15:50:00.000000000 -0500
@@ -44,7 +44,22 @@ logwtmp (const char *line, const char *n
 #endif
 
 #if _HAVE_UT_TV - 0
-  __gettimeofday (&ut.ut_tv, NULL);
+# if __WORDSIZE == 64 && defined __WORDSIZE_COMPAT32
+  {
+    /* 64-bit systems that have 64-bit time_t may need to maintain
+       compatibility with 32-bit code that reads and writes utmp files.
+       In this case ut_tv is not compatible with the struct timeval 
+       required by gettimeofday().  So allocate a temporary struct
+       timeval for the gettimeofday call then copy the fields into
+       ut_tv.  */
+    struct timeval temp;
+    gettimeofday (&temp, NULL);
+    ut.ut_tv.tv_sec = temp.tv_sec;	
+    ut.ut_tv.tv_usec = temp.tv_usec;
+  }
+# else
+  gettimeofday (&ut.ut_tv, NULL);
+# endif
 #else
   ut.ut_time = time (NULL);
 #endif

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]