Magellan Linux

Annotation of /trunk/mkinitrd-magellan/busybox/procps/uptime.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1520 - (hide annotations) (download)
Wed Sep 7 18:39:43 2011 UTC (12 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1784 byte(s)
-fixed build against linux-3.0
1 niro 532 /* vi: set sw=4 ts=4: */
2     /*
3     * Mini uptime implementation for busybox
4     *
5     * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
6     *
7     * Licensed under the GPL version 2, see the file LICENSE in this tarball.
8     */
9    
10     /* This version of uptime doesn't display the number of users on the system,
11     * since busybox init doesn't mess with utmp. For folks using utmp that are
12     * just dying to have # of users reported, feel free to write it as some type
13     * of CONFIG_FEATURE_UTMP_SUPPORT #define
14     */
15    
16     /* getopt not needed */
17    
18 niro 816 #include "libbb.h"
19 niro 1520 #include <sys/sysinfo.h>
20 niro 532
21     #ifndef FSHIFT
22     # define FSHIFT 16 /* nr of bits of precision */
23     #endif
24     #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
25     #define LOAD_INT(x) ((x) >> FSHIFT)
26     #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
27    
28    
29 niro 816 int uptime_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
30     int uptime_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
31 niro 532 {
32     int updays, uphours, upminutes;
33     struct sysinfo info;
34     struct tm *current_time;
35     time_t current_secs;
36    
37     time(&current_secs);
38     current_time = localtime(&current_secs);
39    
40     sysinfo(&info);
41    
42     printf(" %02d:%02d:%02d up ",
43     current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
44     updays = (int) info.uptime / (60*60*24);
45     if (updays)
46     printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
47     upminutes = (int) info.uptime / 60;
48     uphours = (upminutes / 60) % 24;
49     upminutes %= 60;
50 niro 816 if (uphours)
51 niro 532 printf("%2d:%02d, ", uphours, upminutes);
52     else
53     printf("%d min, ", upminutes);
54    
55     printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
56     LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
57     LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
58     LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
59    
60     return EXIT_SUCCESS;
61     }