X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff_plain;f=src%2Fshared%2Fconf-parser.c;h=cfa669b1139bd416bbb4d1aec1c5a5da46e8c5cd;hp=1e3cee5bebc4c21c97f161bda15e8201650fb4a4;hb=46eea341c36f0caf0bdd5b2274a1ef7cb4e83e97;hpb=71a6151083d842b2f5bf04e50239f0bf85d34d2e diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index 1e3cee5be..cfa669b11 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -225,6 +225,15 @@ static int parse_line(const char* unit, if (startswith(l, ".include ")) { _cleanup_free_ char *fn = NULL; + /* .includes are a bad idea, we only support them here + * for historical reasons. They create cyclic include + * problems and make it difficult to detect + * configuration file changes with an easy + * stat(). Better approaches, such as .d/ drop-in + * snippets exist. + * + * Support for them should be eventually removed. */ + if (!allow_include) { log_syntax(unit, LOG_ERR, filename, line, EBADMSG, ".include not allowed here. Ignoring."); @@ -332,6 +341,8 @@ int config_parse(const char *unit, } } + fd_warn_permissions(filename, fileno(f)); + while (!feof(f)) { char l[LINE_MAX], *p, *c = NULL, *e; bool escaped = false; @@ -436,8 +447,7 @@ DEFINE_PARSER(double, double, safe_atod) DEFINE_PARSER(nsec, nsec_t, parse_nsec) DEFINE_PARSER(sec, usec_t, parse_sec) - -int config_parse_bytes_size(const char* unit, +int config_parse_iec_size(const char* unit, const char *filename, unsigned line, const char *section, @@ -457,10 +467,9 @@ int config_parse_bytes_size(const char* unit, assert(rvalue); assert(data); - r = parse_bytes(rvalue, &o); + r = parse_size(rvalue, 1024, &o); if (r < 0 || (off_t) (size_t) o != o) { - log_syntax(unit, LOG_ERR, filename, line, -r, - "Failed to parse byte value, ignoring: %s", rvalue); + log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue); return 0; } @@ -468,8 +477,37 @@ int config_parse_bytes_size(const char* unit, return 0; } +int config_parse_si_size(const char* unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { -int config_parse_bytes_off(const char* unit, + size_t *sz = data; + off_t o; + int r; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + r = parse_size(rvalue, 1000, &o); + if (r < 0 || (off_t) (size_t) o != o) { + log_syntax(unit, LOG_ERR, filename, line, r < 0 ? -r : ERANGE, "Failed to parse size value, ignoring: %s", rvalue); + return 0; + } + + *sz = (size_t) o; + return 0; +} + +int config_parse_iec_off(const char* unit, const char *filename, unsigned line, const char *section, @@ -490,10 +528,9 @@ int config_parse_bytes_off(const char* unit, assert_cc(sizeof(off_t) == sizeof(uint64_t)); - r = parse_bytes(rvalue, bytes); + r = parse_size(rvalue, 1024, bytes); if (r < 0) - log_syntax(unit, LOG_ERR, filename, line, -r, - "Failed to parse bytes value, ignoring: %s", rvalue); + log_syntax(unit, LOG_ERR, filename, line, -r, "Failed to parse size value, ignoring: %s", rvalue); return 0; } @@ -528,6 +565,35 @@ int config_parse_bool(const char* unit, return 0; } +int config_parse_show_status(const char* unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + int k; + ShowStatus *b = data; + + assert(filename); + assert(lvalue); + assert(rvalue); + assert(data); + + k = parse_show_status(rvalue, b); + if (k < 0) { + log_syntax(unit, LOG_ERR, filename, line, -k, + "Failed to parse show status setting, ignoring: %s", rvalue); + return 0; + } + + return 0; +} + int config_parse_string(const char *unit, const char *filename, unsigned line,