diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-03-05 08:16:03 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-03-05 08:16:03 +0000 |
commit | 65fc1c70f7c992f4eda7aa8452d265a4f0d8d641 (patch) | |
tree | 381b6f02e99a9ceaa962ee806c522939b5a24918 /procps | |
parent | fb002d0df02ce53e8bcc03fe6e451b250b4d519e (diff) | |
download | busybox-w32-65fc1c70f7c992f4eda7aa8452d265a4f0d8d641.tar.gz busybox-w32-65fc1c70f7c992f4eda7aa8452d265a4f0d8d641.tar.bz2 busybox-w32-65fc1c70f7c992f4eda7aa8452d265a4f0d8d641.zip |
Oops. Forgot to add in uptime when I added uptime.
Here it is in all its /proc free glory.
-Erik
Diffstat (limited to 'procps')
-rw-r--r-- | procps/uptime.c | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/procps/uptime.c b/procps/uptime.c new file mode 100644 index 000000000..46797adb7 --- /dev/null +++ b/procps/uptime.c | |||
@@ -0,0 +1,73 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Mini uptime implementation for busybox | ||
4 | * | ||
5 | * Copyright (C) 1999 by Lineo, inc. | ||
6 | * Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | */ | ||
23 | |||
24 | /* This version of uptime doesn't display the number of users on the system, | ||
25 | * since busybox init doesn't mess with utmp. For folks using utmp that are | ||
26 | * just dying to have # of users reported, feel free to write it as some type | ||
27 | * of BB_FEATURE_UMTP_SUPPORT #define | ||
28 | */ | ||
29 | |||
30 | |||
31 | #include "internal.h" | ||
32 | #include <stdio.h> | ||
33 | #include <time.h> | ||
34 | #include <sys/sysinfo.h> | ||
35 | |||
36 | #define FSHIFT 16 /* nr of bits of precision */ | ||
37 | #define FIXED_1 (1<<FSHIFT) /* 1.0 as fixed-point */ | ||
38 | #define LOAD_INT(x) ((x) >> FSHIFT) | ||
39 | #define LOAD_FRAC(x) LOAD_INT(((x) & (FIXED_1-1)) * 100) | ||
40 | |||
41 | extern int uptime_main(int argc, char **argv) | ||
42 | { | ||
43 | int updays, uphours, upminutes; | ||
44 | struct sysinfo info; | ||
45 | struct tm *current_time; | ||
46 | time_t current_secs; | ||
47 | |||
48 | time(¤t_secs); | ||
49 | current_time = localtime(¤t_secs); | ||
50 | |||
51 | sysinfo(&info); | ||
52 | |||
53 | fprintf(stdout, " %2d:%02d%s up ", | ||
54 | current_time->tm_hour%12 ? current_time->tm_hour%12 : 12, | ||
55 | current_time->tm_min, current_time->tm_hour > 11 ? "pm" : "am"); | ||
56 | updays = (int) info.uptime / (60*60*24); | ||
57 | if (updays) | ||
58 | fprintf(stdout, "%d day%s, ", updays, (updays != 1) ? "s" : ""); | ||
59 | upminutes = (int) info.uptime / 60; | ||
60 | uphours = (upminutes / 60) % 24; | ||
61 | upminutes %= 60; | ||
62 | if(uphours) | ||
63 | fprintf(stdout, "%2d:%02d, ", uphours, upminutes); | ||
64 | else | ||
65 | fprintf(stdout, "%d min, ", upminutes); | ||
66 | |||
67 | printf("load average: %ld.%02ld, %ld.%02ld, %ld.%02ld\n", | ||
68 | LOAD_INT(info.loads[0]), LOAD_FRAC(info.loads[0]), | ||
69 | LOAD_INT(info.loads[1]), LOAD_FRAC(info.loads[1]), | ||
70 | LOAD_INT(info.loads[2]), LOAD_FRAC(info.loads[2])); | ||
71 | |||
72 | exit(TRUE); | ||
73 | } | ||