aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2021-09-23 14:17:18 -0700
committerElliott Hughes <enh@google.com>2021-09-23 14:35:09 -0700
commit7cc7771c12fe083f37db151e80d0d9637e799684 (patch)
treee9b09d238eba774c27d1bc63b5a3ef8a464ddb0b
parent2703f86b6c0e2a147298ff301e831b51fe419801 (diff)
parent2a5dc105a323a20ab3dce82f3b39fa20555ab174 (diff)
downloadtoybox-7cc7771c12fe083f37db151e80d0d9637e799684.tar.gz
Upgrade toybox to 2a5dc105a323a20ab3dce82f3b39fa20555ab174
Test: make Change-Id: I5d9a16bac75c6e98b36b469d83db875c93b82990
-rw-r--r--METADATA16
-rw-r--r--android/device/generated/flags.h52
-rw-r--r--android/device/generated/globals.h4
-rw-r--r--android/device/generated/help.h4
-rw-r--r--android/device/generated/newtoys.h2
-rw-r--r--android/linux/generated/flags.h52
-rw-r--r--android/linux/generated/globals.h4
-rw-r--r--android/linux/generated/help.h4
-rw-r--r--android/linux/generated/newtoys.h2
-rw-r--r--android/mac/generated/flags.h52
-rw-r--r--android/mac/generated/globals.h4
-rw-r--r--android/mac/generated/help.h4
-rw-r--r--android/mac/generated/newtoys.h2
-rwxr-xr-xpost_update.sh (renamed from regenerate.sh)0
-rwxr-xr-xtests/grep.test1
-rw-r--r--toys/other/makedevs.c19
-rw-r--r--toys/other/uptime.c34
-rw-r--r--toys/pending/arp.c143
-rw-r--r--toys/pending/bootchartd.c28
-rw-r--r--toys/pending/crond.c18
-rw-r--r--toys/pending/init.c110
-rw-r--r--toys/pending/userdel.c14
-rw-r--r--toys/posix/grep.c13
23 files changed, 290 insertions, 292 deletions
diff --git a/METADATA b/METADATA
index 313792c1..0c292aa5 100644
--- a/METADATA
+++ b/METADATA
@@ -1,3 +1,19 @@
+name: "toybox"
+description: "Toybox: all-in-one Linux command line."
third_party {
+ url {
+ type: HOMEPAGE
+ value: "https://landley.net/toybox/"
+ }
+ url {
+ type: GIT
+ value: "https://github.com/landley/toybox"
+ }
+ version: "2a5dc105a323a20ab3dce82f3b39fa20555ab174"
license_type: UNENCUMBERED
+ last_upgrade_date {
+ year: 2021
+ month: 9
+ day: 23
+ }
}
diff --git a/android/device/generated/flags.h b/android/device/generated/flags.h
index 378a67f3..573db783 100644
--- a/android/device/generated/flags.h
+++ b/android/device/generated/flags.h
@@ -1126,9 +1126,9 @@
#undef FLAG_t
#endif
-// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
+// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
#undef OPTSTR_grep
-#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
+#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
#ifdef CLEANUP_grep
#undef CLEANUP_grep
#undef FOR_grep
@@ -1141,6 +1141,7 @@
#undef FLAG_e
#undef FLAG_q
#undef FLAG_l
+#undef FLAG_L
#undef FLAG_c
#undef FLAG_w
#undef FLAG_v
@@ -4589,29 +4590,30 @@
#define FLAG_e (1<<6)
#define FLAG_q (1<<7)
#define FLAG_l (1<<8)
-#define FLAG_c (1<<9)
-#define FLAG_w (1<<10)
-#define FLAG_v (1<<11)
-#define FLAG_s (1<<12)
-#define FLAG_R (1<<13)
-#define FLAG_r (1<<14)
-#define FLAG_o (1<<15)
-#define FLAG_n (1<<16)
-#define FLAG_i (1<<17)
-#define FLAG_h (1<<18)
-#define FLAG_b (1<<19)
-#define FLAG_a (1<<20)
-#define FLAG_I (1<<21)
-#define FLAG_H (1<<22)
-#define FLAG_F (1<<23)
-#define FLAG_E (1<<24)
-#define FLAG_z (1<<25)
-#define FLAG_Z (1<<26)
-#define FLAG_M (1<<27)
-#define FLAG_S (1<<28)
-#define FLAG_exclude_dir (1<<29)
-#define FLAG_color (1<<30)
-#define FLAG_line_buffered (1LL<<31)
+#define FLAG_L (1<<9)
+#define FLAG_c (1<<10)
+#define FLAG_w (1<<11)
+#define FLAG_v (1<<12)
+#define FLAG_s (1<<13)
+#define FLAG_R (1<<14)
+#define FLAG_r (1<<15)
+#define FLAG_o (1<<16)
+#define FLAG_n (1<<17)
+#define FLAG_i (1<<18)
+#define FLAG_h (1<<19)
+#define FLAG_b (1<<20)
+#define FLAG_a (1<<21)
+#define FLAG_I (1<<22)
+#define FLAG_H (1<<23)
+#define FLAG_F (1<<24)
+#define FLAG_E (1<<25)
+#define FLAG_z (1<<26)
+#define FLAG_Z (1<<27)
+#define FLAG_M (1<<28)
+#define FLAG_S (1<<29)
+#define FLAG_exclude_dir (1<<30)
+#define FLAG_color (1LL<<31)
+#define FLAG_line_buffered (1LL<<32)
#endif
#ifdef FOR_groupadd
diff --git a/android/device/generated/globals.h b/android/device/generated/globals.h
index 16079aba..3140d864 100644
--- a/android/device/generated/globals.h
+++ b/android/device/generated/globals.h
@@ -510,7 +510,7 @@ struct arp_data {
char *af_type_A;
char *af_type_p;
char *interface;
-
+
int sockfd;
char *device;
};
@@ -544,7 +544,7 @@ struct bc_data {
// toys/pending/bootchartd.c
struct bootchartd_data {
- char buf[32];
+ char timestamp[32];
long msec;
int proc_accounting;
diff --git a/android/device/generated/help.h b/android/device/generated/help.h
index dc9c149f..5ac0baca 100644
--- a/android/device/generated/help.h
+++ b/android/device/generated/help.h
@@ -474,7 +474,7 @@
#define HELP_arping "usage: arping [-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP\n\nSend ARP requests/replies\n\n-f Quit on first ARP reply\n-q Quiet\n-b Keep broadcasting, don't go unicast\n-D Duplicated address detection mode\n-U Unsolicited ARP mode, update your neighbors\n-A ARP answer mode, update your neighbors\n-c N Stop after sending N ARP requests\n-w TIMEOUT Time to wait for ARP reply, seconds\n-I IFACE Interface to use (default eth0)\n-s SRC_IP Sender IP address\nDST_IP Target IP address"
-#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IF Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
+#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache.\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IFACE Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
#define HELP_xargs "usage: xargs [-0prt] [-snE STR] COMMAND...\n\nRun command line one or more times, appending arguments from stdin.\n\nIf COMMAND exits with 255, don't launch another even if arguments remain.\n\n-0 Each argument is NULL terminated, no whitespace or quote processing\n-E Stop at line matching string\n-n Max number of arguments per command\n-o Open tty for COMMAND's stdin (default /dev/null)\n-p Prompt for y/n from tty before running each command\n-P Parallel processes (default 1)\n-r Don't run with empty input (otherwise always run command once)\n-s Size in bytes per command line\n-t Trace, print command line to stderr"
@@ -584,7 +584,7 @@
#define HELP_head "usage: head [-n NUM] [FILE...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n Number of lines to copy\n-c Number of bytes to copy\n-q Never print headers\n-v Always print headers"
-#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
+#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-L show only non-matching filenames\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
#define HELP_getconf "usage: getconf -a [PATH] | -l | NAME [PATH]\n\nGet system configuration values. Values from pathconf(3) require a path.\n\n-a Show all (defaults to \"/\" if no path given)\n-l List available value names (grouped by source)"
diff --git a/android/device/generated/newtoys.h b/android/device/generated/newtoys.h
index 51414673..0c43fadb 100644
--- a/android/device/generated/newtoys.h
+++ b/android/device/generated/newtoys.h
@@ -102,7 +102,7 @@ USE_GETENFORCE(NEWTOY(getenforce, ">0", TOYFLAG_USR|TOYFLAG_SBIN))
USE_GETFATTR(NEWTOY(getfattr, "(only-values)dhn:", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETOPT(NEWTOY(getopt, "^a(alternative)n:(name)o:(options)l*(long)(longoptions)Tu", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETTY(NEWTOY(getty, "<2t#<0H:I:l:f:iwnmLh", TOYFLAG_SBIN))
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
USE_GROUPADD(NEWTOY(groupadd, "<1>2g#<0S", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPDEL(NEWTOY(groupdel, "<1>2", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/linux/generated/flags.h b/android/linux/generated/flags.h
index ac676453..84c68c46 100644
--- a/android/linux/generated/flags.h
+++ b/android/linux/generated/flags.h
@@ -1126,9 +1126,9 @@
#undef FLAG_t
#endif
-// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
+// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
#undef OPTSTR_grep
-#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
+#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
#ifdef CLEANUP_grep
#undef CLEANUP_grep
#undef FOR_grep
@@ -1141,6 +1141,7 @@
#undef FLAG_e
#undef FLAG_q
#undef FLAG_l
+#undef FLAG_L
#undef FLAG_c
#undef FLAG_w
#undef FLAG_v
@@ -4589,29 +4590,30 @@
#define FLAG_e (1<<6)
#define FLAG_q (1<<7)
#define FLAG_l (1<<8)
-#define FLAG_c (1<<9)
-#define FLAG_w (1<<10)
-#define FLAG_v (1<<11)
-#define FLAG_s (1<<12)
-#define FLAG_R (1<<13)
-#define FLAG_r (1<<14)
-#define FLAG_o (1<<15)
-#define FLAG_n (1<<16)
-#define FLAG_i (1<<17)
-#define FLAG_h (1<<18)
-#define FLAG_b (1<<19)
-#define FLAG_a (1<<20)
-#define FLAG_I (1<<21)
-#define FLAG_H (1<<22)
-#define FLAG_F (1<<23)
-#define FLAG_E (1<<24)
-#define FLAG_z (1<<25)
-#define FLAG_Z (1<<26)
-#define FLAG_M (1<<27)
-#define FLAG_S (1<<28)
-#define FLAG_exclude_dir (1<<29)
-#define FLAG_color (1<<30)
-#define FLAG_line_buffered (1LL<<31)
+#define FLAG_L (1<<9)
+#define FLAG_c (1<<10)
+#define FLAG_w (1<<11)
+#define FLAG_v (1<<12)
+#define FLAG_s (1<<13)
+#define FLAG_R (1<<14)
+#define FLAG_r (1<<15)
+#define FLAG_o (1<<16)
+#define FLAG_n (1<<17)
+#define FLAG_i (1<<18)
+#define FLAG_h (1<<19)
+#define FLAG_b (1<<20)
+#define FLAG_a (1<<21)
+#define FLAG_I (1<<22)
+#define FLAG_H (1<<23)
+#define FLAG_F (1<<24)
+#define FLAG_E (1<<25)
+#define FLAG_z (1<<26)
+#define FLAG_Z (1<<27)
+#define FLAG_M (1<<28)
+#define FLAG_S (1<<29)
+#define FLAG_exclude_dir (1<<30)
+#define FLAG_color (1LL<<31)
+#define FLAG_line_buffered (1LL<<32)
#endif
#ifdef FOR_groupadd
diff --git a/android/linux/generated/globals.h b/android/linux/generated/globals.h
index 16079aba..3140d864 100644
--- a/android/linux/generated/globals.h
+++ b/android/linux/generated/globals.h
@@ -510,7 +510,7 @@ struct arp_data {
char *af_type_A;
char *af_type_p;
char *interface;
-
+
int sockfd;
char *device;
};
@@ -544,7 +544,7 @@ struct bc_data {
// toys/pending/bootchartd.c
struct bootchartd_data {
- char buf[32];
+ char timestamp[32];
long msec;
int proc_accounting;
diff --git a/android/linux/generated/help.h b/android/linux/generated/help.h
index 2154ba77..b51afad8 100644
--- a/android/linux/generated/help.h
+++ b/android/linux/generated/help.h
@@ -476,7 +476,7 @@
#define HELP_arping "usage: arping [-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP\n\nSend ARP requests/replies\n\n-f Quit on first ARP reply\n-q Quiet\n-b Keep broadcasting, don't go unicast\n-D Duplicated address detection mode\n-U Unsolicited ARP mode, update your neighbors\n-A ARP answer mode, update your neighbors\n-c N Stop after sending N ARP requests\n-w TIMEOUT Time to wait for ARP reply, seconds\n-I IFACE Interface to use (default eth0)\n-s SRC_IP Sender IP address\nDST_IP Target IP address"
-#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IF Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
+#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache.\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IFACE Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
#define HELP_xargs "usage: xargs [-0prt] [-snE STR] COMMAND...\n\nRun command line one or more times, appending arguments from stdin.\n\nIf COMMAND exits with 255, don't launch another even if arguments remain.\n\n-0 Each argument is NULL terminated, no whitespace or quote processing\n-E Stop at line matching string\n-n Max number of arguments per command\n-o Open tty for COMMAND's stdin (default /dev/null)\n-p Prompt for y/n from tty before running each command\n-P Parallel processes (default 1)\n-r Don't run with empty input (otherwise always run command once)\n-s Size in bytes per command line\n-t Trace, print command line to stderr"
@@ -590,7 +590,7 @@
#define HELP_head "usage: head [-n NUM] [FILE...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n Number of lines to copy\n-c Number of bytes to copy\n-q Never print headers\n-v Always print headers"
-#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
+#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-L show only non-matching filenames\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
#define HELP_getconf "usage: getconf -a [PATH] | -l | NAME [PATH]\n\nGet system configuration values. Values from pathconf(3) require a path.\n\n-a Show all (defaults to \"/\" if no path given)\n-l List available value names (grouped by source)"
diff --git a/android/linux/generated/newtoys.h b/android/linux/generated/newtoys.h
index 51414673..0c43fadb 100644
--- a/android/linux/generated/newtoys.h
+++ b/android/linux/generated/newtoys.h
@@ -102,7 +102,7 @@ USE_GETENFORCE(NEWTOY(getenforce, ">0", TOYFLAG_USR|TOYFLAG_SBIN))
USE_GETFATTR(NEWTOY(getfattr, "(only-values)dhn:", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETOPT(NEWTOY(getopt, "^a(alternative)n:(name)o:(options)l*(long)(longoptions)Tu", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETTY(NEWTOY(getty, "<2t#<0H:I:l:f:iwnmLh", TOYFLAG_SBIN))
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
USE_GROUPADD(NEWTOY(groupadd, "<1>2g#<0S", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPDEL(NEWTOY(groupdel, "<1>2", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/android/mac/generated/flags.h b/android/mac/generated/flags.h
index 88189027..5d464251 100644
--- a/android/mac/generated/flags.h
+++ b/android/mac/generated/flags.h
@@ -1126,9 +1126,9 @@
#undef FLAG_t
#endif
-// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
+// grep (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw] (line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]
#undef OPTSTR_grep
-#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
+#define OPTSTR_grep "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]"
#ifdef CLEANUP_grep
#undef CLEANUP_grep
#undef FOR_grep
@@ -1141,6 +1141,7 @@
#undef FLAG_e
#undef FLAG_q
#undef FLAG_l
+#undef FLAG_L
#undef FLAG_c
#undef FLAG_w
#undef FLAG_v
@@ -4589,29 +4590,30 @@
#define FLAG_e (1<<6)
#define FLAG_q (1<<7)
#define FLAG_l (1<<8)
-#define FLAG_c (1<<9)
-#define FLAG_w (1<<10)
-#define FLAG_v (1<<11)
-#define FLAG_s (1<<12)
-#define FLAG_R (1<<13)
-#define FLAG_r (1<<14)
-#define FLAG_o (1<<15)
-#define FLAG_n (1<<16)
-#define FLAG_i (1<<17)
-#define FLAG_h (1<<18)
-#define FLAG_b (1<<19)
-#define FLAG_a (1<<20)
-#define FLAG_I (1<<21)
-#define FLAG_H (1<<22)
-#define FLAG_F (1<<23)
-#define FLAG_E (1<<24)
-#define FLAG_z (1<<25)
-#define FLAG_Z (1<<26)
-#define FLAG_M (1<<27)
-#define FLAG_S (1<<28)
-#define FLAG_exclude_dir (1<<29)
-#define FLAG_color (1<<30)
-#define FLAG_line_buffered (1LL<<31)
+#define FLAG_L (1<<9)
+#define FLAG_c (1<<10)
+#define FLAG_w (1<<11)
+#define FLAG_v (1<<12)
+#define FLAG_s (1<<13)
+#define FLAG_R (1<<14)
+#define FLAG_r (1<<15)
+#define FLAG_o (1<<16)
+#define FLAG_n (1<<17)
+#define FLAG_i (1<<18)
+#define FLAG_h (1<<19)
+#define FLAG_b (1<<20)
+#define FLAG_a (1<<21)
+#define FLAG_I (1<<22)
+#define FLAG_H (1<<23)
+#define FLAG_F (1<<24)
+#define FLAG_E (1<<25)
+#define FLAG_z (1<<26)
+#define FLAG_Z (1<<27)
+#define FLAG_M (1<<28)
+#define FLAG_S (1<<29)
+#define FLAG_exclude_dir (1<<30)
+#define FLAG_color (1LL<<31)
+#define FLAG_line_buffered (1LL<<32)
#endif
#ifdef FOR_groupadd
diff --git a/android/mac/generated/globals.h b/android/mac/generated/globals.h
index 16079aba..3140d864 100644
--- a/android/mac/generated/globals.h
+++ b/android/mac/generated/globals.h
@@ -510,7 +510,7 @@ struct arp_data {
char *af_type_A;
char *af_type_p;
char *interface;
-
+
int sockfd;
char *device;
};
@@ -544,7 +544,7 @@ struct bc_data {
// toys/pending/bootchartd.c
struct bootchartd_data {
- char buf[32];
+ char timestamp[32];
long msec;
int proc_accounting;
diff --git a/android/mac/generated/help.h b/android/mac/generated/help.h
index 2154ba77..b51afad8 100644
--- a/android/mac/generated/help.h
+++ b/android/mac/generated/help.h
@@ -476,7 +476,7 @@
#define HELP_arping "usage: arping [-fqbDUA] [-c CNT] [-w TIMEOUT] [-I IFACE] [-s SRC_IP] DST_IP\n\nSend ARP requests/replies\n\n-f Quit on first ARP reply\n-q Quiet\n-b Keep broadcasting, don't go unicast\n-D Duplicated address detection mode\n-U Unsolicited ARP mode, update your neighbors\n-A ARP answer mode, update your neighbors\n-c N Stop after sending N ARP requests\n-w TIMEOUT Time to wait for ARP reply, seconds\n-I IFACE Interface to use (default eth0)\n-s SRC_IP Sender IP address\nDST_IP Target IP address"
-#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IF Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
+#define HELP_arp "usage: arp\n[-vn] [-H HWTYPE] [-i IF] -a [HOSTNAME]\n[-v] [-i IF] -d HOSTNAME [pub]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [temp]\n[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub\n[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub\n\nManipulate ARP cache.\n\n-a Display (all) hosts\n-s Set new ARP entry\n-d Delete a specified entry\n-v Verbose\n-n Don't resolve names\n-i IFACE Network interface\n-D Read <hwaddr> from given device\n-A,-p AF Protocol family\n-H HWTYPE Hardware address type"
#define HELP_xargs "usage: xargs [-0prt] [-snE STR] COMMAND...\n\nRun command line one or more times, appending arguments from stdin.\n\nIf COMMAND exits with 255, don't launch another even if arguments remain.\n\n-0 Each argument is NULL terminated, no whitespace or quote processing\n-E Stop at line matching string\n-n Max number of arguments per command\n-o Open tty for COMMAND's stdin (default /dev/null)\n-p Prompt for y/n from tty before running each command\n-P Parallel processes (default 1)\n-r Don't run with empty input (otherwise always run command once)\n-s Size in bytes per command line\n-t Trace, print command line to stderr"
@@ -590,7 +590,7 @@
#define HELP_head "usage: head [-n NUM] [FILE...]\n\nCopy first lines from files to stdout. If no files listed, copy from\nstdin. Filename \"-\" is a synonym for stdin.\n\n-n Number of lines to copy\n-c Number of bytes to copy\n-q Never print headers\n-v Always print headers"
-#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
+#define HELP_grep "usage: grep [-EFrivwcloqsHbhn] [-ABC NUM] [-m MAX] [-e REGEX]... [-MS PATTERN]... [-f REGFILE] [FILE]...\n\nShow lines matching regular expressions. If no -e, first argument is\nregular expression to match. With no files (or \"-\" filename) read stdin.\nReturns 0 if matched, 1 if no match found, 2 for command errors.\n\n-e Regex to match. (May be repeated.)\n-f File listing regular expressions to match.\n\nfile search:\n-r Recurse into subdirectories (defaults FILE to \".\")\n-R Recurse into subdirectories and symlinks to directories\n-M Match filename pattern (--include)\n-S Skip filename pattern (--exclude)\n--exclude-dir=PATTERN Skip directory pattern\n-I Ignore binary files\n\nmatch type:\n-A Show NUM lines after -B Show NUM lines before match\n-C NUM lines context (A+B) -E extended regex syntax\n-F fixed (literal match) -a always text (not binary)\n-i case insensitive -m match MAX many lines\n-v invert match -w whole word (implies -E)\n-x whole line -z input NUL terminated\n\ndisplay modes: (default: matched line)\n-L show only non-matching filenames\n-c count of matching lines -l show only matching filenames\n-o only matching part -q quiet (errors only)\n-s silent (no error msg) -Z output NUL terminated\n\noutput prefix (default: filename if checking more than 1 file)\n-H force filename -b byte offset of match\n-h hide filename -n line number of match"
#define HELP_getconf "usage: getconf -a [PATH] | -l | NAME [PATH]\n\nGet system configuration values. Values from pathconf(3) require a path.\n\n-a Show all (defaults to \"/\" if no path given)\n-l List available value names (grouped by source)"
diff --git a/android/mac/generated/newtoys.h b/android/mac/generated/newtoys.h
index 51414673..0c43fadb 100644
--- a/android/mac/generated/newtoys.h
+++ b/android/mac/generated/newtoys.h
@@ -102,7 +102,7 @@ USE_GETENFORCE(NEWTOY(getenforce, ">0", TOYFLAG_USR|TOYFLAG_SBIN))
USE_GETFATTR(NEWTOY(getfattr, "(only-values)dhn:", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETOPT(NEWTOY(getopt, "^a(alternative)n:(name)o:(options)l*(long)(longoptions)Tu", TOYFLAG_USR|TOYFLAG_BIN))
USE_GETTY(NEWTOY(getty, "<2t#<0H:I:l:f:iwnmLh", TOYFLAG_SBIN))
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
USE_GROUPADD(NEWTOY(groupadd, "<1>2g#<0S", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPDEL(NEWTOY(groupdel, "<1>2", TOYFLAG_NEEDROOT|TOYFLAG_SBIN))
USE_GROUPS(NEWTOY(groups, NULL, TOYFLAG_USR|TOYFLAG_BIN))
diff --git a/regenerate.sh b/post_update.sh
index 689a482a..689a482a 100755
--- a/regenerate.sh
+++ b/post_update.sh
diff --git a/tests/grep.test b/tests/grep.test
index 215491c2..7f882919 100755
--- a/tests/grep.test
+++ b/tests/grep.test
@@ -13,6 +13,7 @@ echo -e "this is test" > foo
echo -e "this is test2" > foo2
echo -e "this is foo3" > foo3
testing "-l" "grep -l test foo foo2 foo3" "foo\nfoo2\n" "" ""
+testing "-L" "grep -L test foo foo2 foo3" "foo3\n" "" ""
rm foo foo2 foo3
testing "-q" "grep -q test input && echo yes" "yes\n" "this is a test\n" ""
diff --git a/toys/other/makedevs.c b/toys/other/makedevs.c
index a6998fcc..4edd0737 100644
--- a/toys/other/makedevs.c
+++ b/toys/other/makedevs.c
@@ -39,22 +39,24 @@ GLOBALS(
char *d;
)
-void makedevs_main()
+void makedevs_main(void)
{
- int fd = 0, line_no, i;
+ FILE *fp = stdin;
char *line = NULL;
+ size_t allocated_length = 0;
+ int line_no = 0, i;
// Open file and chdir, verbosely
xprintf("rootdir = %s\n", *toys.optargs);
- if ((toys.optflags & FLAG_d) && strcmp(TT.d, "-")) {
- fd = xopenro(TT.d);
+ if (FLAG(d) && strcmp(TT.d, "-")) {
+ fp = xfopen(TT.d, "r");
xprintf("table = %s\n", TT.d);
} else xprintf("table = <stdin>\n");
xchdir(*toys.optargs);
- for (line_no = 0; (line = get_line(fd)); free(line)) {
+ while (getline(&line, &allocated_length, fp) > 0) {
char type=0, user[64], group[64], *node, *ptr = line;
- unsigned int mode = 0755, major = 0, minor = 0, cnt = 0, incr = 0,
+ unsigned int mode = 0755, major = 0, minor = 0, cnt = 0, incr = 0,
st_val = 0;
uid_t uid;
gid_t gid;
@@ -104,9 +106,10 @@ void makedevs_main()
continue;
}
- if (chown(ptr, uid, gid) || chmod(ptr, mode))
+ if (chown(ptr, uid, gid) || chmod(ptr, mode))
perror_msg("line %d: can't chown/chmod '%s'", line_no, ptr);
}
}
- xclose(fd);
+ free(line);
+ if (fp != stdin) fclose(fp);
}
diff --git a/toys/other/uptime.c b/toys/other/uptime.c
index 001af02c..6c0c8052 100644
--- a/toys/other/uptime.c
+++ b/toys/other/uptime.c
@@ -28,7 +28,7 @@ void uptime_main(void)
struct sysinfo info;
time_t t;
struct tm *tm;
- unsigned int days, hours, minutes;
+ unsigned int weeks, days, hours, minutes;
struct utmpx *entry;
int users = 0;
@@ -37,7 +37,7 @@ void uptime_main(void)
time(&t);
// Just show the time of boot?
- if (toys.optflags & FLAG_s) {
+ if (FLAG(s)) {
t -= info.uptime;
tm = localtime(&t);
strftime(toybuf, sizeof(toybuf), "%F %T", tm);
@@ -54,29 +54,27 @@ void uptime_main(void)
hours = info.uptime%24;
days = info.uptime/24;
- if (toys.optflags & FLAG_p) {
- int weeks = days/7;
+ if (FLAG(p)) {
+ weeks = days/7;
days %= 7;
-
- xprintf("up %d week%s, %d day%s, %d hour%s, %d minute%s\n",
+ xprintf("up %d week%s, %d day%s, %d hour%s, %d minute%s, ",
weeks, (weeks!=1)?"s":"",
days, (days!=1)?"s":"",
hours, (hours!=1)?"s":"",
minutes, (minutes!=1)?"s":"");
- return;
- }
+ } else {
+ xprintf(" %02d:%02d:%02d up ", tm->tm_hour, tm->tm_min, tm->tm_sec);
+ if (days) xprintf("%d day%s, ", days, (days!=1)?"s":"");
+ if (hours) xprintf("%2d:%02d, ", hours, minutes);
+ else printf("%d min, ", minutes);
- xprintf(" %02d:%02d:%02d up ", tm->tm_hour, tm->tm_min, tm->tm_sec);
- if (days) xprintf("%d day%s, ", days, (days!=1)?"s":"");
- if (hours) xprintf("%2d:%02d, ", hours, minutes);
- else printf("%d min, ", minutes);
-
- // Obtain info about logged on users
- setutxent();
- while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++;
- endutxent();
+ // Obtain info about logged on users
+ setutxent();
+ while ((entry = getutxent())) if (entry->ut_type == USER_PROCESS) users++;
+ endutxent();
+ printf(" %d user%s, ", users, (users!=1) ? "s" : "");
+ }
- printf(" %d user%s, ", users, (users!=1) ? "s" : "");
printf(" load average: %.02f, %.02f, %.02f\n", info.loads[0]/65536.0,
info.loads[1]/65536.0, info.loads[2]/65536.0);
}
diff --git a/toys/pending/arp.c b/toys/pending/arp.c
index eaecfc71..0f564288 100644
--- a/toys/pending/arp.c
+++ b/toys/pending/arp.c
@@ -2,7 +2,7 @@
*
* Copyright 2014 Sandeep Sharma <sandeep.jack2756@gmail.com>
* Copyright 2014 Kyungwan Han <asura321@gamil.com>
- * No Standard
+ * No Standard
USE_ARP(NEWTOY(arp, "vi:nDsdap:A:H:[+Ap][!sd]", TOYFLAG_USR|TOYFLAG_BIN))
@@ -17,17 +17,17 @@ config ARP
[-v] [-H HWTYPE] [-i IF] -s HOSTNAME HWADDR [netmask MASK] pub
[-v] [-H HWTYPE] [-i IF] -Ds HOSTNAME IFACE [netmask MASK] pub
- Manipulate ARP cache
+ Manipulate ARP cache.
- -a Display (all) hosts
- -s Set new ARP entry
- -d Delete a specified entry
- -v Verbose
- -n Don't resolve names
- -i IF Network interface
- -D Read <hwaddr> from given device
- -A,-p AF Protocol family
- -H HWTYPE Hardware address type
+ -a Display (all) hosts
+ -s Set new ARP entry
+ -d Delete a specified entry
+ -v Verbose
+ -n Don't resolve names
+ -i IFACE Network interface
+ -D Read <hwaddr> from given device
+ -A,-p AF Protocol family
+ -H HWTYPE Hardware address type
*/
@@ -40,12 +40,12 @@ GLOBALS(
char *af_type_A;
char *af_type_p;
char *interface;
-
+
int sockfd;
char *device;
)
-struct arpreq req; //Global request structure
+struct arpreq req;
struct type {
char *name;
@@ -53,7 +53,7 @@ struct type {
};
struct type hwtype[] = {
- {"ether", ARPHRD_ETHER },
+ {"ether", ARPHRD_ETHER },
{"loop" ,ARPHRD_LOOPBACK},
{"ppp" ,ARPHRD_PPP},
{"infiniband" ,ARPHRD_INFINIBAND},
@@ -61,14 +61,14 @@ struct type hwtype[] = {
};
struct type aftype[] = {
- {"inet", AF_INET },
+ {"inet", AF_INET },
{"inet6" ,AF_INET6},
{"unspec" ,AF_UNSPEC},
{NULL, -1},
};
struct type flag_type[] = {
- {"PERM", ATF_PERM },
+ {"PERM", ATF_PERM },
{"PUB" ,ATF_PUBL},
{"DONTPUB" ,ATF_DONTPUB},
{"TRAIL" ,ATF_USETRAILERS},
@@ -78,25 +78,18 @@ struct type flag_type[] = {
static int get_index(struct type arr[], char *name)
{
int i;
-
- for (i = 0; arr[i].name; i++)
+
+ for (i = 0; arr[i].name; i++)
if (!strcmp(arr[i].name, name)) break;
return arr[i].val;
}
static void resolve_host(char *host, struct sockaddr *sa)
{
- struct addrinfo hints, *res = NULL;
- int ret;
+ struct addrinfo *ai = xgetaddrinfo(host, NULL, AF_INET, SOCK_STREAM, 0, 0);
- memset(&hints, 0, sizeof hints);
- hints.ai_family = AF_INET;
- hints.ai_socktype = SOCK_STREAM;
- if ((ret = getaddrinfo(host, NULL, &hints, &res)))
- perror_exit("%s", gai_strerror(ret));
-
- memcpy(sa, res->ai_addr, res->ai_addrlen);
- freeaddrinfo(res);
+ memcpy(sa, ai->ai_addr, ai->ai_addrlen);
+ freeaddrinfo(ai);
}
static void check_flags(int *i, char** argv)
@@ -142,7 +135,7 @@ static int set_entry(void)
if (!toys.optargs[1]) error_exit("bad syntax");
- if (!(toys.optflags & FLAG_D)) {
+ if (!FLAG(D)) {
char *ptr = toys.optargs[1];
char *p = ptr, *hw_addr = req.arp_ha.sa_data;
@@ -162,7 +155,7 @@ static int set_entry(void)
xstrncpy(ifre.ifr_name, toys.optargs[1], IFNAMSIZ);
xioctl(TT.sockfd, SIOCGIFHWADDR, &ifre);
- if ((toys.optflags & FLAG_H) && (ifre.ifr_hwaddr.sa_family != ARPHRD_ETHER))
+ if (FLAG(H) && ifre.ifr_hwaddr.sa_family != ARPHRD_ETHER)
error_exit("protocol type mismatch");
memcpy(&req.arp_ha, &(ifre.ifr_hwaddr), sizeof(req.arp_ha));
}
@@ -172,12 +165,12 @@ static int set_entry(void)
req.arp_flags = flags;
xstrncpy(req.arp_dev, TT.device, sizeof(req.arp_dev));
xioctl(TT.sockfd, SIOCSARP, &req);
-
- if (toys.optflags & FLAG_v) xprintf("Entry set for %s\n", toys.optargs[0]);
+
+ if (FLAG(v)) xprintf("Entry set for %s\n", toys.optargs[0]);
return 0;
}
-static int ip_to_host(struct sockaddr *sa, int flag)
+static int ip_to_host(struct sockaddr *sa, int flag)
{
int status = 0;
char hbuf[NI_MAXHOST] = {0,}, sbuf[NI_MAXSERV] = {0,};
@@ -194,55 +187,51 @@ static int ip_to_host(struct sockaddr *sa, int flag)
static int delete_entry(void)
{
- int flags;
-
- flags = ATF_PERM;
+ int flags = ATF_PERM;
+
if (toys.optargs[1]) check_flags(&flags, (toys.optargs+1));
req.arp_flags = flags;
xstrncpy(req.arp_dev, TT.device, sizeof(req.arp_dev));
xioctl(TT.sockfd, SIOCDARP, &req);
-
- if (toys.optflags & FLAG_v) xprintf("Delete entry for %s\n", toys.optargs[0]);
+
+ if (FLAG(v)) xprintf("Delete entry for %s\n", toys.optargs[0]);
return 0;
}
void arp_main(void)
{
struct sockaddr sa;
- char ip[128], hw_addr[128], mask[12], dev[128], *host_ip = NULL, *buf;
- int h_type, type, flag, i, fd, entries = 0, disp = 0;
+ char ip[16], hw_addr[30], mask[16], dev[16], *host_ip = NULL;
+ FILE *fp;
+ int h_type, type, flag, i, entries = 0, disp = 0;
TT.device = "";
memset(&sa, 0, sizeof(sa));
- memset(&req, 0, sizeof(req));
TT.sockfd = xsocket(AF_INET, SOCK_STREAM, 0);
- if ((toys.optflags & FLAG_A) || (toys.optflags & FLAG_p)) {
- if ((type = get_index(aftype,
- (TT.af_type_A)?TT.af_type_A:TT.af_type_p)) != AF_INET)
+ if (FLAG(A) || FLAG(p)) {
+ if ((type = get_index(aftype,
+ (TT.af_type_A)?TT.af_type_A:TT.af_type_p)) != AF_INET)
error_exit((type != -1)?"only inet supported by kernel":"unknown family");
- }
+ }
req.arp_ha.sa_family = ARPHRD_ETHER;
- if (toys.optflags & FLAG_H) {
- if ((type = get_index(hwtype, TT.hw_type)) != ARPHRD_ETHER)
+ if (FLAG(H)) {
+ if ((type = get_index(hwtype, TT.hw_type)) != ARPHRD_ETHER)
error_exit((type != -1)?"h/w type not supported":"unknown h/w type");
req.arp_ha.sa_family = type;
}
- if (((toys.optflags & FLAG_s) || toys.optflags & FLAG_d)) {
- if (!toys.optargs[0]) error_exit("host name req");
+ if (FLAG(s) || FLAG(d)) {
+ if (!toys.optargs[0]) error_exit("-%c needs a host name", FLAG(d)?'d':'s');
resolve_host(toys.optargs[0], &sa);
memcpy(&req.arp_pa, &sa, sizeof(struct sockaddr));
- }
- if ((toys.optflags & FLAG_s) && !set_entry()) return;
- if ((toys.optflags & FLAG_d) && !delete_entry()) return;
+ if (FLAG(s) && !set_entry()) return;
+ if (FLAG(d) && !delete_entry()) return;
+ }
- //show arp chache
- fd = xopenro("/proc/net/arp");
- buf = get_line(fd);
- free(buf); //skip first line
+ // Show arp cache.
if (toys.optargs[0]) {
resolve_host(toys.optargs[0], &sa);
@@ -250,28 +239,27 @@ void arp_main(void)
host_ip = xstrdup(toybuf);
}
- while ((buf = get_line(fd))) {
+ fp = xfopen("/proc/net/arp", "r");
+ fgets(toybuf, sizeof(toybuf), fp); // Skip header.
+ while (fscanf(fp, "%16s 0x%x 0x%x %30s %16s %16s",
+ ip, &h_type, &flag, hw_addr, mask, dev) == 6) {
char *host_name = "?";
-
- if ((sscanf(buf, "%s 0x%x 0x%x %s %s %s\n", ip,
- &h_type, &flag, hw_addr, mask, dev )) != 6) break;
+
entries++;
- if (((toys.optflags & FLAG_H) && (get_index(hwtype, TT.hw_type) != h_type))
- || ((toys.optflags & FLAG_i) && strcmp(TT.interface, dev))
- || (toys.optargs[0] && strcmp(host_ip, ip))) {
- free(buf);
+ if ((FLAG(H) && get_index(hwtype, TT.hw_type) != h_type) ||
+ (FLAG(i) && strcmp(TT.interface, dev)) ||
+ (toys.optargs[0] && strcmp(host_ip, ip))) {
continue;
}
- resolve_host(buf, &sa);
- if (!(toys.optflags & FLAG_n)) {
- if (!ip_to_host(&sa, NI_NAMEREQD)) host_name = toybuf;
- } else ip_to_host(&sa, NI_NUMERICHOST);
-
+ resolve_host(ip, &sa);
+ if (FLAG(n)) ip_to_host(&sa, NI_NUMERICHOST);
+ else if (!ip_to_host(&sa, NI_NAMEREQD)) host_name = toybuf;
+
disp++;
printf("%s (%s) at" , host_name, ip);
- for (i = 0; hwtype[i].name; i++)
+ for (i = 0; hwtype[i].name; i++)
if (hwtype[i].val & h_type) break;
if (!hwtype[i].name) error_exit("unknown h/w type");
@@ -282,21 +270,20 @@ void arp_main(void)
if (flag & ATF_NETMASK) printf("netmask %s ", mask);
- for (i = 0; flag_type[i].name; i++)
+ for (i = 0; flag_type[i].name; i++)
if (flag_type[i].val & flag) printf(" %s", flag_type[i].name);
printf(" on %s\n", dev);
- free(buf);
}
-
- if (toys.optflags & FLAG_v)
+
+ if (FLAG(v))
xprintf("Entries: %d\tSkipped: %d\tFound: %d\n",
entries, entries - disp, disp);
- if (!disp) xprintf("No Match found in %d entries\n", entries);
-
+ if (toys.optargs[0] && !disp)
+ xprintf("%s (%s) -- no entry\n", toys.optargs[0], host_ip);
+
if (CFG_TOYBOX_FREE) {
free(host_ip);
- free(buf);
- xclose(fd);
+ fclose(fp);
}
}
diff --git a/toys/pending/bootchartd.c b/toys/pending/bootchartd.c
index 3590c81e..78084289 100644
--- a/toys/pending/bootchartd.c
+++ b/toys/pending/bootchartd.c
@@ -29,7 +29,7 @@ config BOOTCHARTD
#include "toys.h"
GLOBALS(
- char buf[32];
+ char timestamp[32];
long msec;
int proc_accounting;
@@ -41,7 +41,7 @@ static void dump_data_in_file(char *fname, int wfd)
int rfd = open(fname, O_RDONLY);
if (rfd != -1) {
- xwrite(wfd, TT.buf, strlen(TT.buf));
+ xwrite(wfd, TT.timestamp, strlen(TT.timestamp));
xsendfile(rfd, wfd);
close(rfd);
xwrite(wfd, "\n", 1);
@@ -55,7 +55,7 @@ static int dump_proc_data(FILE *fp)
pid_t pid;
DIR *proc_dir = opendir("/proc");
- fputs(TT.buf, fp);
+ fputs(TT.timestamp, fp);
while ((pid_dir = readdir(proc_dir))) {
char filename[64];
int fd;
@@ -134,6 +134,7 @@ static char *create_tmp_dir()
static void start_logging()
{
+ struct timespec ts;
int proc_stat_fd = xcreate("proc_stat.log",
O_WRONLY | O_CREAT | O_TRUNC, 0644);
int proc_diskstats_fd = xcreate("proc_diskstats.log",
@@ -148,31 +149,16 @@ static void start_logging()
xclose(kp_fd);
acct("kernel_procs_acct");
}
- memset(TT.buf, 0, sizeof(TT.buf));
while (--tcnt && !toys.signal) {
- int i = 0, j = 0, fd = open("/proc/uptime", O_RDONLY);
- if (fd < 0) goto wait;
- char *line = get_line(fd);
-
- if (!line) goto wait;
- while (line[i] != ' ') {
- if (line[i] == '.') {
- i++;
- continue;
- }
- TT.buf[j++] = line[i++];
- }
- TT.buf[j++] = '\n';
- TT.buf[j] = 0;
- free(line);
- close(fd);
+ clock_gettime(CLOCK_BOOTTIME, &ts);
+ sprintf(TT.timestamp, "%ld.%02d\n", (long) ts.tv_sec,
+ (int) (ts.tv_nsec/10000000));
dump_data_in_file("/proc/stat", proc_stat_fd);
dump_data_in_file("/proc/diskstats", proc_diskstats_fd);
// stop proc dumping in 2 secs if getty or gdm, kdm, xdm found
if (dump_proc_data(proc_ps_fp))
if (tcnt > 2 * 1000 / TT.msec) tcnt = 2 * 1000 / TT.msec;
fflush(0);
-wait:
msleep(TT.msec);
}
xclose(proc_stat_fd);
diff --git a/toys/pending/crond.c b/toys/pending/crond.c
index df8b5f11..81cc8448 100644
--- a/toys/pending/crond.c
+++ b/toys/pending/crond.c
@@ -371,26 +371,29 @@ static void scan_cronfiles()
if (!(dp = opendir("."))) loginfo(LOG_EXIT, "chdir(%s)", ".");
while ((entry = readdir(dp))) {
- int fd;
- char *line;
CRONFILE *cfile;
+ FILE *fp;
+ char *line = 0;
+ size_t allocated_length = 0;
- if (entry->d_name[0] == '.' && (!entry->d_name[1] ||
- (entry->d_name[1] == '.' && !entry->d_name[2])))
- continue;
+ if (isdotdot(entry->d_name)) continue;
if (!getpwnam(entry->d_name)) {
loginfo(LOG_LEVEL7, "ignoring file '%s' (no such user)", entry->d_name);
continue;
}
- if ((fd = open(entry->d_name, O_RDONLY)) < 0) continue;
+
+ if (!(fp = fopen(entry->d_name, "r"))) continue;
// one node for each user
cfile = xzalloc(sizeof(CRONFILE));
cfile->username = xstrdup(entry->d_name);
- for (; (line = get_line(fd)); free(line))
+ while (getline(&line, &allocated_length, fp) > 0) {
parse_line(line, cfile);
+ }
+ free(line);
+ fclose(fp);
// If there is no job for a cron, remove the VAR list.
if (!cfile->job) {
@@ -410,7 +413,6 @@ static void scan_cronfiles()
dlist_add_nomalloc((struct double_list **)&gclist,
(struct double_list *)cfile);
}
- close(fd);
}
closedir(dp);
}
diff --git a/toys/pending/init.c b/toys/pending/init.c
index afc9a3ed..565c5c08 100644
--- a/toys/pending/init.c
+++ b/toys/pending/init.c
@@ -93,7 +93,7 @@ static void reset_term(int fd)
tcsetattr(fd, TCSANOW, &terminal);
}
-static void add_new_action(uint8_t action,char *command,char *term)
+static void add_new_action(int action, char *command, char *term)
{
struct action_list_seed *x,**y;
@@ -120,72 +120,66 @@ static void add_new_action(uint8_t action,char *command,char *term)
*y = x;
}
-static void inittab_parsing(void)
+static void parse_inittab(void)
{
- int i, fd, line_number = 0, token_count = 0;
- char *p, *q, *extracted_token, *tty_name = NULL, *command = NULL, *tmp;
- uint8_t action = 0;
+ char *line = 0;
+ size_t allocated_length = 0;
+ int line_number = 0;
char *act_name = "sysinit\0wait\0once\0respawn\0askfirst\0ctrlaltdel\0"
"shutdown\0restart\0";
+ FILE *fp = fopen("/etc/inittab", "r");
- fd = open("/etc/inittab", O_RDONLY);
- if (fd < 0) {
+ if (!fp) {
error_msg("Unable to open /etc/inittab. Using Default inittab");
add_new_action(SYSINIT, "/etc/init.d/rcS", "");
add_new_action(RESPAWN, "/sbin/getty -n -l /bin/sh -L 115200 tty1 vt100", "");
- } else {
- while((q = p = get_line(fd))) { //read single line from /etc/inittab
- char *x;
-
- if ((x = strchr(p, '#'))) *x = '\0';
- line_number++;
- token_count = 0;
- action = 0;
- tty_name = command = NULL;
-
- while ((extracted_token = strsep(&p,":"))) {
- token_count++;
- switch (token_count) {
- case 1:
- if (*extracted_token) {
- if (!strncmp(extracted_token, "/dev/", 5))
- tty_name = xmprintf("%s",extracted_token);
- else tty_name = xmprintf("/dev/%s",extracted_token);
- } else tty_name = xstrdup("");
- break;
- case 2:
- break;
- case 3:
- for (tmp = act_name, i = 0; *tmp; i++, tmp += strlen(tmp) +1) {
- if (!strcmp(tmp, extracted_token)) {
- action = 1 << i;
- break;
- }
- }
- if (!*tmp) error_msg("Invalid action at line number %d ---- ignoring",line_number);
- break;
- case 4:
- command = xstrdup(extracted_token);
- break;
- default:
- error_msg("Bad inittab entry at line %d", line_number);
- break;
- }
- } //while token
+ return;
+ }
- if (q) free(q);
- if (token_count != 4) {
- free(tty_name);
- free(command);
- continue;
+ while (getline(&line, &allocated_length, fp)) {
+ char *p = line, *x, *tty_name = 0, *command = 0, *extracted_token, *tmp;
+ int action = 0, token_count = 0, i;
+
+ if ((x = strchr(p, '#'))) *x = '\0';
+ line_number++;
+ action = 0;
+
+ while ((extracted_token = strsep(&p,":"))) {
+ token_count++;
+ switch (token_count) {
+ case 1:
+ if (*extracted_token) {
+ if (!strncmp(extracted_token, "/dev/", 5))
+ tty_name = xmprintf("%s",extracted_token);
+ else tty_name = xmprintf("/dev/%s",extracted_token);
+ } else tty_name = xstrdup("");
+ break;
+ case 2:
+ break;
+ case 3:
+ for (tmp = act_name, i = 0; *tmp; i++, tmp += strlen(tmp) +1) {
+ if (!strcmp(tmp, extracted_token)) {
+ action = 1 << i;
+ break;
+ }
+ }
+ if (!*tmp) error_msg("Invalid action at line number %d ---- ignoring",line_number);
+ break;
+ case 4:
+ command = xstrdup(extracted_token);
+ break;
+ default:
+ error_msg("Bad inittab entry at line %d", line_number);
+ break;
}
- if (action) add_new_action(action, command, tty_name);
- free(tty_name);
- free(command);
- } //while line
+ } //while token
- close(fd);
+ if (token_count == 4 && action) add_new_action(action, command, tty_name);
+ free(tty_name);
+ free(command);
}
+ free(line);
+ fclose(fp);
}
static void reload_inittab(void)
@@ -204,7 +198,7 @@ static void reload_inittab(void)
}
y = &(*y)->next;
}
- inittab_parsing();
+ parse_inittab();
}
static void run_command(char *command)
@@ -478,7 +472,7 @@ void init_main(void)
putenv("SHELL=/bin/sh");
putenv("USER=root");
- inittab_parsing();
+ parse_inittab();
xsignal(SIGUSR1, halt_poweroff_reboot_handler);//halt
xsignal(SIGUSR2, halt_poweroff_reboot_handler);//poweroff
xsignal(SIGTERM, halt_poweroff_reboot_handler);//reboot
diff --git a/toys/pending/userdel.c b/toys/pending/userdel.c
index 8307c0f3..abf67f43 100644
--- a/toys/pending/userdel.c
+++ b/toys/pending/userdel.c
@@ -27,6 +27,7 @@ static void update_groupfiles(char *filename, char* username)
char *filenamesfx = NULL, *sfx = NULL, *line = NULL;
FILE *exfp, *newfp;
int ulen = strlen(username);
+ size_t allocated_length = 0;
struct flock lock;
filenamesfx = xmprintf("%s+", filename);
@@ -49,10 +50,9 @@ static void update_groupfiles(char *filename, char* username)
newfp = xfopen(filenamesfx, "w+");
- while ((line = get_line(fileno(exfp))) != NULL){
+ while (getline(&line, &allocated_length, exfp)) {
sprintf(toybuf, "%s:",username);
- if (!strncmp(line, toybuf, ulen+1)) goto LOOP;
- else {
+ if (strncmp(line, toybuf, ulen+1)) {
char *n, *p = strrchr(line, ':');
if (p && *++p && (n = strstr(p, username))) {
@@ -72,9 +72,8 @@ static void update_groupfiles(char *filename, char* username)
if (!n) fprintf(newfp, "%s\n", line);
} else fprintf(newfp, "%s\n", line);
}
-LOOP:
- free(line);
}
+ free(line);
fcntl(fileno(exfp), F_SETLK, &lock);
fclose(exfp);
errno = 0;
@@ -91,9 +90,8 @@ LOOP:
void userdel_main(void)
{
- struct passwd *pwd = NULL;
+ struct passwd *pwd = xgetpwnam(*toys.optargs);
- pwd = xgetpwnam(*toys.optargs);
update_password("/etc/passwd", pwd->pw_name, NULL);
update_password("/etc/shadow", pwd->pw_name, NULL);
@@ -106,7 +104,7 @@ void userdel_main(void)
update_groupfiles("/etc/group", *toys.optargs);
update_groupfiles("/etc/gshadow", *toys.optargs);
- if (toys.optflags & FLAG_r) {
+ if (FLAG(r)) {
char *arg[] = {"rm", "-fr", pwd->pw_dir, NULL, NULL};
sprintf(toybuf, "/var/spool/mail/%s",pwd->pw_name);
diff --git a/toys/posix/grep.c b/toys/posix/grep.c
index 8eb3c03a..37e2083d 100644
--- a/toys/posix/grep.c
+++ b/toys/posix/grep.c
@@ -10,7 +10,7 @@
* echo hello | grep -f </dev/null
*
-USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcl(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
+USE_GREP(NEWTOY(grep, "(line-buffered)(color):;(exclude-dir)*S(exclude)*M(include)*ZzEFHIab(byte-offset)h(no-filename)ino(only-matching)rRsvwcL(files-without-match)l(files-with-matches)q(quiet)(silent)e*f*C#B#A#m#x[!wx][!EFw]", TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
USE_EGREP(OLDTOY(egrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
USE_FGREP(OLDTOY(fgrep, grep, TOYFLAG_BIN|TOYFLAG_ARGFAIL(2)|TOYFLAG_LINEBUF))
@@ -44,6 +44,7 @@ config GREP
-x whole line -z input NUL terminated
display modes: (default: matched line)
+ -L show only non-matching filenames
-c count of matching lines -l show only matching filenames
-o only matching part -q quiet (errors only)
-s silent (no error msg) -Z output NUL terminated
@@ -267,8 +268,9 @@ static void do_grep(int fd, char *name)
toys.exitval = 0;
xexit();
}
- if (FLAG(l)) {
- xprintf("%s%c", name, TT.outdelim);
+ if (FLAG(L) || FLAG(l)) {
+ if (FLAG(l))
+ xprintf("%s%c", name, TT.outdelim);
free(line);
fclose(file);
return;
@@ -353,6 +355,11 @@ static void do_grep(int fd, char *name)
if (FLAG(m) && mcount >= TT.m) break;
}
+ if (FLAG(L)) {
+ xprintf("%s%c", name, TT.outdelim);
+ return;
+ }
+
if (FLAG(c)) outline(0, ':', name, mcount, 0, 1);
// loopfiles will also close the fd, but this frees an (opaque) struct.