[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug-inetutils] [PATCH] Use a temporary `struct timeval' for gettimeofda
From: |
Guillem Jover |
Subject: |
[bug-inetutils] [PATCH] Use a temporary `struct timeval' for gettimeofday |
Date: |
Thu, 3 Dec 2009 21:08:53 +0100 |
User-agent: |
Mutt/1.5.20 (2009-06-14) |
The utmp structures match the on-disk format, and need to have the same
size independent of the wordsize of the machine. So we use timeval for
gettimeofday and copy the results to avoid any damage to the variables.
* ftpd/logwtmp.c (logwtmp) [_HAVE_UT_TV]: Use a `struct timeval' variable
to get the result from gettimeofday.
* libinetutils/logwtmp.c (logwtmp) [HAVE_STRUCT_UTMP_UT_TV]: Likewise.
* libinetutils/utmp_init.c (utmp_init) [HAVE_STRUCT_UTMPX_UT_TV]: Likewise.
* libinetutils/utmp_logout.c (utmp_logout): Likewise.
---
ftpd/logwtmp.c | 7 ++++++-
libinetutils/logwtmp.c | 7 ++++++-
libinetutils/utmp_init.c | 7 ++++++-
libinetutils/utmp_logout.c | 14 ++++++++++++--
4 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/ftpd/logwtmp.c b/ftpd/logwtmp.c
index 99e23f6..a21bd0c 100644
--- a/ftpd/logwtmp.c
+++ b/ftpd/logwtmp.c
@@ -74,6 +74,9 @@ void
logwtmp (const char *line, const char *name, const char *host)
{
struct utmp ut;
+#if _HAVE_UT_TV - 0
+ struct timeval tv;
+#endif
/* Set information in new entry. */
memset (&ut, 0, sizeof (ut));
@@ -87,7 +90,9 @@ logwtmp (const char *line, const char *name, const char *host)
#endif
#if _HAVE_UT_TV - 0
- gettimeofday (&ut.ut_tv, NULL);
+ gettimeofday (&tv, NULL);
+ ut.ut_tv.tv_sec = tv.tv_sec;
+ ut.ut_tv.tv_usec = tv.tv_usec;
#else
time (&ut.ut_time);
#endif
diff --git a/libinetutils/logwtmp.c b/libinetutils/logwtmp.c
index 0dad8cd..0940967 100644
--- a/libinetutils/logwtmp.c
+++ b/libinetutils/logwtmp.c
@@ -111,6 +111,9 @@ logwtmp (char *line, char *name, char *host)
#endif
{
struct utmp ut;
+#ifdef HAVE_STRUCT_UTMP_UT_TV
+ struct timeval tv;
+#endif
/* Set information in new entry. */
bzero (&ut, sizeof (ut));
@@ -124,7 +127,9 @@ logwtmp (char *line, char *name, char *host)
#endif
#ifdef HAVE_STRUCT_UTMP_UT_TV
- gettimeofday (&ut.ut_tv, NULL);
+ gettimeofday (&tv, NULL);
+ ut.ut_tv.tv_sec = tv.tv_sec;
+ ut.ut_tv.tv_usec = tv.tv_usec;
#else
time (&ut.ut_time);
#endif
diff --git a/libinetutils/utmp_init.c b/libinetutils/utmp_init.c
index 1ce2549..07fe050 100644
--- a/libinetutils/utmp_init.c
+++ b/libinetutils/utmp_init.c
@@ -76,6 +76,9 @@ utmp_init (char *line, char *user, char *id)
#else
struct utmp utx;
#endif
+#if defined(HAVE_STRUCT_UTMPX_UT_TV)
+ struct timeval tv;
+#endif
memset ((char *) &utx, 0, sizeof (utx));
#if defined(HAVE_STRUCT_UTMP_UT_ID)
@@ -94,7 +97,9 @@ utmp_init (char *line, char *user, char *id)
utx.ut_type = LOGIN_PROCESS;
#endif
#if defined(HAVE_STRUCT_UTMPX_UT_TV)
- gettimeofday (&(utx.ut_tv), 0);
+ gettimeofday (&tv, 0);
+ utx.ut_tv.tv_sec = tv.tv_sec;
+ utx.ut_tv.tv_usec = tv.tv_usec;
#else
time (&(utx.ut_time));
#endif
diff --git a/libinetutils/utmp_logout.c b/libinetutils/utmp_logout.c
index cea9e0d..cc36494 100644
--- a/libinetutils/utmp_logout.c
+++ b/libinetutils/utmp_logout.c
@@ -76,10 +76,14 @@ utmp_logout (char *line)
ut = getutxline (&utx);
if (ut)
{
+ struct timeval tv;
+
ut->ut_type = DEAD_PROCESS;
ut->ut_exit.e_termination = 0;
ut->ut_exit.e_exit = 0;
- gettimeofday (&(ut->ut_tv), 0);
+ gettimeofday (&tv, 0);
+ ut->ut_tv.tv_sec = tv_sec;
+ ut->ut_tv.tv_usec = tv_usec;
pututxline (ut);
updwtmpx (PATH_WTMPX, ut);
}
@@ -93,6 +97,10 @@ utmp_logout (char *line)
ut = getutline (&utx);
if (ut)
{
+# ifdef HAVE_STRUCT_UTMP_UT_TV
+ struct timeval tv;
+# endif
+
# ifdef HAVE_STRUCT_UTMP_UT_TYPE
ut->ut_type = DEAD_PROCESS;
# endif
@@ -101,7 +109,9 @@ utmp_logout (char *line)
ut->ut_exit.e_exit = 0;
# endif
# ifdef HAVE_STRUCT_UTMP_UT_TV
- gettimeofday (&(ut->ut_tv), 0);
+ gettimeofday (&tv, 0);
+ ut->ut_tv.tv_sec = tv.tv_sec;
+ ut->ut_tv.tv_usec = tv.tv_usec;
# else
time (&(ut->ut_time));
# endif
--
1.6.5.3
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [bug-inetutils] [PATCH] Use a temporary `struct timeval' for gettimeofday,
Guillem Jover <=