diff options
author | Elliott Hughes <enh@google.com> | 2018-02-26 20:14:11 +0000 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-02-26 20:14:11 +0000 |
commit | 12285d088a3e672a5f3964952dac3b443f67574c (patch) | |
tree | 452224022749fc74d1f339b0e5b39d62260bd429 | |
parent | a62c5f6d669cf2d15f54ce58fa4ca025613632e4 (diff) | |
parent | 7f401dbddef921116ddb9c8a7860965af864af80 (diff) | |
download | toybox-pie-qpr3-b-release.tar.gz |
Merge remote-tracking branch 'toybox/master' into HEAD am: 14cafec540 am: 4d29f725c0android-9.0.0_r47android-9.0.0_r46android-9.0.0_r45android-9.0.0_r44android-9.0.0_r43android-9.0.0_r42android-9.0.0_r41android-9.0.0_r40android-9.0.0_r39android-9.0.0_r38android-9.0.0_r37android-9.0.0_r36android-9.0.0_r35android-9.0.0_r34android-9.0.0_r33android-9.0.0_r32android-9.0.0_r31android-9.0.0_r30android-9.0.0_r22android-9.0.0_r21android-9.0.0_r20android-9.0.0_r19android-9.0.0_r16android-9.0.0_r12android-9.0.0_r11pie-qpr3-s1-releasepie-qpr3-releasepie-qpr3-b-releasepie-qpr2-releasepie-qpr1-s3-releasepie-qpr1-s2-releasepie-qpr1-s1-releasepie-qpr1-releasepie-dr1-releasepie-dr1-devpie-devpie-b4s4-releasepie-b4s4-dev
am: 7f401dbdde
Change-Id: I7ba3d69a58986c71eaf798e7404c634c51a7352c
-rw-r--r-- | generated/help.h | 2 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | toys/example/hello.c | 5 | ||||
-rw-r--r-- | toys/example/skeleton.c | 1 | ||||
-rw-r--r-- | toys/posix/logger.c | 48 |
5 files changed, 43 insertions, 15 deletions
diff --git a/generated/help.h b/generated/help.h index d38c4d21..d005dc3b 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" @@ -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 3b7d27b6..4cd5d13a 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 ee67b58f..666e804a 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 16262c9f..47562999 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); |