aboutsummaryrefslogtreecommitdiff
path: root/toys
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2018-10-21 21:36:51 -0500
committerRob Landley <rob@landley.net>2018-10-21 21:36:51 -0500
commit07a3b9192001369c7bf74cd4f096dc49703b24e9 (patch)
treecfb6f13f8a275f0ae21d6b577baa69d8a05f9ce7 /toys
parent3e0b077ec236aa26bfeb290f3cd7973ec3fbcb7d (diff)
downloadtoybox-07a3b9192001369c7bf74cd4f096dc49703b24e9.tar.gz
Add % to lib/args.c (long time in milliseconds), add xmillitime(), redo
xparsetime() not to need floating point, adjust callers.
Diffstat (limited to 'toys')
-rw-r--r--toys/net/ping.c23
-rw-r--r--toys/other/timeout.c2
-rw-r--r--toys/posix/ps.c21
-rw-r--r--toys/posix/sleep.c2
4 files changed, 13 insertions, 35 deletions
diff --git a/toys/net/ping.c b/toys/net/ping.c
index 752879a2..ad7679fd 100644
--- a/toys/net/ping.c
+++ b/toys/net/ping.c
@@ -11,7 +11,7 @@
* Yes, I wimped out and capped -s at sizeof(toybuf), waiting for a complaint...
// -s > 4088 = sizeof(toybuf)-sizeof(struct icmphdr), then kernel adds 20 bytes
-USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i:W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN))
+USE_PING(NEWTOY(ping, "<1>1m#t#<0>255=64c#<0=3s#<0>4088=56I:i%W#<0=3w#<0qf46[-46]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PING(OLDTOY(ping6, ping, TOYFLAG_USR|TOYFLAG_BIN))
config PING
@@ -47,18 +47,12 @@ config PING
#include <netinet/ip_icmp.h>
GLOBALS(
- long w;
- long W;
- char *i;
+ long w, W, i;
char *I;
- long s;
- long c;
- long t;
- long m;
+ long s, c, t, m;
struct sockaddr *sa;
int sock;
- long i_ms;
unsigned long sent, recv, fugit, min, max;
)
@@ -115,13 +109,8 @@ void ping_main(void)
struct icmphdr *ih = (void *)toybuf;
// Interval
- if (TT.i) {
- long frac;
-
- TT.i_ms = xparsetime(TT.i, 1000, &frac) * 1000;
- TT.i_ms += frac;
- if (TT.i_ms<200 && getuid()) error_exit("need root for -i <200");
- } else TT.i_ms = (toys.optflags&FLAG_f) ? 200 : 1000;
+ if (!(toys.optflags&FLAG_i)) TT.i = (toys.optflags&FLAG_f) ? 200 : 1000;
+ else if (TT.i<200 && getuid()) error_exit("need root for -i <200");
if (!(toys.optflags&FLAG_s)) TT.s = 56; // 64-PHDR_LEN
if ((toys.optflags&(FLAG_f|FLAG_c)) == FLAG_f) TT.c = 15;
@@ -230,7 +219,7 @@ void ping_main(void)
// Time to send the next packet?
if (!tW && tnext-tnow <= 0) {
- tnext += TT.i_ms;
+ tnext += TT.i;
memset(ih, 0, sizeof(*ih));
ih->type = (ai->ai_family == AF_INET) ? 8 : 128;
diff --git a/toys/other/timeout.c b/toys/other/timeout.c
index b62d696e..b903c3ec 100644
--- a/toys/other/timeout.c
+++ b/toys/other/timeout.c
@@ -58,7 +58,7 @@ void xparsetimeval(char *s, struct timeval *tv)
{
long ll;
- tv->tv_sec = xparsetime(s, 1000000, &ll);
+ tv->tv_sec = xparsetime(s, 6, &ll);
tv->tv_usec = ll;
}
diff --git a/toys/posix/ps.c b/toys/posix/ps.c
index d8f54862..833ecabe 100644
--- a/toys/posix/ps.c
+++ b/toys/posix/ps.c
@@ -48,8 +48,8 @@ USE_PS(NEWTOY(ps, "k(sort)*P(ppid)*aAdeflMno*O*p(pid)*s*t*Tu*U*g*G*wZ[!ol][+Ae][
// stayroot because iotop needs root to read other process' proc/$$/io
// TOP and IOTOP have a large common option block used for common processing,
// the default values are different but the flags are in the same order.
-USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d:m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
-USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d:m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
+USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d%<100=3000m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE))
+USE_IOTOP(NEWTOY(iotop, ">0AaKO" "Hk*o*p*u*s#<1=7d%<100=3000m#n#<1bq", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_STAYROOT|TOYFLAG_LOCALE))
USE_PGREP(NEWTOY(pgrep, "?cld:u*U*t*s*P*g*G*fnovxL:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
USE_PKILL(NEWTOY(pkill, "?Vu*U*t*s*P*g*G*fnovxl:[-no]", TOYFLAG_USR|TOYFLAG_BIN))
@@ -193,12 +193,8 @@ GLOBALS(
struct arg_list *G, *g, *U, *u, *t, *s, *p, *O, *o, *P, *k;
} ps;
struct {
- long n, m;
- char *d;
- long s;
+ long n, m, d, s;
struct arg_list *u, *p, *o, *k, *O;
-
- long d_ms;
} top;
struct {
char *L;
@@ -1638,8 +1634,8 @@ static void top_common(
}
now = millitime();
- if (timeout<=now) timeout = new.whence+TT.top.d_ms;
- if (timeout<=now || timeout>now+TT.top.d_ms) timeout = now+TT.top.d_ms;
+ if (timeout<=now) timeout = new.whence+TT.top.d;
+ if (timeout<=now || timeout>now+TT.top.d) timeout = now+TT.top.d;
// In batch mode, we ignore the keyboard.
if (toys.optflags&FLAG_b) {
@@ -1693,13 +1689,6 @@ static void top_common(
static void top_setup(char *defo, char *defk)
{
- if (TT.top.d) {
- long frac;
-
- TT.top.d_ms = xparsetime(TT.top.d, 1000, &frac) * 1000;
- TT.top.d_ms += frac;
- } else TT.top.d_ms = 3000;
-
TT.ticks = sysconf(_SC_CLK_TCK); // units for starttime/uptime
TT.tty = tty_fd() != -1;
diff --git a/toys/posix/sleep.c b/toys/posix/sleep.c
index c7b8bbf1..0381c107 100644
--- a/toys/posix/sleep.c
+++ b/toys/posix/sleep.c
@@ -31,6 +31,6 @@ void sleep_main(void)
{
struct timespec tv;
- tv.tv_sec = xparsetime(*toys.optargs, 1000000000, &tv.tv_nsec);
+ tv.tv_sec = xparsetime(*toys.optargs, 9, &tv.tv_nsec);
toys.exitval = !!nanosleep(&tv, NULL);
}