aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2012-06-14 17:30:04 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2012-06-14 17:30:04 +0200
commit604499e5a93d8055a761e968b12d6a0907bc3d0a (patch)
tree1175e19dc2d8941b4ef258187bb45f3e0cf4dab1
parentbf146b861083e3170af05016982d50d297e3ace7 (diff)
parentac42e3de90ebf4b921035893e3670da63cad882c (diff)
downloadbusybox-604499e5a93d8055a761e968b12d6a0907bc3d0a.tar.gz
Merge branch 'master' of git+ssh://busybox.net/var/lib/git/busybox
-rw-r--r--miscutils/nandwrite.c2
-rw-r--r--procps/ps.c40
2 files changed, 30 insertions, 12 deletions
diff --git a/miscutils/nandwrite.c b/miscutils/nandwrite.c
index 2ba6e3fe5..c636a5aa2 100644
--- a/miscutils/nandwrite.c
+++ b/miscutils/nandwrite.c
@@ -129,7 +129,7 @@ int nandwrite_main(int argc UNUSED_PARAM, char **argv)
xmove_fd(tmp_fd, IS_NANDDUMP ? STDOUT_FILENO : STDIN_FILENO);
}
- fd = xopen(argv[0], O_RDWR);
+ fd = xopen(argv[0], IS_NANDWRITE ? O_RDWR : O_RDONLY);
xioctl(fd, MEMGETINFO, &meminfo);
mtdoffset = xstrtou(opt_s, 0);
diff --git a/procps/ps.c b/procps/ps.c
index 4727b218b..3a5af7c18 100644
--- a/procps/ps.c
+++ b/procps/ps.c
@@ -69,6 +69,31 @@
/* Absolute maximum on output line length */
enum { MAX_WIDTH = 2*1024 };
+#if ENABLE_FEATURE_PS_TIME || ENABLE_FEATURE_PS_LONG
+static long get_uptime(void)
+{
+#ifdef __linux__
+ struct sysinfo info;
+ if (sysinfo(&info) < 0)
+ return 0;
+ return info.uptime;
+#elif 1
+ char buf[64];
+ long uptime;
+ if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
+ bb_perror_msg_and_die("can't read %s", "/proc/uptime");
+ buf[sizeof(buf)-1] = '\0';
+ sscanf(buf, "%l", &uptime);
+ return uptime;
+#else
+ struct timespec ts;
+ if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0)
+ return 0;
+ return ts.tv_sec;
+#endif
+}
+#endif
+
#if ENABLE_DESKTOP
#include <sys/times.h> /* for times() */
@@ -197,8 +222,6 @@ static inline unsigned get_HZ_by_waiting(void)
static unsigned get_kernel_HZ(void)
{
- //char buf[64];
- struct sysinfo info;
if (kernel_HZ)
return kernel_HZ;
@@ -208,12 +231,7 @@ static unsigned get_kernel_HZ(void)
if (kernel_HZ == (unsigned)-1)
kernel_HZ = get_HZ_by_waiting();
- //if (open_read_close("/proc/uptime", buf, sizeof(buf)) <= 0)
- // bb_perror_msg_and_die("can't read %s", "/proc/uptime");
- //buf[sizeof(buf)-1] = '\0';
- ///sscanf(buf, "%llu", &seconds_since_boot);
- sysinfo(&info);
- seconds_since_boot = info.uptime;
+ seconds_since_boot = get_uptime();
return kernel_HZ;
}
@@ -635,7 +653,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
};
#if ENABLE_FEATURE_PS_LONG
time_t now = now;
- struct sysinfo info;
+ long uptime;
#endif
int opts = 0;
/* If we support any options, parse argv */
@@ -695,7 +713,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
puts("S UID PID PPID VSZ RSS TTY STIME TIME CMD");
#if ENABLE_FEATURE_PS_LONG
now = time(NULL);
- sysinfo(&info);
+ uptime = get_uptime();
#endif
}
else {
@@ -727,7 +745,7 @@ int ps_main(int argc UNUSED_PARAM, char **argv UNUSED_PARAM)
char tty[2 * sizeof(int)*3 + 2];
char *endp;
unsigned sut = (p->stime + p->utime) / 100;
- unsigned elapsed = info.uptime - (p->start_time / 100);
+ unsigned elapsed = uptime - (p->start_time / 100);
time_t start = now - elapsed;
struct tm *tm = localtime(&start);