specifier: when resolving specifier strings when loading configuration, don't misunderstand parse failures as OOM

http://lists.freedesktop.org/archives/systemd-devel/2013-February/009179.html
This commit is contained in:
Lennart Poettering 2013-03-01 14:54:55 +01:00
parent 3f8ee79182
commit 487060c239
2 changed files with 37 additions and 22 deletions

2
TODO
View file

@ -49,6 +49,8 @@ Fedora 19:
Features: Features:
* rework specifier logic so that we can distuingish OOM errors from other errors
* systemd-inhibit: refuse taking delay locks * systemd-inhibit: refuse taking delay locks
* journal-or-kmsg is currently broken? See reverted commit 4a01181e460686d8b4a543b1dfa7f77c9e3c5ab8. * journal-or-kmsg is currently broken? See reverted commit 4a01181e460686d8b4a543b1dfa7f77c9e3c5ab8.

View file

@ -127,9 +127,10 @@ int config_parse_unit_string_printf(
k = unit_full_printf(u, rvalue); k = unit_full_printf(u, rvalue);
if (!k) if (!k)
return log_oom(); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, rvalue);
return config_parse_string(filename, line, section, lvalue, ltype, k, data, userdata); return config_parse_string(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata);
} }
int config_parse_unit_strv_printf( int config_parse_unit_strv_printf(
@ -152,9 +153,10 @@ int config_parse_unit_strv_printf(
k = unit_full_printf(u, rvalue); k = unit_full_printf(u, rvalue);
if (!k) if (!k)
return log_oom(); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, rvalue);
return config_parse_strv(filename, line, section, lvalue, ltype, k, data, userdata); return config_parse_strv(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata);
} }
int config_parse_unit_path_printf( int config_parse_unit_path_printf(
@ -177,9 +179,10 @@ int config_parse_unit_path_printf(
k = unit_full_printf(u, rvalue); k = unit_full_printf(u, rvalue);
if (!k) if (!k)
return log_oom(); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, rvalue);
return config_parse_path(filename, line, section, lvalue, ltype, k, data, userdata); return config_parse_path(filename, line, section, lvalue, ltype, k ? k : rvalue, data, userdata);
} }
int config_parse_socket_listen( int config_parse_socket_listen(
@ -217,8 +220,13 @@ int config_parse_socket_listen(
p->type = ltype; p->type = ltype;
p->path = unit_full_printf(UNIT(s), rvalue); p->path = unit_full_printf(UNIT(s), rvalue);
if (!p->path) { if (!p->path) {
free(p); p->path = strdup(rvalue);
return log_oom(); if (!p->path) {
free(p);
return log_oom();
} else
log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, rvalue);
} }
path_kill_slashes(p->path); path_kill_slashes(p->path);
@ -229,12 +237,11 @@ int config_parse_socket_listen(
p->type = SOCKET_SOCKET; p->type = SOCKET_SOCKET;
k = unit_full_printf(UNIT(s), rvalue); k = unit_full_printf(UNIT(s), rvalue);
if (!k) { if (!k)
free(p); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
return log_oom(); filename, line, rvalue);
}
r = socket_address_parse_netlink(&p->address, k); r = socket_address_parse_netlink(&p->address, k ? k : rvalue);
if (r < 0) { if (r < 0) {
log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue); log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
free(p); free(p);
@ -247,12 +254,11 @@ int config_parse_socket_listen(
p->type = SOCKET_SOCKET; p->type = SOCKET_SOCKET;
k = unit_full_printf(UNIT(s), rvalue); k = unit_full_printf(UNIT(s), rvalue);
if (!k) { if (!k)
free(p); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
return log_oom(); filename, line, rvalue);
}
r = socket_address_parse(&p->address, k); r = socket_address_parse(&p->address, k ? k : rvalue);
if (r < 0) { if (r < 0) {
log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue); log_error("[%s:%u] Failed to parse address value, ignoring: %s", filename, line, rvalue);
free(p); free(p);
@ -995,9 +1001,10 @@ int config_parse_unit_cgroup(
k = unit_full_printf(u, t); k = unit_full_printf(u, t);
if (!k) if (!k)
return log_oom(); log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, t);
ku = cunescape(k); ku = cunescape(k ? k : t);
if (!ku) if (!ku)
return log_oom(); return log_oom();
@ -1284,8 +1291,14 @@ int config_parse_path_spec(
} }
k = unit_full_printf(UNIT(p), rvalue); k = unit_full_printf(UNIT(p), rvalue);
if (!k) if (!k) {
return log_oom(); k = strdup(rvalue);
if (!k)
return log_oom();
else
log_error("[%s:%u] Failed to resolve unit specifiers on %s. Ignoring.",
filename, line, rvalue);
}
if (!path_is_absolute(k)) { if (!path_is_absolute(k)) {
log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, k); log_error("[%s:%u] Path is not absolute, ignoring: %s", filename, line, k);