Magellan Linux

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 532 - (show annotations) (download)
Sat Sep 1 22:45:15 2007 UTC (16 years, 9 months ago) by niro
File MIME type: text/plain
File size: 1670 byte(s)
-import if magellan mkinitrd; it is a fork of redhats mkinitrd-5.0.8 with all magellan patches and features; deprecates magellan-src/mkinitrd

1 /* 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 #include "busybox.h"
19
20 #ifndef FSHIFT
21 # define FSHIFT 16 /* nr of bits of precision */
22 #endif
23 #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */
24 #define LOAD_INT(x) ((x) >> FSHIFT)
25 #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100)
26
27
28 int uptime_main(int argc, char **argv)
29 {
30 int updays, uphours, upminutes;
31 struct sysinfo info;
32 struct tm *current_time;
33 time_t current_secs;
34
35 time(&current_secs);
36 current_time = localtime(&current_secs);
37
38 sysinfo(&info);
39
40 printf(" %02d:%02d:%02d up ",
41 current_time->tm_hour, current_time->tm_min, current_time->tm_sec);
42 updays = (int) info.uptime / (60*60*24);
43 if (updays)
44 printf("%d day%s, ", updays, (updays != 1) ? "s" : "");
45 upminutes = (int) info.uptime / 60;
46 uphours = (upminutes / 60) % 24;
47 upminutes %= 60;
48 if(uphours)
49 printf("%2d:%02d, ", uphours, upminutes);
50 else
51 printf("%d min, ", upminutes);
52
53 printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n",
54 LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]),
55 LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]),
56 LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2]));
57
58 return EXIT_SUCCESS;
59 }