aboutsummaryrefslogtreecommitdiff
path: root/procps
diff options
context:
space:
mode:
Diffstat (limited to 'procps')
-rw-r--r--procps/powertop.c2
-rw-r--r--procps/ps.c40
-rw-r--r--procps/sysctl.c32
3 files changed, 49 insertions, 25 deletions
diff --git a/procps/powertop.c b/procps/powertop.c
index 008cdfca4..b4c45edbc 100644
--- a/procps/powertop.c
+++ b/procps/powertop.c
@@ -9,7 +9,7 @@
9 * Licensed under GPLv2, see file LICENSE in this source tree. 9 * Licensed under GPLv2, see file LICENSE in this source tree.
10 */ 10 */
11 11
12//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_BIN, BB_SUID_DROP)) 12//applet:IF_POWERTOP(APPLET(powertop, BB_DIR_USR_SBIN, BB_SUID_DROP))
13 13
14//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o 14//kbuild:lib-$(CONFIG_POWERTOP) += powertop.o
15 15
diff --git a/procps/ps.c b/procps/ps.c
index aa004aa22..dc6fda61d 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -69,6 +69,31 @@
69/* Absolute maximum on output line length */ 69/* Absolute maximum on output line length */
70enum { MAX_WIDTH = 2*1024 }; 70enum { MAX_WIDTH = 2*1024 };
71 71
72#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
73static long get_uptime(void)
74{
75#ifdef __linux__
76 struct sysinfo info;
77 if (sysinfo(&info) < 0)
78 return 0;
79 return info.uptime;
80#elif 1
81 char buf[64];
82 long uptime;
83 if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
84 bb_perror_msg_and_die("can't read %s", "/proc/uptime");
85 buf[sizeof(buf)-1] = '\0';
86 sscanf(buf, "%l", &uptime);
87 return uptime;
88#else
89 struct timespec ts;
90 if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
91 return 0;
92 return ts.tv_sec;
93#endif
94}
95#endif
96
72#if ENABLE_DESKTOP 97#if ENABLE_DESKTOP
73 98
74#include <sys/times.h> /* for times() */ 99#include <sys/times.h> /* for times() */
@@ -197,8 +222,6 @@ static inline unsigned get_HZ_by_waiting(void)
197 222
198static unsigned get_kernel_HZ(void) 223static unsigned get_kernel_HZ(void)
199{ 224{
200 //char buf[64];
201 struct sysinfo info;
202 225
203 if (kernel_HZ) 226 if (kernel_HZ)
204 return kernel_HZ; 227 return kernel_HZ;
@@ -208,12 +231,7 @@ static unsigned get_kernel_HZ(void)
208 if (kernel_HZ == (unsigned)-1) 231 if (kernel_HZ == (unsigned)-1)
209 kernel_HZ = get_HZ_by_waiting(); 232 kernel_HZ = get_HZ_by_waiting();
210 233
211 //if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0) 234 seconds_since_boot = get_uptime();
212 // bb_perror_msg_and_die("can't read %s", "/proc/uptime");
213 //buf[sizeof(buf)-1] = '\0';
214 ///sscanf(buf, "%llu", &seconds_since_boot);
215 sysinfo(&info);
216 seconds_since_boot = info.uptime;
217 235
218 return kernel_HZ; 236 return kernel_HZ;
219} 237}
@@ -645,7 +663,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
645 }; 663 };
646#if ENABLE_FEATURE_PS_LONG 664#if ENABLE_FEATURE_PS_LONG
647 time_t now = now; 665 time_t now = now;
648 struct sysinfo info; 666 long uptime;
649#endif 667#endif
650 int opts = 0; 668 int opts = 0;
651 /* If we support any options, parse argv */ 669 /* If we support any options, parse argv */
@@ -705,7 +723,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
705 puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD"); 723 puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD");
706#if ENABLE_FEATURE_PS_LONG 724#if ENABLE_FEATURE_PS_LONG
707 now = time(NULL); 725 now = time(NULL);
708 sysinfo(&info); 726 uptime = get_uptime();
709#endif 727#endif
710 } 728 }
711 else { 729 else {
@@ -737,7 +755,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
737 char tty[2 * sizeof(int)*3 + 2]; 755 char tty[2 * sizeof(int)*3 + 2];
738 char *endp; 756 char *endp;
739 unsigned sut = (p->stime + p->utime) / 100; 757 unsigned sut = (p->stime + p->utime) / 100;
740 unsigned elapsed = info.uptime - (p->start_time / 100); 758 unsigned elapsed = uptime - (p->start_time / 100);
741 time_t start = now - elapsed; 759 time_t start = now - elapsed;
742 struct tm *tm = localtime(&start); 760 struct tm *tm = localtime(&start);
743 761
diff --git a/procps/sysctl.c b/procps/sysctl.c
index 5296d0f58..878656862 100644
--- a/procps/sysctl.c
+++ b/procps/sysctl.c
@@ -12,21 +12,23 @@
12 */ 12 */
13 13
14//usage:#define sysctl_trivial_usage 14//usage:#define sysctl_trivial_usage
15//usage: "[OPTIONS] [VALUE]..." 15//usage: "[OPTIONS] [KEY[=VALUE]]..."
16//usage:#define sysctl_full_usage "\n\n" 16//usage:#define sysctl_full_usage "\n\n"
17//usage: "Configure kernel parameters at runtime\n" 17//usage: "Show/set kernel parameters\n"
18//usage: "\n -n Don't print key names"
19//usage: "\n -e Don't warn about unknown keys" 18//usage: "\n -e Don't warn about unknown keys"
20//usage: "\n -w Change sysctl setting" 19//usage: "\n -n Don't show key names"
21//usage: "\n -p FILE Load sysctl settings from FILE (default /etc/sysctl.conf)" 20//usage: "\n -a Show all values"
22//usage: "\n -a Display all values" 21/* Same as -a, no need to show it */
23//usage: "\n -A Display all values in table form" 22/* //usage: "\n -A Show all values in table form" */
23//usage: "\n -w Set values"
24//usage: "\n -p FILE Set values from FILE (default /etc/sysctl.conf)"
25//usage: "\n -q Set values silently"
24//usage: 26//usage:
25//usage:#define sysctl_example_usage 27//usage:#define sysctl_example_usage
26//usage: "sysctl [-n] [-e] variable...\n" 28//usage: "sysctl [-n] [-e] variable...\n"
27//usage: "sysctl [-n] [-e] -w variable=value...\n" 29//usage: "sysctl [-n] [-e] [-q] -w variable=value...\n"
28//usage: "sysctl [-n] [-e] -a\n" 30//usage: "sysctl [-n] [-e] -a\n"
29//usage: "sysctl [-n] [-e] -p file (default /etc/sysctl.conf)\n" 31//usage: "sysctl [-n] [-e] [-q] -p file (default /etc/sysctl.conf)\n"
30//usage: "sysctl [-n] [-e] -A\n" 32//usage: "sysctl [-n] [-e] -A\n"
31 33
32#include "libbb.h" 34#include "libbb.h"
@@ -37,9 +39,11 @@ enum {
37 FLAG_TABLE_FORMAT = 1 << 2, /* not implemented */ 39 FLAG_TABLE_FORMAT = 1 << 2, /* not implemented */
38 FLAG_SHOW_ALL = 1 << 3, 40 FLAG_SHOW_ALL = 1 << 3,
39 FLAG_PRELOAD_FILE = 1 << 4, 41 FLAG_PRELOAD_FILE = 1 << 4,
42/* TODO: procps 3.2.8 seems to not require -w for KEY=VAL to work: */
40 FLAG_WRITE = 1 << 5, 43 FLAG_WRITE = 1 << 5,
44 FLAG_QUIET = 1 << 6,
41}; 45};
42#define OPTION_STR "neAapw" 46#define OPTION_STR "neAapwq"
43 47
44static void sysctl_dots_to_slashes(char *name) 48static void sysctl_dots_to_slashes(char *name)
45{ 49{
@@ -144,9 +148,11 @@ static int sysctl_act_on_setting(char *setting)
144//TODO: procps 3.2.7 writes "value\n", note trailing "\n" 148//TODO: procps 3.2.7 writes "value\n", note trailing "\n"
145 xwrite_str(fd, value); 149 xwrite_str(fd, value);
146 close(fd); 150 close(fd);
147 if (option_mask32 & FLAG_SHOW_KEYS) 151 if (!(option_mask32 & FLAG_QUIET)) {
148 printf("%s = ", outname); 152 if (option_mask32 & FLAG_SHOW_KEYS)
149 puts(value); 153 printf("%s = ", outname);
154 puts(value);
155 }
150 } else { 156 } else {
151 char c; 157 char c;
152 158