diff options
author | Elliott Hughes <enh@google.com> | 2023-04-14 19:20:55 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2023-04-14 19:20:55 +0000 |
commit | 0795da6bb6a0180e0ddaceadcb6f17cf0d4d2021 (patch) | |
tree | 1499c7c21c235460e56311d9a7f1d9ef868deebf | |
parent | 421d6b883a259d2ece918ffe2fd78b72a1d3edee (diff) | |
parent | a08eebc1fb0de072dd2f17955f5545530afba603 (diff) | |
download | toybox-0795da6bb6a0180e0ddaceadcb6f17cf0d4d2021.tar.gz |
Upgrade toybox to c8f758c734506d6131c2eefdb5ce2618d4b2b1d2 am: 88cd220c06 am: a08eebc1fb
Original change: https://android-review.googlesource.com/c/platform/external/toybox/+/2537732
Change-Id: Ie9706f277778887c2b37f39c486e168dd08a4fff
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r-- | METADATA | 4 | ||||
-rw-r--r-- | android/device/generated/flags.h | 4 | ||||
-rw-r--r-- | android/device/generated/newtoys.h | 2 | ||||
-rw-r--r-- | android/linux/generated/flags.h | 4 | ||||
-rw-r--r-- | android/linux/generated/newtoys.h | 2 | ||||
-rw-r--r-- | android/mac/generated/flags.h | 4 | ||||
-rw-r--r-- | android/mac/generated/newtoys.h | 2 | ||||
-rw-r--r-- | lib/deflate.c | 7 | ||||
-rw-r--r-- | toys/other/vmstat.c | 117 | ||||
-rw-r--r-- | toys/posix/ls.c | 2 |
10 files changed, 74 insertions, 74 deletions
@@ -13,11 +13,11 @@ third_party { type: GIT value: "https://github.com/landley/toybox" } - version: "704278e45d0441c5a13777af727e4159f2ebffd9" + version: "c8f758c734506d6131c2eefdb5ce2618d4b2b1d2" license_type: UNENCUMBERED last_upgrade_date { year: 2023 month: 4 - day: 10 + day: 14 } } diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h index 55672500..ef9fc67a 100644 --- a/android/device/generated/flags.h +++ b/android/device/generated/flags.h @@ -1824,9 +1824,9 @@ #undef FLAG_S #endif -// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] +// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] #undef OPTSTR_ls -#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" +#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" #ifdef CLEANUP_ls #undef CLEANUP_ls #undef FOR_ls diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h index 72091791..0680e5d9 100644 --- a/android/device/generated/newtoys.h +++ b/android/device/generated/newtoys.h @@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN)) USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN)) USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN)) -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h index f0a29d93..e852aa97 100644 --- a/android/linux/generated/flags.h +++ b/android/linux/generated/flags.h @@ -1824,9 +1824,9 @@ #undef FLAG_S #endif -// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] +// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] #undef OPTSTR_ls -#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" +#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" #ifdef CLEANUP_ls #undef CLEANUP_ls #undef FOR_ls diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h index 72091791..0680e5d9 100644 --- a/android/linux/generated/newtoys.h +++ b/android/linux/generated/newtoys.h @@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN)) USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN)) USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN)) -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h index 8993979c..5d7e2e94 100644 --- a/android/mac/generated/flags.h +++ b/android/mac/generated/flags.h @@ -1824,9 +1824,9 @@ #undef FLAG_S #endif -// ls (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] +// ls (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] (sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb] #undef OPTSTR_ls -#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" +#define OPTSTR_ls "(sort):(color):;(full-time)(show-control-chars)¡(group-directories-first)þZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]" #ifdef CLEANUP_ls #undef CLEANUP_ls #undef FOR_ls diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h index 72091791..0680e5d9 100644 --- a/android/mac/generated/newtoys.h +++ b/android/mac/generated/newtoys.h @@ -169,7 +169,7 @@ USE_LOGIN(NEWTOY(login, ">1f:ph:", TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_LOGNAME(NEWTOY(logname, ">0", TOYFLAG_USR|TOYFLAG_BIN)) USE_LOGPATH(NEWTOY(logpath, 0, TOYFLAG_NOHELP|TOYFLAG_USR|TOYFLAG_BIN)) USE_LOSETUP(NEWTOY(losetup, ">2S(sizelimit)#s(show)ro#j:fdcaD[!afj]", TOYFLAG_SBIN)) -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) USE_LSATTR(NEWTOY(lsattr, "ldapvR", TOYFLAG_BIN)) USE_LSMOD(NEWTOY(lsmod, NULL, TOYFLAG_SBIN)) USE_LSOF(NEWTOY(lsof, "lp*t", TOYFLAG_USR|TOYFLAG_BIN)) diff --git a/lib/deflate.c b/lib/deflate.c index 06d61e97..a418c21c 100644 --- a/lib/deflate.c +++ b/lib/deflate.c @@ -433,16 +433,17 @@ static void gzip_crc(struct deflate *dd, char *data, unsigned len) /* // Start with crc = 1, or pass in last crc to append more data +// Deferred modulus good for paged size inputs (can't overflow for ~5500 bytes) unsigned adler32(char *buf, unsigned len, unsigned crc) { unsigned aa = crc&((1<<16)-1), bb = crc>>16; while (len--) { - aa = (aa+*buf)%65521; - bb = (bb+aa)%65521; + aa += *buf++; + bb += aa; } - return (bb<16)+aa; + return ((bb%65521)<<16)+aa%65521; } */ diff --git a/toys/other/vmstat.c b/toys/other/vmstat.c index d5cf5691..ebe5399e 100644 --- a/toys/other/vmstat.c +++ b/toys/other/vmstat.c @@ -29,125 +29,124 @@ config VMSTAT #include "toys.h" struct vmstat_proc { - // From /proc/stat (jiffies) - uint64_t user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked; - // From /proc/meminfo (units are kb) - uint64_t memfree, buffers, cached, swapfree, swaptotal; - // From /proc/vmstat (units are kb) - uint64_t io_in, io_out; - // From /proc/vmstat (units are pages) - uint64_t swap_in, swap_out; + unsigned long long + // From /proc/stat (jiffies) 0-10 + user, nice, sys, idle, wait, irq, sirq, intr, ctxt, running, blocked, + // From /proc/meminfo (units are kb) 11-16 + memfree, buffers, cached, swapfree, swaptotal, reclaimable, + // From /proc/vmstat (units are kb) 17-18 + io_in, io_out, + // From /proc/vmstat (units are pages) 19-20 + swap_in, swap_out; }; // All the elements of vmstat_proc are the same size, so we can populate it as // a big array, then read the elements back out by name -static void get_vmstat_proc(struct vmstat_proc *vmstat_proc) +static void get_vmstat_proc(struct vmstat_proc *vmsp) { - char *vmstuff[] = { "/proc/stat", "cpu ", 0, 0, 0, 0, 0, 0, - "intr ", "ctxt ", "procs_running ", "procs_blocked ", "/proc/meminfo", - "MemFree: ", "Buffers: ", "Cached: ", "SwapFree: ", "SwapTotal: ", + char *vmstuff[] = { "/proc/stat", "cpu ", 0, 0, 0, 0, 0, 0, "intr ", "ctxt ", + "procs_running ", "procs_blocked ", "/proc/meminfo", "MemFree:", + "Buffers:", "Cached:", "SwapFree:", "SwapTotal:", "SReclaimable:", "/proc/vmstat", "pgpgin ", "pgpgout ", "pswpin ", "pswpout " }; - uint64_t *new = (uint64_t *)vmstat_proc; - char *p = p, *name = name, *file = NULL; + unsigned long long *new = (void *)vmsp; + char *p, *name = name, *file = 0; int i, j; - // We use vmstuff to fill out vmstat_proc as an array of uint64_t: + // We use vmstuff to fill out vmstat_proc as an array of long long: // Strings starting with / are the file to find next entries in // Any other string is a key to search for, with decimal value right after // 0 means parse another value on same line as last key - for (i = 0; i<ARRAY_LEN(vmstuff); i++) { - if (!vmstuff[i]) p++; + memset(new, 0, sizeof(struct vmstat_proc)); + for (i = j = 0; i<ARRAY_LEN(vmstuff); i++) { + if (!vmstuff[i]) p++; // Read next entry on same line else if (*vmstuff[i] == '/') { - // /proc/stat for a 48-core machine doesn't fit in toybuf. free(file); file = xreadfile(name = vmstuff[i], 0, 0); continue; - } else p = strafter(file, vmstuff[i]); - if (!p || 1!=sscanf(p, "%"PRIu64"%n", new++, &j)) - error_exit("Bad %sin %s: %s", vmstuff[i], name, p ? p : ""); - p += j; + } else if (file && !(p = strafter(file, vmstuff[i]))) { + free(file); + file = 0; + } + if (!file) new++; + else if (1==sscanf(p, "%llu%n", new++, &j)) p += j; } free(file); + + // combine some fields we display as aggregates + vmsp->running--; // Don't include ourselves + vmsp->user += vmsp->nice; + vmsp->sys += vmsp->irq + vmsp->sirq; + vmsp->swaptotal -= vmsp->swapfree; + vmsp->cached += vmsp->reclaimable; } void vmstat_main(void) { - struct vmstat_proc top[2]; int i, loop_delay = 0, loop_max = 0; unsigned loop, rows = 25, page_kb = sysconf(_SC_PAGESIZE)/1024; - char *headers="r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0" - "sy\0id\0wa", lengths[] = {2,2,7,7,6,7,5,5,5,5,5,5,2,2,2,2}; + unsigned long long units, total_hz, *ptr, *oldptr; + char *headers = "r\0b\0swpd\0free\0buff\0cache\0si\0so\0bi\0bo\0in\0cs\0us\0" + "sy\0id\0wa", lengths[] = {2,2,7,7,6,7,4,4,5,5,4,4,2,2,2,2}; - memset(top, 0, sizeof(top)); if (toys.optc) loop_delay = atolx_range(toys.optargs[0], 0, INT_MAX); - if (toys.optc > 1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX); + if (toys.optc>1) loop_max = atolx_range(toys.optargs[1], 1, INT_MAX); + + xreadfile("/proc/uptime", toybuf, sizeof(toybuf)); + sscanf(toybuf, "%*s %llu", &units); - for (loop = 0; !loop_max || loop < loop_max; loop++) { - unsigned idx = loop&1, offset = 0, expected = 0; - uint64_t units, total_hz, *ptr = (uint64_t *)(top+idx), - *oldptr = (uint64_t *)(top+!idx); + for (loop = 0; !loop_max || loop<loop_max; loop++) { + unsigned offset = 0, expected = 0; if (loop && loop_delay) sleep(loop_delay); + ptr = oldptr = (void *)toybuf; + *((loop&1) ? &ptr : &oldptr) += sizeof(struct vmstat_proc); + get_vmstat_proc((void *)ptr); + // Print headers if (rows>3 && !(loop % (rows-3))) { char *header = headers; - if (!(toys.optflags&FLAG_n) && isatty(1)) terminal_size(0, &rows); + if (!FLAG(n) && isatty(1)) terminal_size(0, &rows); else rows = 0; - printf("procs ------------memory------------ ----swap--- -----io---- ---system-- ----cpu----\n"); - for (i=0; i<sizeof(lengths); i++) { + printf("procs ------------memory------------ ---swap-- -----io---- --system- ----cpu----\n"); + for (i = 0; i<sizeof(lengths); i++) { printf(" %*s"+!i, lengths[i], header); header += strlen(header)+1; } xputc('\n'); } - // Read data and combine some fields we display as aggregates - get_vmstat_proc(top+idx); - top[idx].running--; // Don't include ourselves - top[idx].user += top[idx].nice; - top[idx].sys += top[idx].irq + top[idx].sirq; - top[idx].swaptotal -= top[idx].swapfree; - - // Collect unit adjustments (outside the inner loop to save time) - - if (!loop) { - char *s = toybuf; - - xreadfile("/proc/uptime", toybuf, sizeof(toybuf)); - while (*(s++) > ' '); - sscanf(s, "%"PRIu64, &units); - } else units = loop_delay; + if (loop) units = loop_delay; // add up user, sys, idle, and wait time used since last time // (Already appended nice to user) - total_hz = 0; - for (i=0; i<4; i++) total_hz += ptr[i+!!i] - oldptr[i+!!i]; + for (i = total_hz = 0; i<4; i++) total_hz += ptr[i+!!i] - oldptr[i+!!i]; // Output values in order[]: running, blocked, swaptotal, memfree, buffers, - // cache, swap_in, swap_out, io_in, io_out, sirq, ctxt, user, sys, idle,wait + // cache, swap_in, swap_out, io_in, io_out, intr, ctxt, user, sys, idle,wait for (i=0; i<sizeof(lengths); i++) { - char order[] = {9, 10, 15, 11, 12, 13, 18, 19, 16, 17, 6, 8, 0, 2, 3, 4}; - uint64_t out = ptr[order[i]]; + char order[] = {9, 10, 15, 11, 12, 13, 19, 20, 17, 18, 7, 8, 0, 2, 3, 4}; + unsigned long long out = ptr[order[i]]; int len; // Adjust rate and units if (i>5) out -= oldptr[order[i]]; if (order[i]<7) out = ((out*100) + (total_hz/2)) / total_hz; - else if (order[i]>17) out = ((out * page_kb)+(units-1))/units; - else if (order[i]>15) out = ((out)+(units-1))/units; - else if (order[i]<9) out = (out+(units-1)) / units; + else if (order[i]>16) { + if (order[i]>18) out *= page_kb; + out = (out*page_kb+(units-1))/units; + } else if (order[i]<9) out = (out+(units-1)) / units; // If a field was too big to fit in its slot, try to compensate later expected += lengths[i] + !!i; len = expected - offset - !!i; if (len < 0) len = 0; - offset += printf(" %*"PRIu64+!i, len, out); + offset += printf(" %*llu"+!i, len, out); } xputc('\n'); diff --git a/toys/posix/ls.c b/toys/posix/ls.c index fc5b5f6f..56d5c638 100644 --- a/toys/posix/ls.c +++ b/toys/posix/ls.c @@ -13,7 +13,7 @@ * and we do --time-style=long-iso instead * ignore -k because we default to 1024 byte blocks -USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) +USE_LS(NEWTOY(ls, "(sort):(color):;(full-time)(show-control-chars)\241(group-directories-first)\376ZgoACFHLNRSUXabcdfhikl@mnpqrstuw#=80<0x1[-Cxm1][-Cxml][-Cxmo][-Cxmg][-cu][-ftS][-HL][-Nqb]", TOYFLAG_BIN|TOYFLAG_LOCALE)) config LS bool "ls" |