2000-03-05 13:46:03 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
|
|
|
/*
|
|
|
|
* Mini uptime implementation for busybox
|
|
|
|
*
|
2004-03-15 13:59:22 +05:30
|
|
|
* Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
|
2000-03-05 13:46:03 +05:30
|
|
|
*
|
2006-09-22 08:22:41 +05:30
|
|
|
* Licensed under the GPL version 2, see the file LICENSE in this tarball.
|
2000-03-05 13:46:03 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
/* 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 10:30:29 +05:30
|
|
|
* of CONFIG_FEATURE_UTMP_SUPPORT #define
|
2000-03-05 13:46:03 +05:30
|
|
|
*/
|
|
|
|
|
2001-03-10 05:29:51 +05:30
|
|
|
/* getopt not needed */
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.h"
|
2000-03-05 13:46:03 +05:30
|
|
|
|
2005-08-27 23:48:06 +05:30
|
|
|
#ifndef FSHIFT
|
|
|
|
# define FSHIFT 16 /* nr of bits of precision */
|
|
|
|
#endif
|
2000-03-05 13:46:03 +05:30
|
|
|
#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 16:15:52 +05:30
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
|
2000-03-05 13:46:03 +05:30
|
|
|
{
|
|
|
|
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 16:40:50 +05:30
|
|
|
printf(" %02d:%02d:%02d up ",
|
|
|
|
current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
|
2000-03-05 13:46:03 +05:30
|
|
|
updays = (int) info.uptime / (60*60*24);
|
|
|
|
if (updays)
|
2001-01-18 08:27:08 +05:30
|
|
|
printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
|
2000-03-05 13:46:03 +05:30
|
|
|
upminutes = (int) info.uptime / 60;
|
|
|
|
uphours = (upminutes / 60) % 24;
|
|
|
|
upminutes %= 60;
|
2007-04-12 06:02:05 +05:30
|
|
|
if (uphours)
|
2001-01-18 08:27:08 +05:30
|
|
|
printf("%2d:%02d, ", uphours, upminutes);
|
2000-03-05 13:46:03 +05:30
|
|
|
else
|
2001-01-18 08:27:08 +05:30
|
|
|
printf("%d min, ", upminutes);
|
2000-03-05 13:46:03 +05:30
|
|
|
|
2004-03-15 13:59:22 +05:30
|
|
|
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 13:46:03 +05:30
|
|
|
LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
|
|
|
|
|
2000-12-01 08:25:13 +05:30
|
|
|
return EXIT_SUCCESS;
|
2000-03-05 13:46:03 +05:30
|
|
|
}
|