diff options
author | Elliott Hughes <enh@google.com> | 2017-11-27 17:21:21 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-11-27 17:21:34 -0800 |
commit | 73fd808900b5a6c0df7bcd9900dad37f37367f3f (patch) | |
tree | 79e381148e614261b6b797f10951868873404f36 | |
parent | 62f36d9160d0fdf60f8732874b6310e4c04d925f (diff) | |
parent | a9111bd499622577c3acd6565f02d6efdd16b44c (diff) | |
download | toybox-o-mr1-iot-preview-6.tar.gz |
Merge remote-tracking branch 'toybox/master' into HEADandroid-o-mr1-iot-preview-6o-mr1-iot-preview-6
Change-Id: I22ec2b8b3f1a978442fd5f7031a35eba8cb9ce25
-rw-r--r-- | generated/flags.h | 22 | ||||
-rw-r--r-- | generated/globals.h | 1 | ||||
-rw-r--r-- | generated/help.h | 4 | ||||
-rw-r--r-- | generated/newtoys.h | 4 | ||||
-rw-r--r-- | toys/posix/df.c | 63 | ||||
-rw-r--r-- | toys/posix/file.c | 13 | ||||
-rw-r--r-- | toys/posix/find.c | 6 | ||||
-rw-r--r-- | toys/posix/time.c | 23 |
8 files changed, 89 insertions, 47 deletions
diff --git a/generated/flags.h b/generated/flags.h index d8755e1f..0efe1c46 100644 --- a/generated/flags.h +++ b/generated/flags.h @@ -450,14 +450,15 @@ #undef FOR_deallocvt #endif -// df HPkht*a[-HPkh] HPkht*a[-HPkh] +// df HPkhit*a[-HPkh] HPkhit*a[-HPkh] #undef OPTSTR_df -#define OPTSTR_df "HPkht*a[-HPkh]" +#define OPTSTR_df "HPkhit*a[-HPkh]" #ifdef CLEANUP_df #undef CLEANUP_df #undef FOR_df #undef FLAG_a #undef FLAG_t +#undef FLAG_i #undef FLAG_h #undef FLAG_k #undef FLAG_P @@ -2773,12 +2774,13 @@ #undef FLAG_r #endif -// time <1^p <1^p +// time <1^pv <1^pv #undef OPTSTR_time -#define OPTSTR_time "<1^p" +#define OPTSTR_time "<1^pv" #ifdef CLEANUP_time #undef CLEANUP_time #undef FOR_time +#undef FLAG_v #undef FLAG_p #endif @@ -3617,10 +3619,11 @@ #endif #define FLAG_a (1<<0) #define FLAG_t (1<<1) -#define FLAG_h (1<<2) -#define FLAG_k (1<<3) -#define FLAG_P (1<<4) -#define FLAG_H (1<<5) +#define FLAG_i (1<<2) +#define FLAG_h (1<<3) +#define FLAG_k (1<<4) +#define FLAG_P (1<<5) +#define FLAG_H (1<<6) #endif #ifdef FOR_dhcp @@ -5576,7 +5579,8 @@ #ifndef TT #define TT this.time #endif -#define FLAG_p (1<<0) +#define FLAG_v (1<<0) +#define FLAG_p (1<<1) #endif #ifdef FOR_timeout diff --git a/generated/globals.h b/generated/globals.h index 22594423..9d7b8720 100644 --- a/generated/globals.h +++ b/generated/globals.h @@ -1092,6 +1092,7 @@ struct find_data { struct double_list *argdata; int topdir, xdev, depth; time_t now; + long max_bytes; }; // toys/posix/grep.c diff --git a/generated/help.h b/generated/help.h index 3c806e68..680daf7f 100644 --- a/generated/help.h +++ b/generated/help.h @@ -454,7 +454,7 @@ #define HELP_touch "usage: touch [-amch] [-d DATE] [-t TIME] [-r FILE] FILE...\n\nUpdate the access and modification times of each FILE to the current time.\n\n-a change access time\n-m change modification time\n-c don't create file\n-h change symlink\n-d set time to DATE (in YYYY-MM-DDThh:mm:SS[.frac][tz] format)\n-t set time to TIME (in [[CC]YY]MMDDhhmm[.ss][frac] format)\n-r set time same as reference FILE\n\n" -#define HELP_time "usage: time [-p] COMMAND [ARGS...]\n\nRun command line and report real, user, and system time elapsed in seconds.\n(real = clock on the wall, user = cpu used by command's code,\nsystem = cpu used by OS on behalf of command.)\n\n-p posix mode (ignored)\n\n" +#define HELP_time "usage: time [-pv] COMMAND [ARGS...]\n\nRun command line and report real, user, and system time elapsed in seconds.\n(real = clock on the wall, user = cpu used by command's code,\nsystem = cpu used by OS on behalf of command.)\n\n-p posix mode (default)\n-v verbose mode\n\n" #define HELP_tee "usage: tee [-ai] [file...]\n\nCopy stdin to each listed file, and also to stdout.\nFilename \"-\" is a synonym for stdout.\n\n-a append to files\n-i ignore SIGINT\n\n" @@ -552,7 +552,7 @@ #define HELP_dirname "usage: dirname PATH\n\nShow directory portion of path.\n\n" -#define HELP_df "usage: df [-HPkh] [-t type] [FILESYSTEM ...]\n\nThe \"disk free\" command shows total/used/available disk space for\neach filesystem listed on the command line, or all currently mounted\nfilesystems.\n\n-a Show all (including /proc and friends)\n-P The SUSv3 \"Pedantic\" option\n-k Sets units back to 1024 bytes (the default without -P)\n-h Human readable output (K=1024)\n-H Human readable output (k=1000)\n-t type Display only filesystems of this type\n\nPedantic provides a slightly less useful output format dictated by Posix,\nand sets the units to 512 bytes instead of the default 1024 bytes.\n\n" +#define HELP_df "usage: df [-HPkhi] [-t type] [FILESYSTEM ...]\n\nThe \"disk free\" command shows total/used/available disk space for\neach filesystem listed on the command line, or all currently mounted\nfilesystems.\n\n-a Show all (including /proc and friends)\n-P The SUSv3 \"Pedantic\" option\n-k Sets units back to 1024 bytes (the default without -P)\n-h Human readable output (K=1024)\n-H Human readable output (k=1000)\n-i Show inodes instead of blocks\n-t type Display only filesystems of this type\n\nPedantic provides a slightly less useful output format dictated by Posix,\nand sets the units to 512 bytes instead of the default 1024 bytes.\n\n" #define HELP_date "usage: date [-u] [-r FILE] [-d DATE] [+DISPLAY_FORMAT] [-D SET_FORMAT] [SET]\n\nSet/get the current date/time. With no SET shows the current date.\n\nDefault SET format is \"MMDDhhmm[[CC]YY][.ss]\", that's (2 digits each)\nmonth, day, hour (0-23), and minute. Optionally century, year, and second.\nAlso accepts \"@UNIXTIME[.FRACTION]\" as seconds since midnight Jan 1 1970.\n\n-d Show DATE instead of current time (convert date format)\n-D +FORMAT for SET or -d (instead of MMDDhhmm[[CC]YY][.ss])\n-r Use modification time of FILE instead of current date\n-u Use UTC instead of current timezone\n\n+FORMAT specifies display format string using strftime(3) syntax:\n\n%% literal % %n newline %t tab\n%S seconds (00-60) %M minute (00-59) %m month (01-12)\n%H hour (0-23) %I hour (01-12) %p AM/PM\n%y short year (00-99) %Y year %C century\n%a short weekday name %A weekday name %u day of week (1-7, 1=mon)\n%b short month name %B month name %Z timezone name\n%j day of year (001-366) %d day of month (01-31) %e day of month ( 1-31)\n%N nanosec (output only)\n\n%U Week of year (0-53 start sunday) %W Week of year (0-53 start monday)\n%V Week of year (1-53 start monday, week < 4 days not part of this year)\n\n%D = \"%m/%d/%y\" %r = \"%I : %M : %S %p\" %T = \"%H:%M:%S\" %h = \"%b\"\n%x locale date %X locale time %c locale date/time\n\n" diff --git a/generated/newtoys.h b/generated/newtoys.h index 6b98539d..6685c624 100644 --- a/generated/newtoys.h +++ b/generated/newtoys.h @@ -44,7 +44,7 @@ USE_DD(NEWTOY(dd, 0, TOYFLAG_USR|TOYFLAG_BIN)) USE_DEALLOCVT(NEWTOY(deallocvt, ">1", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_NEEDROOT)) USE_GROUPDEL(OLDTOY(delgroup, groupdel, TOYFLAG_NEEDROOT|TOYFLAG_SBIN)) USE_USERDEL(OLDTOY(deluser, userdel, TOYFLAG_NEEDROOT|TOYFLAG_SBIN)) -USE_DF(NEWTOY(df, "HPkht*a[-HPkh]", TOYFLAG_SBIN)) +USE_DF(NEWTOY(df, "HPkhit*a[-HPkh]", TOYFLAG_SBIN)) USE_DHCP(NEWTOY(dhcp, "V:H:F:x*r:O*A#<0=20T#<0=3t#<0=3s:p:i:SBRCaovqnbf", TOYFLAG_SBIN|TOYFLAG_ROOTONLY)) USE_DHCP6(NEWTOY(dhcp6, "r:A#<0T#<0t#<0s:p:i:SRvqnbf", TOYFLAG_SBIN|TOYFLAG_ROOTONLY)) USE_DHCPD(NEWTOY(dhcpd, ">1P#<0>65535fi:S46[!46]", TOYFLAG_SBIN|TOYFLAG_ROOTONLY)) @@ -241,7 +241,7 @@ USE_TEST_SCANKEY(NEWTOY(test_scankey, 0, TOYFLAG_BIN)) USE_TEST_UTF8TOWC(NEWTOY(test_utf8towc, 0, TOYFLAG_USR|TOYFLAG_BIN)) USE_TFTP(NEWTOY(tftp, "<1b#<8>65464r:l:g|p|[!gp]", TOYFLAG_USR|TOYFLAG_BIN)) USE_TFTPD(NEWTOY(tftpd, "rcu:l", TOYFLAG_BIN)) -USE_TIME(NEWTOY(time, "<1^p", TOYFLAG_USR|TOYFLAG_BIN)) +USE_TIME(NEWTOY(time, "<1^pv", TOYFLAG_USR|TOYFLAG_BIN)) USE_TIMEOUT(NEWTOY(timeout, "<2^vk:s: ", TOYFLAG_BIN)) USE_TOP(NEWTOY(top, ">0O*" "Hk*o*p*u*s#<1d#=3<1m#n#<1bq[!oO]", TOYFLAG_USR|TOYFLAG_BIN|TOYFLAG_LOCALE)) USE_TOUCH(NEWTOY(touch, "<1acd:mr:t:h[!dtr]", TOYFLAG_BIN)) diff --git a/toys/posix/df.c b/toys/posix/df.c index 9c6b2c3f..64eabf2e 100644 --- a/toys/posix/df.c +++ b/toys/posix/df.c @@ -4,13 +4,13 @@ * * See http://opengroup.org/onlinepubs/9699919799/utilities/df.html -USE_DF(NEWTOY(df, "HPkht*a[-HPkh]", TOYFLAG_SBIN)) +USE_DF(NEWTOY(df, "HPkhit*a[-HPkh]", TOYFLAG_SBIN)) config DF bool "df" default y help - usage: df [-HPkh] [-t type] [FILESYSTEM ...] + usage: df [-HPkhi] [-t type] [FILESYSTEM ...] The "disk free" command shows total/used/available disk space for each filesystem listed on the command line, or all currently mounted @@ -21,6 +21,7 @@ config DF -k Sets units back to 1024 bytes (the default without -P) -h Human readable output (K=1024) -H Human readable output (k=1000) + -i Show inodes instead of blocks -t type Display only filesystems of this type Pedantic provides a slightly less useful output format dictated by Posix, @@ -47,7 +48,7 @@ static void measure_column(int col, const char *s) static void measure_numeric_column(int col, long long n) { - snprintf(toybuf, sizeof(toybuf), "%lld", n); + snprintf(toybuf, sizeof(toybuf), "%llu", n); return measure_column(col, toybuf); } @@ -58,22 +59,35 @@ static void show_header() // The filesystem column is always at least this wide. if (TT.column_widths[0] < 14) TT.column_widths[0] = 14; - if (toys.optflags & (FLAG_H|FLAG_h)) { - xprintf("%-*s Size Used Avail Use%% Mounted on\n", + if ((toys.optflags & (FLAG_H|FLAG_h))) { + xprintf((toys.optflags&FLAG_i) ? + "%-*sInodes IUsed IFree IUse%% Mounted on\n" : + "%-*s Size Used Avail Use%% Mounted on\n", TT.column_widths[0], "Filesystem"); } else { - const char *blocks_label = TT.units == 512 ? "512-blocks" : "1K-blocks"; - const char *use_label = toys.optflags & FLAG_P ? "Capacity" : "Use%"; + const char *item_label, *used_label, *free_label, *use_label; + + if (toys.optflags & FLAG_i) { + item_label = "Inodes"; + used_label = "IUsed"; + free_label = "IFree"; + use_label = "IUse%"; + } else { + item_label = TT.units == 512 ? "512-blocks" : "1K-blocks"; + used_label = "Used"; + free_label = "Available"; + use_label = toys.optflags & FLAG_P ? "Capacity" : "Use%"; + } - measure_column(1, blocks_label); - measure_column(2, "Used"); - measure_column(3, "Available"); + measure_column(1, item_label); + measure_column(2, used_label); + measure_column(3, free_label); measure_column(4, use_label); xprintf("%-*s %*s %*s %*s %*s Mounted on\n", TT.column_widths[0], "Filesystem", - TT.column_widths[1], blocks_label, - TT.column_widths[2], "Used", - TT.column_widths[3], "Available", + TT.column_widths[1], item_label, + TT.column_widths[2], used_label, + TT.column_widths[3], free_label, TT.column_widths[4], use_label); // For the "Use%" column, the trailing % should be inside the column. @@ -83,7 +97,7 @@ static void show_header() static void show_mt(struct mtab_list *mt, int measuring) { - long long size, used, avail, percent, block; + unsigned long long size, used, avail, percent, block; char *device; // Return if it wasn't found (should never happen, but with /etc/mtab...) @@ -104,10 +118,16 @@ static void show_mt(struct mtab_list *mt, int measuring) // Figure out how much total/used/free space this filesystem has, // forcing 64-bit math because filesystems are big now. - block = mt->statvfs.f_bsize ? mt->statvfs.f_bsize : 1; - size = (block * mt->statvfs.f_blocks) / TT.units; - used = (block * (mt->statvfs.f_blocks-mt->statvfs.f_bfree)) / TT.units; - avail = (block*(getuid()?mt->statvfs.f_bavail:mt->statvfs.f_bfree))/TT.units; + if (toys.optflags & FLAG_i) { + size = mt->statvfs.f_files; + used = mt->statvfs.f_files - mt->statvfs.f_ffree; + avail = getuid() ? mt->statvfs.f_favail : mt->statvfs.f_ffree; + } else { + block = mt->statvfs.f_bsize ? mt->statvfs.f_bsize : 1; + size = (block * mt->statvfs.f_blocks) / TT.units; + used = (block * (mt->statvfs.f_blocks-mt->statvfs.f_bfree)) / TT.units; + avail= (block*(getuid()?mt->statvfs.f_bavail:mt->statvfs.f_bfree))/TT.units; + } if (!(used+avail)) percent = 0; else { percent = (used*100)/(used+avail); @@ -128,14 +148,15 @@ static void show_mt(struct mtab_list *mt, int measuring) if (toys.optflags & (FLAG_H|FLAG_h)) { char *size_str = toybuf, *used_str = toybuf+64, *avail_str = toybuf+128; int hr_flags = (toys.optflags & FLAG_H) ? HR_1000 : 0; + int w = 4 + !!(toys.optflags & FLAG_i); human_readable(size_str, size, hr_flags); human_readable(used_str, used, hr_flags); human_readable(avail_str, avail, hr_flags); - xprintf("%-*s %4s %4s %4s % 3lld%% %s\n", + xprintf("%-*s %*s %*s %*s %*llu%% %s\n", TT.column_widths[0], device, - size_str, used_str, avail_str, percent, mt->dir); - } else xprintf("%-*s %*lld %*lld %*lld %*lld%% %s\n", + w, size_str, w, used_str, w, avail_str, w-1, percent, mt->dir); + } else xprintf("%-*s %*llu %*llu %*llu %*llu%% %s\n", TT.column_widths[0], device, TT.column_widths[1], size, TT.column_widths[2], used, diff --git a/toys/posix/file.c b/toys/posix/file.c index 5e5c15bc..b84eece6 100644 --- a/toys/posix/file.c +++ b/toys/posix/file.c @@ -30,7 +30,7 @@ GLOBALS( static void do_elf_file(int fd, struct stat *sb) { int endian = toybuf[5], bits = toybuf[4], i, j; - int64_t (*elf_int)(void *ptr, unsigned size) = peek_le; + int64_t (*elf_int)(void *ptr, unsigned size); // Values from include/linux/elf-em.h (plus arch/*/include/asm/elf.h) // Names are linux/arch/ directory (sometimes before 32/64 bit merges) struct {int val; char *name;} type[] = {{0x9026, "alpha"}, {93, "arc"}, @@ -53,9 +53,10 @@ static void do_elf_file(int fd, struct stat *sb) int phentsize, phnum, shsize, shnum; printf("ELF "); + elf_int = (endian==2) ? peek_be : peek_le; - // executable (ELF says this is short but reality says byte, not MSB swapped) - i = toybuf[16]; + // executable type + i = elf_int(toybuf+16, 2); if (i == 1) printf("relocatable"); else if (i == 2) printf("executable"); else if (i == 3) printf("shared object"); @@ -73,10 +74,8 @@ static void do_elf_file(int fd, struct stat *sb) // "LSB" if (endian == 1) printf("LSB "); - else if (endian == 2) { - printf("MSB "); - elf_int = peek_be; - } else { + else if (endian == 2) printf("MSB "); + else { printf("(bad endian %d) \n", endian); endian = 0; } diff --git a/toys/posix/find.c b/toys/posix/find.c index 5c72131d..762f89fc 100644 --- a/toys/posix/find.c +++ b/toys/posix/find.c @@ -61,6 +61,7 @@ GLOBALS( struct double_list *argdata; int topdir, xdev, depth; time_t now; + long max_bytes; ) struct execdir_data { @@ -498,10 +499,10 @@ static int do_find(struct dirtree *new) // Done here vs argument parsing pass so it's after dlist_terminate aa->prev = (void *)1; - // Flush if we pass 16 megs of environment space. + // Flush if the child's environment space gets too large. // An insanely long path (>2 gigs) could wrap the counter and // defeat this test, which could potentially trigger OOM killer. - if ((aa->plus += sizeof(char *)+strlen(name)+1) > 1<<24) { + if ((aa->plus += sizeof(char *)+strlen(name)+1) > TT.max_bytes) { aa->plus = 1; toys.exitval |= flush_exec(new, aa); } @@ -543,6 +544,7 @@ void find_main(void) char **ss = toys.optargs; TT.topdir = -1; + TT.max_bytes = sysconf(_SC_ARG_MAX) - environ_bytes(); // Distinguish paths from filters for (len = 0; toys.optargs[len]; len++) diff --git a/toys/posix/time.c b/toys/posix/time.c index 2151826d..18664c10 100644 --- a/toys/posix/time.c +++ b/toys/posix/time.c @@ -4,22 +4,24 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/time.html -USE_TIME(NEWTOY(time, "<1^p", TOYFLAG_USR|TOYFLAG_BIN)) +USE_TIME(NEWTOY(time, "<1^pv", TOYFLAG_USR|TOYFLAG_BIN)) config TIME bool "time" default y depends on TOYBOX_FLOAT help - usage: time [-p] COMMAND [ARGS...] + usage: time [-pv] COMMAND [ARGS...] Run command line and report real, user, and system time elapsed in seconds. (real = clock on the wall, user = cpu used by command's code, system = cpu used by OS on behalf of command.) - -p posix mode (ignored) + -p posix mode (default) + -v verbose mode */ +#define FOR_time #include "toys.h" void time_main(void) @@ -43,7 +45,20 @@ void time_main(void) r = (tv2.tv_sec-tv.tv_sec)+((tv2.tv_usec-tv.tv_usec)/1000000.0); u = ru.ru_utime.tv_sec+(ru.ru_utime.tv_usec/1000000.0); s = ru.ru_stime.tv_sec+(ru.ru_stime.tv_usec/1000000.0); - fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s); + if (toys.optflags&FLAG_v) { + fprintf(stderr, "Real time (s): %f\n" + "System time (s): %f\n" + "User time (s): %f\n" + "Max RSS (KiB): %ld\n" + "Major faults: %ld\n" + "Minor faults: %ld\n" + "File system inputs: %ld\n" + "File system outputs: %ld\n" + "Voluntary context switches: %ld\n" + "Involuntary context switches: %ld\n", r, u, s, + ru.ru_maxrss, ru.ru_majflt, ru.ru_minflt, ru.ru_inblock, + ru.ru_oublock, ru.ru_nvcsw, ru.ru_nivcsw); + } else fprintf(stderr, "real %f\nuser %f\nsys %f\n", r, u, s); toys.exitval = WIFEXITED(stat) ? WEXITSTATUS(stat) : WTERMSIG(stat); } } |