X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fshared%2Fconf-parser.c;h=fbacf986a515b3e30ceeb0a1c5fe1c958733d283;hb=245802dd89ccf10de446faff5577e041d5372062;hp=b09e90ae8bd40c672c338b1073f09fa34d6f6819;hpb=f7900e258dfb8ab55f333d02d96f908ca0ea8899;p=elogind.git diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index b09e90ae8..fbacf986a 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -262,23 +262,19 @@ int config_parse( void *userdata) { unsigned line = 0; - char *section = NULL; + char _cleanup_free_ *section = NULL, *continuation = NULL; + FILE _cleanup_fclose_ *ours = NULL; int r; - bool ours = false; - char *continuation = NULL; assert(filename); assert(lookup); if (!f) { - f = fopen(filename, "re"); + f = ours = fopen(filename, "re"); if (!f) { - r = -errno; - log_error("Failed to open configuration file '%s': %s", filename, strerror(-r)); - goto finish; + log_error("Failed to open configuration file '%s': %m", filename); + return -errno; } - - ours = true; } while (!feof(f)) { @@ -289,19 +285,16 @@ int config_parse( if (feof(f)) break; - r = -errno; - log_error("Failed to read configuration file '%s': %s", filename, strerror(-r)); - goto finish; + log_error("Failed to read configuration file '%s': %m", filename); + return -errno; } truncate_nl(l); if (continuation) { c = strappend(continuation, l); - if (!c) { - r = -ENOMEM; - goto finish; - } + if (!c) + return -ENOMEM; free(continuation); continuation = NULL; @@ -323,10 +316,8 @@ int config_parse( continuation = c; else { continuation = strdup(l); - if (!continuation) { - r = -ENOMEM; - goto finish; - } + if (!continuation) + return -ENOMEM; } continue; @@ -344,19 +335,10 @@ int config_parse( free(c); if (r < 0) - goto finish; + return r; } - r = 0; - -finish: - free(section); - free(continuation); - - if (f && ours) - fclose(f); - - return r; + return 0; } int config_parse_int( @@ -705,9 +687,18 @@ int config_parse_strv( assert(data); if (isempty(rvalue)) { - /* Empty assignment resets the list */ + char **empty; + + /* Empty assignment resets the list. As a special rule + * we actually fill in a real empty array here rather + * than NULL, since some code wants to know if + * something was set at all... */ + empty = strv_new(NULL, NULL); + if (!empty) + return log_oom(); + strv_free(*sv); - *sv = NULL; + *sv = empty; return 0; } @@ -783,7 +774,7 @@ int config_parse_path_strv( return 0; } -int config_parse_usec( +int config_parse_sec( const char *filename, unsigned line, const char *section, @@ -800,7 +791,7 @@ int config_parse_usec( assert(rvalue); assert(data); - if (parse_usec(rvalue, usec) < 0) { + if (parse_sec(rvalue, usec) < 0) { log_error("[%s:%u] Failed to parse time value, ignoring: %s", filename, line, rvalue); return 0; }