Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

external-toybox: Commit

external/toybox


Commit MetaInfo

Revision66f12b756a5431fe364c6817ec64e4e373bdc55a (tree)
Time2018-02-19 10:35:10
AuthorRob Landley <rob@land...>
CommiterRob Landley

Log Message

Work around a musl-libc bug that has facilitynames/prioritynames in headers
but then the link fails.

Change Summary

Incremental Difference

--- a/toys/posix/logger.c
+++ b/toys/posix/logger.c
@@ -29,29 +29,54 @@ GLOBALS(
2929 char *ident;
3030 )
3131
32+// find str in names[], accepting unambiguous short matches
33+// returns offset into array of match, or -1 if no match
34+int arrayfind(char *str, char *names[], int len)
35+{
36+ int try, i, matchlen = 0, found = -1, ambiguous = 1;
37+
38+ for (try = 0; try<len; try++) {
39+ for (i=0; ; i++) {
40+ if (!str[i]) {
41+ if (matchlen<i) found = try, ambiguous = 0;
42+ if (matchlen==i) ambiguous++;
43+ if (!names[try][i]) return try;
44+ break;
45+ }
46+ if (!names[try][i]) break;
47+ if (toupper(str[i]) != toupper(names[try][i])) break;
48+ }
49+ }
50+ return ambiguous ? -1 : found;
51+}
52+
3253 void logger_main(void)
3354 {
3455 int facility = LOG_USER, priority = LOG_NOTICE, len;
35- char *s1, *s2, **arg;
36- CODE *code;
56+ char *s1, *s2, **arg,
57+ *priorities[] = {"emerg", "alert", "crit", "error", "warning", "notice",
58+ "info", "debug"},
59+ *facilities[] = {"kern", "user", "mail", "daemon", "auth", "syslog",
60+ "lpr", "news", "uucp", "cron", "authpriv", "ftp"};
3761
3862 if (!TT.ident) TT.ident = xstrdup(xgetpwuid(geteuid())->pw_name);
3963 if (toys.optflags & FLAG_p) {
4064 if (!(s1 = strchr(TT.priority, '.'))) s1 = TT.priority;
4165 else {
42- *s1++ = 0;
43- for (code = facilitynames; code->c_name; code++)
44- if (!strcasecmp(TT.priority, code->c_name)) break;
45- if (!code->c_name) error_exit("bad facility: %s", TT.priority);
46- facility = code->c_val;
66+ *s1++ = len = 0;
67+ facility = arrayfind(TT.priority, facilities, ARRAY_LEN(facilities));
68+ if (facility == -1 && strncasecmp(TT.priority, "local", 5)) {
69+ facility = s1[5]-'0';
70+ if (facility>7 || s1[6]) facility = -1;
71+ if (facility>=0) facility += 16;
72+ }
73+ if (facility<0) error_exit("bad facility: %s", TT.priority);
4774 }
4875
49- for (code = prioritynames; code->c_name; code++)
50- if (!strcasecmp(s1, code->c_name)) break;
51- if (!code->c_name) error_exit("bad priority: %s", s1);
76+ priority = arrayfind(s1, priorities, ARRAY_LEN(priorities));
77+ if (priority<0) error_exit("bad priority: %s", s1);
5278 }
5379
54-
5580 if (toys.optc) {
5681 for (len = 0, arg = toys.optargs; *arg; arg++) len += strlen(*arg)+1;
5782 s1 = s2 = xmalloc(len);
Show on old repository browser