conf-parser.c | conf-parser.c | |||
---|---|---|---|---|
skipping to change at line 79 | skipping to change at line 79 | |||
"CONFIG_FILE=%s", config_file, | "CONFIG_FILE=%s", config_file, | |||
"CONFIG_LINE=%u", config_line, | "CONFIG_LINE=%u", config_line, | |||
"ERRNO=%d", error > 0 ? error : EIN VAL, | "ERRNO=%d", error > 0 ? error : EIN VAL, | |||
"MESSAGE=[%s:%u] %s", config_file, config_line, msg, | "MESSAGE=[%s:%u] %s", config_file, config_line, msg, | |||
NULL); | NULL); | |||
return r; | return r; | |||
} | } | |||
int config_item_table_lookup( | int config_item_table_lookup( | |||
void *table, | const void *table, | |||
const char *section, | const char *section, | |||
const char *lvalue, | const char *lvalue, | |||
ConfigParserCallback *func, | ConfigParserCallback *func, | |||
int *ltype, | int *ltype, | |||
void **data, | void **data, | |||
void *userdata) { | void *userdata) { | |||
ConfigTableItem *t; | const ConfigTableItem *t; | |||
assert(table); | assert(table); | |||
assert(lvalue); | assert(lvalue); | |||
assert(func); | assert(func); | |||
assert(ltype); | assert(ltype); | |||
assert(data); | assert(data); | |||
for (t = table; t->lvalue; t++) { | for (t = table; t->lvalue; t++) { | |||
if (!streq(lvalue, t->lvalue)) | if (!streq(lvalue, t->lvalue)) | |||
skipping to change at line 113 | skipping to change at line 113 | |||
*func = t->parse; | *func = t->parse; | |||
*ltype = t->ltype; | *ltype = t->ltype; | |||
*data = t->data; | *data = t->data; | |||
return 1; | return 1; | |||
} | } | |||
return 0; | return 0; | |||
} | } | |||
int config_item_perf_lookup( | int config_item_perf_lookup( | |||
void *table, | const void *table, | |||
const char *section, | const char *section, | |||
const char *lvalue, | const char *lvalue, | |||
ConfigParserCallback *func, | ConfigParserCallback *func, | |||
int *ltype, | int *ltype, | |||
void **data, | void **data, | |||
void *userdata) { | void *userdata) { | |||
ConfigPerfItemLookup lookup = (ConfigPerfItemLookup) table; | ConfigPerfItemLookup lookup = (ConfigPerfItemLookup) table; | |||
const ConfigPerfItem *p; | const ConfigPerfItem *p; | |||
skipping to change at line 157 | skipping to change at line 157 | |||
*ltype = p->ltype; | *ltype = p->ltype; | |||
*data = (uint8_t*) userdata + p->offset; | *data = (uint8_t*) userdata + p->offset; | |||
return 1; | return 1; | |||
} | } | |||
/* Run the user supplied parser for an assignment */ | /* Run the user supplied parser for an assignment */ | |||
static int next_assignment(const char *unit, | static int next_assignment(const char *unit, | |||
const char *filename, | const char *filename, | |||
unsigned line, | unsigned line, | |||
ConfigItemLookup lookup, | ConfigItemLookup lookup, | |||
void *table, | const void *table, | |||
const char *section, | const char *section, | |||
unsigned section_line, | unsigned section_line, | |||
const char *lvalue, | const char *lvalue, | |||
const char *rvalue, | const char *rvalue, | |||
bool relaxed, | bool relaxed, | |||
void *userdata) { | void *userdata) { | |||
ConfigParserCallback func = NULL; | ConfigParserCallback func = NULL; | |||
int ltype = 0; | int ltype = 0; | |||
void *data = NULL; | void *data = NULL; | |||
skipping to change at line 202 | skipping to change at line 202 | |||
return 0; | return 0; | |||
} | } | |||
/* Parse a variable assignment line */ | /* Parse a variable assignment line */ | |||
static int parse_line(const char* unit, | static int parse_line(const char* unit, | |||
const char *filename, | const char *filename, | |||
unsigned line, | unsigned line, | |||
const char *sections, | const char *sections, | |||
ConfigItemLookup lookup, | ConfigItemLookup lookup, | |||
void *table, | const void *table, | |||
bool relaxed, | bool relaxed, | |||
bool allow_include, | bool allow_include, | |||
char **section, | char **section, | |||
unsigned *section_line, | unsigned *section_line, | |||
bool *section_ignored, | bool *section_ignored, | |||
char *l, | char *l, | |||
void *userdata) { | void *userdata) { | |||
char *e; | char *e; | |||
skipping to change at line 248 | skipping to change at line 248 | |||
if (!allow_include) { | if (!allow_include) { | |||
log_syntax(unit, LOG_ERR, filename, line, EBADMSG, | log_syntax(unit, LOG_ERR, filename, line, EBADMSG, | |||
".include not allowed here. Ignoring."); | ".include not allowed here. Ignoring."); | |||
return 0; | return 0; | |||
} | } | |||
fn = file_in_same_dir(filename, strstrip(l+9)); | fn = file_in_same_dir(filename, strstrip(l+9)); | |||
if (!fn) | if (!fn) | |||
return -ENOMEM; | return -ENOMEM; | |||
return config_parse(unit, fn, NULL, sections, lookup, table , relaxed, false, userdata); | return config_parse(unit, fn, NULL, sections, lookup, table , relaxed, false, false, userdata); | |||
} | } | |||
if (*l == '[') { | if (*l == '[') { | |||
size_t k; | size_t k; | |||
char *n; | char *n; | |||
k = strlen(l); | k = strlen(l); | |||
assert(k > 0); | assert(k > 0); | |||
if (l[k-1] != ']') { | if (l[k-1] != ']') { | |||
skipping to change at line 326 | skipping to change at line 326 | |||
relaxed, | relaxed, | |||
userdata); | userdata); | |||
} | } | |||
/* Go through the file and parse each line */ | /* Go through the file and parse each line */ | |||
int config_parse(const char *unit, | int config_parse(const char *unit, | |||
const char *filename, | const char *filename, | |||
FILE *f, | FILE *f, | |||
const char *sections, | const char *sections, | |||
ConfigItemLookup lookup, | ConfigItemLookup lookup, | |||
void *table, | const void *table, | |||
bool relaxed, | bool relaxed, | |||
bool allow_include, | bool allow_include, | |||
bool warn, | ||||
void *userdata) { | void *userdata) { | |||
_cleanup_free_ char *section = NULL, *continuation = NULL; | _cleanup_free_ char *section = NULL, *continuation = NULL; | |||
_cleanup_fclose_ FILE *ours = NULL; | _cleanup_fclose_ FILE *ours = NULL; | |||
unsigned line = 0, section_line = 0; | unsigned line = 0, section_line = 0; | |||
bool section_ignored = false; | bool section_ignored = false; | |||
int r; | int r; | |||
assert(filename); | assert(filename); | |||
assert(lookup); | assert(lookup); | |||
if (!f) { | if (!f) { | |||
f = ours = fopen(filename, "re"); | f = ours = fopen(filename, "re"); | |||
if (!f) { | if (!f) { | |||
log_full(errno == ENOENT ? LOG_DEBUG : LOG_ERR, "Fa | /* Only log on request, except for ENOENT, | |||
iled to open configuration file '%s': %m", filename); | * since we return 0 to the caller. */ | |||
if (warn || errno == ENOENT) | ||||
log_full(errno == ENOENT ? LOG_DEBUG : LOG_ | ||||
ERR, | ||||
"Failed to open configuration file | ||||
'%s': %m", filename); | ||||
return errno == ENOENT ? 0 : -errno; | return errno == ENOENT ? 0 : -errno; | |||
} | } | |||
} | } | |||
fd_warn_permissions(filename, fileno(f)); | fd_warn_permissions(filename, fileno(f)); | |||
while (!feof(f)) { | while (!feof(f)) { | |||
char l[LINE_MAX], *p, *c = NULL, *e; | char l[LINE_MAX], *p, *c = NULL, *e; | |||
bool escaped = false; | bool escaped = false; | |||
skipping to change at line 366 | skipping to change at line 371 | |||
break; | break; | |||
log_error("Failed to read configuration file '%s': %m", filename); | log_error("Failed to read configuration file '%s': %m", filename); | |||
return -errno; | return -errno; | |||
} | } | |||
truncate_nl(l); | truncate_nl(l); | |||
if (continuation) { | if (continuation) { | |||
c = strappend(continuation, l); | c = strappend(continuation, l); | |||
if (!c) | if (!c) { | |||
if (warn) | ||||
log_oom(); | ||||
return -ENOMEM; | return -ENOMEM; | |||
} | ||||
free(continuation); | free(continuation); | |||
continuation = NULL; | continuation = NULL; | |||
p = c; | p = c; | |||
} else | } else | |||
p = l; | p = l; | |||
for (e = p; *e; e++) { | for (e = p; *e; e++) { | |||
if (escaped) | if (escaped) | |||
escaped = false; | escaped = false; | |||
skipping to change at line 389 | skipping to change at line 397 | |||
escaped = true; | escaped = true; | |||
} | } | |||
if (escaped) { | if (escaped) { | |||
*(e-1) = ' '; | *(e-1) = ' '; | |||
if (c) | if (c) | |||
continuation = c; | continuation = c; | |||
else { | else { | |||
continuation = strdup(l); | continuation = strdup(l); | |||
if (!continuation) | if (!continuation) { | |||
if (warn) | ||||
log_oom(); | ||||
return -ENOMEM; | return -ENOMEM; | |||
} | ||||
} | } | |||
continue; | continue; | |||
} | } | |||
r = parse_line(unit, | r = parse_line(unit, | |||
filename, | filename, | |||
++line, | ++line, | |||
sections, | sections, | |||
lookup, | lookup, | |||
table, | table, | |||
relaxed, | relaxed, | |||
allow_include, | allow_include, | |||
§ion, | §ion, | |||
§ion_line, | §ion_line, | |||
§ion_ignored, | §ion_ignored, | |||
p, | p, | |||
userdata); | userdata); | |||
free(c); | free(c); | |||
if (r < 0) | if (r < 0) { | |||
if (warn) | ||||
log_warning("Failed to parse file '%s': %s" | ||||
, | ||||
filename, strerror(-r)); | ||||
return r; | return r; | |||
} | ||||
} | } | |||
return 0; | return 0; | |||
} | } | |||
#define DEFINE_PARSER(type, vartype, conv_func) \ | #define DEFINE_PARSER(type, vartype, conv_func) \ | |||
int config_parse_##type(const char *unit, \ | int config_parse_##type(const char *unit, \ | |||
const char *filename, \ | const char *filename, \ | |||
unsigned line, \ | unsigned line, \ | |||
const char *section, \ | const char *section, \ | |||
skipping to change at line 663 | skipping to change at line 678 | |||
const char *filename, | const char *filename, | |||
unsigned line, | unsigned line, | |||
const char *section, | const char *section, | |||
unsigned section_line, | unsigned section_line, | |||
const char *lvalue, | const char *lvalue, | |||
int ltype, | int ltype, | |||
const char *rvalue, | const char *rvalue, | |||
void *data, | void *data, | |||
void *userdata) { | void *userdata) { | |||
char *** sv = data, *w, *state; | char ***sv = data; | |||
const char *word, *state; | ||||
size_t l; | size_t l; | |||
int r; | int r; | |||
assert(filename); | assert(filename); | |||
assert(lvalue); | assert(lvalue); | |||
assert(rvalue); | assert(rvalue); | |||
assert(data); | assert(data); | |||
if (isempty(rvalue)) { | if (isempty(rvalue)) { | |||
char **empty; | char **empty; | |||
skipping to change at line 688 | skipping to change at line 704 | |||
* something was set at all... */ | * something was set at all... */ | |||
empty = strv_new(NULL, NULL); | empty = strv_new(NULL, NULL); | |||
if (!empty) | if (!empty) | |||
return log_oom(); | return log_oom(); | |||
strv_free(*sv); | strv_free(*sv); | |||
*sv = empty; | *sv = empty; | |||
return 0; | return 0; | |||
} | } | |||
FOREACH_WORD_QUOTED(w, l, rvalue, state) { | FOREACH_WORD_QUOTED(word, l, rvalue, state) { | |||
char *n; | char *n; | |||
n = strndup(w, l); | n = strndup(word, l); | |||
if (!n) | if (!n) | |||
return log_oom(); | return log_oom(); | |||
if (!utf8_is_valid(n)) { | if (!utf8_is_valid(n)) { | |||
log_invalid_utf8(unit, LOG_ERR, filename, line, EIN VAL, rvalue); | log_invalid_utf8(unit, LOG_ERR, filename, line, EIN VAL, rvalue); | |||
continue; | continue; | |||
} | } | |||
r = strv_consume(sv, n); | r = strv_consume(sv, n); | |||
if (r < 0) | if (r < 0) | |||
return log_oom(); | return log_oom(); | |||
} | } | |||
if (!isempty(state)) | ||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL, | ||||
"Trailing garbage, ignoring."); | ||||
return 0; | return 0; | |||
} | } | |||
int config_parse_mode(const char *unit, | int config_parse_mode(const char *unit, | |||
const char *filename, | const char *filename, | |||
unsigned line, | unsigned line, | |||
const char *section, | const char *section, | |||
unsigned section_line, | unsigned section_line, | |||
const char *lvalue, | const char *lvalue, | |||
End of changes. 19 change blocks. | ||||
15 lines changed or deleted | 36 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |