uptime: Check the return value of various functions.
This commit is contained in:
parent
b51ca2a1f8
commit
2fc42db322
9
uptime.c
9
uptime.c
@ -39,15 +39,18 @@ static void print_uptime_since()
|
|||||||
struct timeval tim;
|
struct timeval tim;
|
||||||
|
|
||||||
/* Get the current time and convert it to a double */
|
/* Get the current time and convert it to a double */
|
||||||
gettimeofday(&tim, NULL);
|
if (gettimeofday(&tim, NULL) != 0)
|
||||||
|
xerr(EXIT_FAILURE, "gettimeofday");
|
||||||
now = tim.tv_sec + (tim.tv_usec / 1000000.0);
|
now = tim.tv_sec + (tim.tv_usec / 1000000.0);
|
||||||
|
|
||||||
/* Get the uptime and calculate when that was */
|
/* Get the uptime and calculate when that was */
|
||||||
uptime(&uptime_secs, &idle_secs);
|
if (uptime(&uptime_secs, &idle_secs) == 0)
|
||||||
|
xerrx(EXIT_FAILURE, "uptime");
|
||||||
up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
|
up_since_secs = (time_t) ((now - uptime_secs) + 0.5);
|
||||||
|
|
||||||
/* Show this */
|
/* Show this */
|
||||||
up_since = localtime(&up_since_secs);
|
if ((up_since = localtime(&up_since_secs)) == NULL)
|
||||||
|
xerrx(EXIT_FAILURE, "localtime");
|
||||||
printf("%04d-%02d-%02d %02d:%02d:%02d\n",
|
printf("%04d-%02d-%02d %02d:%02d:%02d\n",
|
||||||
up_since->tm_year + 1900, up_since->tm_mon + 1, up_since->tm_mday,
|
up_since->tm_year + 1900, up_since->tm_mon + 1, up_since->tm_mday,
|
||||||
up_since->tm_hour, up_since->tm_min, up_since->tm_sec);
|
up_since->tm_hour, up_since->tm_min, up_since->tm_sec);
|
||||||
|
Loading…
Reference in New Issue
Block a user