From 620ee81b7ea055b1fa44c98d0ab5a3309ae7565a Mon Sep 17 00:00:00 2001 From: nekral-guest Date: Wed, 22 Apr 2009 21:06:13 +0000 Subject: [PATCH] * libmisc/utmp.c: Only set ut_time and ut_tv if gettimeofday() succeeds. --- ChangeLog | 5 +++++ libmisc/utmp.c | 22 ++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index f37e2a87..9547816a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2009-04-22 Nicolas François + + * libmisc/utmp.c: Only set ut_time and ut_tv if gettimeofday() + succeeds. + 2009-04-22 Nicolas François * libmisc/utmp.c: Fix the check for empty host in prepare_utmp() diff --git a/libmisc/utmp.c b/libmisc/utmp.c index 8030908a..2c989827 100644 --- a/libmisc/utmp.c +++ b/libmisc/utmp.c @@ -284,17 +284,18 @@ struct utmp *prepare_utmp (const char *name, } /* ut_exit is only for DEAD_PROCESS */ utent->ut_session = getsid (0); - gettimeofday (&tv, NULL); + if (gettimeofday (&tv, NULL) == 0) { #ifdef HAVE_STRUCT_UTMP_UT_TIME - utent->ut_time = tv.tv_sec; + utent->ut_time = tv.tv_sec; #endif /* HAVE_STRUCT_UTMP_UT_TIME */ #ifdef HAVE_STRUCT_UTMP_UT_XTIME - utent->ut_xtime = tv.tv_usec; + utent->ut_xtime = tv.tv_usec; #endif /* HAVE_STRUCT_UTMP_UT_XTIME */ #ifdef HAVE_STRUCT_UTMP_UT_TV - utent->ut_tv.tv_sec = tv.tv_sec; - utent->ut_tv.tv_usec = tv.tv_usec; + utent->ut_tv.tv_sec = tv.tv_sec; + utent->ut_tv.tv_usec = tv.tv_usec; #endif /* HAVE_STRUCT_UTMP_UT_TV */ + } return utent; } @@ -423,15 +424,16 @@ struct utmpx *prepare_utmpx (const char *name, } /* ut_exit is only for DEAD_PROCESS */ utxent->ut_session = getsid (0); - gettimeofday (&tv, NULL); + if (gettimeofday (&tv, NULL) == 0) { #ifdef HAVE_STRUCT_UTMPX_UT_TIME - utxent->ut_time = tv.tv_sec; + utxent->ut_time = tv.tv_sec; #endif /* HAVE_STRUCT_UTMPX_UT_TIME */ #ifdef HAVE_STRUCT_UTMPX_UT_XTIME - utxent->ut_xtime = tv.tv_usec; + utxent->ut_xtime = tv.tv_usec; #endif /* HAVE_STRUCT_UTMPX_UT_XTIME */ - utxent->ut_tv.tv_sec = tv.tv_sec; - utxent->ut_tv.tv_usec = tv.tv_usec; + utxent->ut_tv.tv_sec = tv.tv_sec; + utxent->ut_tv.tv_usec = tv.tv_usec; + } return utxent; }