2000-03-05 08:16:03 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini uptime implementation for busybox
|
|
|
|
*
|
2004-03-15 08:29:22 +00:00
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2000-03-05 08:16:03 +00:00
|
|
|
*
|
2006-09-22 02:52:41 +00:00
|
|
|
* Licensed under the GPL version 2, see the file LICENSE in this tarball.
|
2000-03-05 08:16:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/* This version of uptime doesn't display the number of users on the system,
|
|
|
|
* since busybox init doesn't mess with utmp. For folks using utmp that are
|
|
|
|
* just dying to have # of users reported, feel free to write it as some type
|
2001-10-24 05:00:29 +00:00
|
|
|
* of CONFIG_FEATURE_UTMP_SUPPORT #define
|
2000-03-05 08:16:03 +00:00
|
|
|
*/
|
|
|
|
|
2001-03-09 23:59:51 +00:00
|
|
|
/* getopt not needed */
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2000-03-05 08:16:03 +00:00
|
|
|
|
2005-08-27 18:18:06 +00:00
|
|
|
#ifndef FSHIFT
|
|
|
|
# define FSHIFT 16 /* nr of bits of precision */
|
|
|
|
#endif
|
2000-03-05 08:16:03 +00:00
|
|
|
#define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
|
|
|
|
#define LOAD_INT(x) ((x) >> FSHIFT)
|
|
|
|
#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
|
|
|
|
|
2000-06-26 10:45:52 +00:00
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2006-03-06 20:47:33 +00:00
|
|
|
int uptime_main(int argc, char **argv)
|
2000-03-05 08:16:03 +00:00
|
|
|
{
|
|
|
|
int updays, uphours, upminutes;
|
|
|
|
struct sysinfo info;
|
|
|
|
struct tm *current_time;
|
|
|
|
time_t current_secs;
|
|
|
|
|
|
|
|
time(¤t_secs);
|
|
|
|
current_time = localtime(¤t_secs);
|
|
|
|
|
|
|
|
sysinfo(&info);
|
|
|
|
|
2004-04-06 11:10:50 +00:00
|
|
|
printf(" %02d:%02d:%02d up ",
|
|
|
|
current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
|
2000-03-05 08:16:03 +00:00
|
|
|
updays = (int) info.uptime / (60*60*24);
|
|
|
|
if (updays)
|
2001-01-18 02:57:08 +00:00
|
|
|
printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
|
2000-03-05 08:16:03 +00:00
|
|
|
upminutes = (int) info.uptime / 60;
|
|
|
|
uphours = (upminutes / 60) % 24;
|
|
|
|
upminutes %= 60;
|
2007-04-12 00:32:05 +00:00
|
|
|
if (uphours)
|
2001-01-18 02:57:08 +00:00
|
|
|
printf("%2d:%02d, ", uphours, upminutes);
|
2000-03-05 08:16:03 +00:00
|
|
|
else
|
2001-01-18 02:57:08 +00:00
|
|
|
printf("%d min, ", upminutes);
|
2000-03-05 08:16:03 +00:00
|
|
|
|
2004-03-15 08:29:22 +00:00
|
|
|
printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
|
|
|
|
LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
|
|
|
|
LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
|
2000-03-05 08:16:03 +00:00
|
|
|
LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
|
|
|
|
|
2000-12-01 02:55:13 +00:00
|
|
|
return EXIT_SUCCESS;
|
2000-03-05 08:16:03 +00:00
|
|
|
}
|