X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fconf-parser.c;h=7f286096d234c591860d30aebf83826239b11bc0;hb=74051b9b5865586bf4d30b9075649af838fb92bd;hp=a9b01135e6a1dfc7a3bcbd335b6d59c1a21cb7be;hpb=d7832d2c6e0ef5f2839a2296c1cc2fc85c7d9632;p=elogind.git diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index a9b01135e..7f286096d 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -6,16 +6,16 @@ Copyright 2010 Lennart Poettering systemd is free software; you can redistribute it and/or modify it - under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. systemd is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - General Public License for more details. + Lesser General Public License for more details. - You should have received a copy of the GNU General Public License + You should have received a copy of the GNU Lesser General Public License along with systemd; If not, see . ***/ @@ -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; @@ -374,7 +377,8 @@ int config_parse_int( assert(rvalue); assert(data); - if ((r = safe_atoi(rvalue, i)) < 0) { + r = safe_atoi(rvalue, i); + if (r < 0) { log_error("[%s:%u] Failed to parse numeric value, ingoring: %s", filename, line, rvalue); return 0; } @@ -400,7 +404,8 @@ int config_parse_long( assert(rvalue); assert(data); - if ((r = safe_atoli(rvalue, i)) < 0) { + r = safe_atoli(rvalue, i); + if (r < 0) { log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue); return 0; } @@ -426,7 +431,8 @@ int config_parse_uint64( assert(rvalue); assert(data); - if ((r = safe_atou64(rvalue, u)) < 0) { + r = safe_atou64(rvalue, u); + if (r < 0) { log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue); return 0; } @@ -452,7 +458,8 @@ int config_parse_unsigned( assert(rvalue); assert(data); - if ((r = safe_atou(rvalue, u)) < 0) { + r = safe_atou(rvalue, u); + if (r < 0) { log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue); return r; } @@ -590,9 +597,9 @@ int config_parse_string( assert(rvalue); assert(data); - n = cunescape(rvalue); + n = strdup(rvalue); if (!n) - return -ENOMEM; + return log_oom(); if (!utf8_is_valid(n)) { log_error("[%s:%u] String is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue); @@ -641,7 +648,7 @@ int config_parse_path( n = strdup(rvalue); if (!n) - return -ENOMEM; + return log_oom(); path_kill_slashes(n); @@ -674,13 +681,19 @@ int config_parse_strv( assert(rvalue); assert(data); + if (isempty(rvalue)) { + /* Empty assignment resets the list */ + strv_free(*sv); + *sv = NULL; + } + k = strv_length(*sv); FOREACH_WORD_QUOTED(w, l, rvalue, state) k++; n = new(char*, k+1); if (!n) - return -ENOMEM; + return log_oom(); if (*sv) for (k = 0; (*sv)[k]; k++) @@ -691,7 +704,7 @@ int config_parse_strv( FOREACH_WORD_QUOTED(w, l, rvalue, state) { n[k] = cunescape_length(w, l); if (!n[k]) { - r = -ENOMEM; + r = log_oom(); goto fail; } @@ -741,13 +754,19 @@ int config_parse_path_strv( assert(rvalue); assert(data); + if (isempty(rvalue)) { + /* Empty assignment resets the list */ + strv_free(*sv); + *sv = NULL; + } + k = strv_length(*sv); FOREACH_WORD_QUOTED(w, l, rvalue, state) k++; n = new(char*, k+1); if (!n) - return -ENOMEM; + return log_oom(); k = 0; if (*sv) @@ -757,7 +776,7 @@ int config_parse_path_strv( FOREACH_WORD_QUOTED(w, l, rvalue, state) { n[k] = strndup(w, l); if (!n[k]) { - r = -ENOMEM; + r = log_oom(); goto fail; } @@ -816,6 +835,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, @@ -837,7 +881,7 @@ int config_parse_mode( errno = 0; l = strtol(rvalue, &x, 8); - if (!x || *x || errno) { + if (!x || x == rvalue || *x || errno) { log_error("[%s:%u] Failed to parse mode value, ignoring: %s", filename, line, rvalue); return 0; } @@ -850,3 +894,140 @@ 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); + + if (isempty(rvalue)) { + /* Empty assignment resets the list */ + + set_free(status_set->signal); + set_free(status_set->code); + + status_set->signal = status_set->code = NULL; + return 0; + } + + 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; +}