1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#include "libbb.h"
19
20#ifndef FSHIFT
21# define FSHIFT 16
22#endif
23#define FIXED_1 (1<<FSHIFT)
24#define LOAD_INT(x) ((x) >> FSHIFT)
25#define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
26
27
28int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
29int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
30{
31 int updays, uphours, upminutes;
32 struct sysinfo info;
33 struct tm *current_time;
34 time_t current_secs;
35
36 time(¤t_secs);
37 current_time = localtime(¤t_secs);
38
39 sysinfo(&info);
40
41 printf(" %02d:%02d:%02d up ",
42 current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
43 updays = (int) info.uptime / (60*60*24);
44 if (updays)
45 printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
46 upminutes = (int) info.uptime / 60;
47 uphours = (upminutes / 60) % 24;
48 upminutes %= 60;
49 if (uphours)
50 printf("%2d:%02d, ", uphours, upminutes);
51 else
52 printf("%d min, ", upminutes);
53
54 printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
55 LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
56 LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
57 LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
58
59 return EXIT_SUCCESS;
60}
61