conf-parser.c revision d7832d2c6e0ef5f2839a2296c1cc2fc85c7d9632
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering This file is part of systemd.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering Copyright 2010 Lennart Poettering
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering systemd is free software; you can redistribute it and/or modify it
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering under the terms of the GNU General Public License as published by
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering the Free Software Foundation; either version 2 of the License, or
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering (at your option) any later version.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering systemd is distributed in the hope that it will be useful, but
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering General Public License for more details.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering You should have received a copy of the GNU General Public License
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering ConfigPerfItemLookup lookup = (ConfigPerfItemLookup) table;
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering/* Run the user supplied parser for an assignment */
83f6936a018b08880670838756e0f4e9ea98b4a7Lennart Poettering r = lookup(table, section, lvalue, &func, <ype, &data, userdata);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering return func(filename, line, section, lvalue, ltype, rvalue, data, userdata);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering /* Warn about unknown non-extension fields. */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (!relaxed && !startswith(lvalue, "X-"))
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek log_info("[%s:%u] Unknown lvalue '%s' in section '%s'. Ignoring.", filename, line, lvalue, section);
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek/* Parse a variable assignment line */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering fn = file_in_same_dir(filename, strstrip(l+9));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering r = config_parse(fn, NULL, sections, lookup, table, relaxed, userdata);
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek if (*l == '[') {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Invalid section header.", filename, line);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (sections && !nulstr_contains(sections, n)) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_info("[%s:%u] Unknown section '%s'. Ignoring.", filename, line, n);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_info("[%s:%u] Assignment outside of section. Ignoring.", filename, line);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Missing '='.", filename, line);
c7332b0844e28d9b70c3c763b929f105c1056fe8Zbigniew Jędrzejewski-Szmek/* Go through the file and parse each line */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("Failed to open configuration file '%s': %s", filename, strerror(-r));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (!fgets(l, sizeof(l), f)) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("Failed to read configuration file '%s': %s", filename, strerror(-r));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering for (e = p; *e; e++) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering else if (*e == '\\')
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek if ((r = safe_atoi(rvalue, i)) < 0) {
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek log_error("[%s:%u] Failed to parse numeric value, ingoring: %s", filename, line, rvalue);
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek if ((r = safe_atoli(rvalue, i)) < 0) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse numeric value, ignoring: %s", filename, line, rvalue);
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek if ((r = safe_atou(rvalue, u)) < 0) {
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek log_error("[%s:%u] Failed to parse numeric value: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering if (parse_bytes(rvalue, &o) < 0 || (off_t) (size_t) o != o) {
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse byte value, ignoring: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering assert_cc(sizeof(off_t) == sizeof(uint64_t));
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse bytes value, ignoring: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse boolean value, ignoring: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering /* Tristates are like booleans, but can also take the 'default' value, i.e. "-1" */
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Failed to parse boolean value, ignoring: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] String is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
d4205751d4643c272059a3728045929dd0e5e800Lennart Poettering log_error("[%s:%u] Path is not UTF-8 clean, ignoring assignment: %s", filename, line, rvalue);
844ec79b3c2f246114ea316ebe1f36044bdb688eZbigniew Jędrzejewski-Szmek log_error("[%s:%u] Not an absolute path, ignoring: %s", filename, line, rvalue);
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek FOREACH_WORD_QUOTED(w, l, rvalue, state)
2e8fb7026d3c560194cfe9f83935ce0b16263da0Lukas Nykryn for (k = 0; (*sv)[k]; k++)
464264ac5a35b655065c5d95b8d8ffbbc7ff3bcfLukas Nykryn n[k] = (*sv)[k];
54b7254c1fa629937f92fd6fa34bdf127b696a00Zbigniew Jędrzejewski-Szmek FOREACH_WORD_QUOTED(w, l, rvalue, state) {
if (!utf8_is_valid(n[k])) {
free(n[k]);
n[k] = NULL;
*sv = n;
fail:
free(n);
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
size_t l;
char *state;
return -ENOMEM;
if (*sv)
for (; (*sv)[k]; k++)
n[k] = (*sv)[k];
n[k] = strndup(w, l);
r = -ENOMEM;
goto fail;
if (!utf8_is_valid(n[k])) {
free(n[k]);
if (!path_is_absolute(n[k])) {
free(n[k]);
path_kill_slashes(n[k]);
n[k] = NULL;
*sv = n;
fail:
free(n);
int config_parse_usec(
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
int config_parse_mode(
const char *filename,
unsigned line,
const char *section,
const char *lvalue,
int ltype,
const char *rvalue,
void *data,
void *userdata) {
char *x = NULL;
errno = 0;
if (!x || *x || errno) {
*m = (mode_t) l;