aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2016-05-04 18:25:41 -0700
committerRob Landley <rob@landley.net>2016-05-05 00:52:15 -0500
commit60da2d0b043a23303f052038ea83a933c2f80eb5 (patch)
tree044da2078feed30109678e8b6e5927ba35eba6b5 /toys
parent676e1d93cf3943cbbe91a0fad9b319cff9b136b1 (diff)
downloadtoybox-60da2d0b043a23303f052038ea83a933c2f80eb5.tar.gz
"top -b -n1" should end with a newline.
The use of TT.time to determine whether to use \r or \n is a little odd, but let's stick with that for now. Correct the spelling of millitime and add a test.
Diffstat (limited to 'toys')
-rw-r--r--toys/posix/ps.c17
1 files changed, 7 insertions, 10 deletions
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index 3a39353a..6b89c5ff 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -1228,13 +1228,11 @@ static int header_line(int line, int rev)
return line-1;
}
-// Get current time in miliseconds
-static long long militime(void)
+static long long millitime(void)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts);
-
return ts.tv_sec*1000+ts.tv_nsec/1000000;
}
@@ -1264,7 +1262,7 @@ static void top_common(
plold = plist+(tock++&1);
plnew = plist+(tock&1);
- plnew->whence = militime();
+ plnew->whence = millitime();
dt = dirtree_read("/proc", get_ps);
plnew->tb = collate(plnew->count = TT.kcount, dt);
TT.kcount = 0;
@@ -1421,7 +1419,7 @@ static void top_common(
recalc = 1;
for (i = 0; i<lines && i+topoff<mix.count; i++) {
- if (i) xputc('\n');
+ if (!(toys.optflags&FLAG_b) && i) xputc('\n');
show_ps(mix.tb[i+topoff]);
}
@@ -1430,8 +1428,7 @@ static void top_common(
break;
}
- // Get current time in miliseconds
- now = militime();
+ now = millitime();
if (timeout<=now) timeout = new.whence+TT.top.d;
if (timeout<=now || timeout>now+TT.top.d) timeout = now+TT.top.d;
@@ -1439,7 +1436,7 @@ static void top_common(
if (toys.optflags&FLAG_b) {
msleep(timeout-now);
// Make an obvious gap between datasets.
- xputs("\n\n\n");
+ xputs("\n\n");
continue;
}
@@ -1488,10 +1485,10 @@ static void top_setup(char *defo, char *defk)
{
int len;
- TT.time = militime();
TT.top.d *= 1000;
if (toys.optflags&FLAG_b) TT.width = TT.height = 99999;
else {
+ TT.time = millitime();
set_terminal(0, 1, 0);
sigatexit(tty_sigreset);
xsignal(SIGWINCH, generic_signal);
@@ -1532,7 +1529,7 @@ void top_main(void)
static int iotop_filter(long long *oslot, long long *nslot, int milis)
{
if (!(toys.optflags&FLAG_a)) merge_deltas(oslot, nslot, milis);
- else oslot[SLOT_upticks] = ((militime()-TT.time)*TT.ticks)/1000;
+ else oslot[SLOT_upticks] = ((millitime()-TT.time)*TT.ticks)/1000;
return !(toys.optflags&FLAG_o)||oslot[SLOT_iobytes+!(toys.optflags&FLAG_A)];
}