aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2018-02-26 20:14:11 +0000
committerandroid-build-merger <android-build-merger@google.com>2018-02-26 20:14:11 +0000
commit12285d088a3e672a5f3964952dac3b443f67574c (patch)
tree452224022749fc74d1f339b0e5b39d62260bd429
parenta62c5f6d669cf2d15f54ce58fa4ca025613632e4 (diff)
parent7f401dbddef921116ddb9c8a7860965af864af80 (diff)
downloadtoybox-pie-qpr3-b-release.tar.gz
am: 7f401dbdde Change-Id: I7ba3d69a58986c71eaf798e7404c634c51a7352c
-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 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"
diff --git a/main.c b/main.c
index 0b77b508..4eeb193f 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 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);