aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-02-26 18:29:02 (GMT)
committerElliott Hughes <enh@google.com>2018-02-26 18:30:34 (GMT)
commit14cafec54042565de03bdad44441b3c57b7f524e (patch)
tree452224022749fc74d1f339b0e5b39d62260bd429
parent9d0d75578356c472489769dbdf55eee50119ff81 (diff)
parentc0ad4545137107503d64c7ed1d9bc685ec2f8e9c (diff)
downloadandroid_external_toybox-14cafec54042565de03bdad44441b3c57b7f524e.zip
android_external_toybox-14cafec54042565de03bdad44441b3c57b7f524e.tar.gz
android_external_toybox-14cafec54042565de03bdad44441b3c57b7f524e.tar.bz2
Merge remote-tracking branch 'toybox/master' into HEAD
Change-Id: Ifc6e2ca6cd1939f4d270a5adae1f68c899e2075f
-rw-r--r--generated/help.h2
-rw-r--r--main.c2
-rw-r--r--toys/example/hello.c5
-rw-r--r--toys/example/skeleton.c1
-rw-r--r--toys/posix/logger.c48
5 files changed, 43 insertions, 15 deletions
diff --git a/generated/help.h b/generated/help.h
index d38c4d2..d005dc3 100644
--- a/generated/help.h
+++ b/generated/help.h
@@ -62,7 +62,7 @@
#define HELP_hostid "usage: hostid\n\nPrint the numeric identifier for the current host.\n\n"
-#define HELP_hello "usage: hello [-s]\n\nA hello world program. You don't need this.\n\nMostly used as a simple template for adding new commands.\nOccasionally nice to smoketest kernel booting via \"init=/usr/bin/hello\".\n\n"
+#define HELP_hello "usage: hello\n\nA hello world program.\n\nMostly used as a simple template for adding new commands.\nOccasionally nice to smoketest kernel booting via \"init=/usr/bin/hello\".\n\n"
#define HELP_test_utf8towc "usage: test_utf8towc\n\nPrint differences between toybox's utf8 conversion routines vs libc du jour.\n\n"
diff --git a/main.c b/main.c
index 0b77b50..4eeb193 100644
--- a/main.c
+++ b/main.c
@@ -9,7 +9,7 @@
#ifndef TOYBOX_VENDOR
#define TOYBOX_VENDOR ""
#endif
-#define TOYBOX_VERSION "0.7.5"TOYBOX_VENDOR
+#define TOYBOX_VERSION "0.7.6"TOYBOX_VENDOR
#endif
// Populate toy_list[].
diff --git a/toys/example/hello.c b/toys/example/hello.c
index 3b7d27b..4cd5d13 100644
--- a/toys/example/hello.c
+++ b/toys/example/hello.c
@@ -4,6 +4,7 @@
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
* See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
+ * See https://www.ietf.org/rfc/rfc3.txt
USE_HELLO(NEWTOY(hello, 0, TOYFLAG_USR|TOYFLAG_BIN))
@@ -11,9 +12,9 @@ config HELLO
bool "hello"
default n
help
- usage: hello [-s]
+ usage: hello
- A hello world program. You don't need this.
+ A hello world program.
Mostly used as a simple template for adding new commands.
Occasionally nice to smoketest kernel booting via "init=/usr/bin/hello".
diff --git a/toys/example/skeleton.c b/toys/example/skeleton.c
index ee67b58..666e804 100644
--- a/toys/example/skeleton.c
+++ b/toys/example/skeleton.c
@@ -5,6 +5,7 @@
*
* See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/
* See http://refspecs.linuxfoundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/cmdbehav.html
+ * See https://www.ietf.org/rfc/rfc3.txt
// Accept many different kinds of command line argument (see top of lib/args.c)
// Demonstrate two commands in the same file (see www/documentation.html)
diff --git a/toys/posix/logger.c b/toys/posix/logger.c
index 16262c9..4756299 100644
--- a/toys/posix/logger.c
+++ b/toys/posix/logger.c
@@ -29,29 +29,55 @@ GLOBALS(
char *ident;
)
+// find str in names[], accepting unambiguous short matches
+// returns offset into array of match, or -1 if no match
+int arrayfind(char *str, char *names[], int len)
+{
+ int try, i, matchlen = 0, found = -1, ambiguous = 1;
+
+ for (try = 0; try<len; try++) {
+ for (i=0; ; i++) {
+ if (!str[i]) {
+ if (matchlen<i) found = try, ambiguous = 0;
+ if (matchlen==i) ambiguous++;
+ if (!names[try][i]) return try;
+ break;
+ }
+ if (!names[try][i]) break;
+ if (toupper(str[i]) != toupper(names[try][i])) break;
+ }
+ }
+ return ambiguous ? -1 : found;
+}
+
void logger_main(void)
{
int facility = LOG_USER, priority = LOG_NOTICE, len;
- char *s1, *s2, **arg;
- CODE *code;
+ char *s1, *s2, **arg,
+ *priorities[] = {"emerg", "alert", "crit", "error", "warning", "notice",
+ "info", "debug"},
+ *facilities[] = {"kern", "user", "mail", "daemon", "auth", "syslog",
+ "lpr", "news", "uucp", "cron", "authpriv", "ftp"};
if (!TT.ident) TT.ident = xstrdup(xgetpwuid(geteuid())->pw_name);
if (toys.optflags & FLAG_p) {
if (!(s1 = strchr(TT.priority, '.'))) s1 = TT.priority;
else {
- *s1++ = 0;
- for (code = facilitynames; code->c_name; code++)
- if (!strcasecmp(TT.priority, code->c_name)) break;
- if (!code->c_name) error_exit("bad facility: %s", TT.priority);
- facility = code->c_val;
+ *s1++ = len = 0;
+ facility = arrayfind(TT.priority, facilities, ARRAY_LEN(facilities));
+ if (facility == -1 && strncasecmp(TT.priority, "local", 5)) {
+ facility = s1[5]-'0';
+ if (facility>7 || s1[6]) facility = -1;
+ if (facility>=0) facility += 16;
+ }
+ if (facility<0) error_exit("bad facility: %s", TT.priority);
+ facility *= 8;
}
- for (code = prioritynames; code->c_name; code++)
- if (!strcasecmp(s1, code->c_name)) break;
- if (!code->c_name) error_exit("bad priority: %s", s1);
+ priority = arrayfind(s1, priorities, ARRAY_LEN(priorities));
+ if (priority<0) error_exit("bad priority: %s", s1);
}
-
if (toys.optc) {
for (len = 0, arg = toys.optargs; *arg; arg++) len += strlen(*arg)+1;
s1 = s2 = xmalloc(len);