X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fconf-parser.c;h=68ab80470e5348ae0d7c0cc160edb74f136324d0;hb=b5b46d599524341ddd7407e5dff1021af8ff5089;hp=30980a3ea228d0d213c6e7ae7464ec5655e7d940;hpb=5430f7f2bc7330f3088b894166bf3524a067e3d8;p=elogind.git diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 30980a3ea..68ab80470 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -31,6 +31,9 @@ #include "strv.h" #include "log.h" #include "utf8.h" +#include "path-util.h" +#include "set.h" +#include "exit-status.h" int config_item_table_lookup( void *table, @@ -89,7 +92,7 @@ int config_item_perf_lookup( else { char *key; - key = join(section, ".", lvalue, NULL); + key = strjoin(section, ".", lvalue, NULL); if (!key) return -ENOMEM; @@ -816,6 +819,31 @@ int config_parse_usec( return 0; } +int config_parse_nsec( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + nsec_t *nsec = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + if (parse_nsec(rvalue, nsec) < 0) { + log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue); + return 0; + } + + return 0; +} + int config_parse_mode( const char *filename, unsigned line, @@ -850,3 +878,130 @@ int config_parse_mode( *m = (mode_t) l; return 0; } + +int config_parse_facility( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + + int *o = data, x; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + x = log_facility_unshifted_from_string(rvalue); + if (x < 0) { + log_error("[%s:%u] Failed to parse log facility, ignoring: %s", filename, line, rvalue); + return 0; + } + + *o = (x << 3) | LOG_PRI(*o); + + return 0; +} + +int config_parse_level( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + + int *o = data, x; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + x = log_level_from_string(rvalue); + if (x < 0) { + log_error("[%s:%u] Failed to parse log level, ignoring: %s", filename, line, rvalue); + return 0; + } + + *o = (*o & LOG_FACMASK) | x; + return 0; +} + +int config_parse_set_status( + const char *filename, + unsigned line, + const char *section, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + char *w; + size_t l; + char *state; + int r; + ExitStatusSet *status_set = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + FOREACH_WORD(w, l, rvalue, state) { + int val; + char *temp; + + temp = strndup(w, l); + if (!temp) + return log_oom(); + + r = safe_atoi(temp, &val); + if (r < 0) { + val = signal_from_string_try_harder(temp); + free(temp); + + if (val > 0) { + r = set_ensure_allocated(&status_set->signal, trivial_hash_func, trivial_compare_func); + if (r < 0) + return log_oom(); + + r = set_put(status_set->signal, INT_TO_PTR(val)); + if (r < 0) { + log_error("[%s:%u] Unable to store: %s", filename, line, w); + return r; + } + } else { + log_error("[%s:%u] Failed to parse value, ignoring: %s", filename, line, w); + return 0; + } + } else { + free(temp); + + if (val < 0 || val > 255) + log_warning("[%s:%u] Value %d is outside range 0-255, ignoring", filename, line, val); + else { + r = set_ensure_allocated(&status_set->code, trivial_hash_func, trivial_compare_func); + if (r < 0) + return log_oom(); + + r = set_put(status_set->code, INT_TO_PTR(val)); + if (r < 0) { + log_error("[%s:%u] Unable to store: %s", filename, line, w); + return r; + } + } + } + } + + return 0; +}