2013-01-23 14:44:07 +01:00
|
|
|
From c040936be2a4c77e9465cffae47d77d5ec14fb49 Mon Sep 17 00:00:00 2001
|
|
|
|
From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl>
|
|
|
|
Date: Mon, 19 Nov 2012 16:02:45 +0100
|
|
|
|
Subject: [PATCH] core/load-fragment: be more precise in error messages
|
|
|
|
|
|
|
|
Whenever a message fails, mention the offending word, instead
|
|
|
|
of just giving the whole line. If one bad word causes just this
|
|
|
|
word to be rejected, print only the word. If one bad word causes
|
|
|
|
the whole line to be rejected, print the whole line too.
|
|
|
|
|
|
|
|
https://bugs.freedesktop.org/show_bug.cgi?id=56874
|
|
|
|
---
|
|
|
|
src/core/load-fragment.c | 69 +++++++++++++++++++++-------------------------
|
|
|
|
1 file changed, 31 insertions(+), 38 deletions(-)
|
|
|
|
|
2013-03-20 11:29:34 +01:00
|
|
|
Index: systemd-195/src/core/load-fragment.c
|
|
|
|
===================================================================
|
|
|
|
--- systemd-195.orig/src/core/load-fragment.c
|
|
|
|
+++ systemd-195/src/core/load-fragment.c
|
|
|
|
@@ -85,7 +85,7 @@ int config_parse_unit_deps(
|
2013-01-23 14:44:07 +01:00
|
|
|
assert(rvalue);
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
- char *t, *k;
|
|
|
|
+ char _cleanup_free_ *t = NULL, *k = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
t = strndup(w, l);
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -93,15 +93,13 @@ int config_parse_unit_deps(
|
2013-01-23 14:44:07 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = unit_name_printf(u, t);
|
|
|
|
- free(t);
|
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = unit_add_dependency_by_name(u, d, k, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
- log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
|
|
|
|
-
|
|
|
|
- free(k);
|
|
|
|
+ log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s",
|
|
|
|
+ filename, line, k, strerror(-r));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -739,22 +737,25 @@ int config_parse_exec_cpu_affinity(
|
2013-01-23 14:44:07 +01:00
|
|
|
assert(data);
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
- char *t;
|
|
|
|
+ char _cleanup_free_ *t = NULL;
|
|
|
|
int r;
|
|
|
|
unsigned cpu;
|
|
|
|
|
|
|
|
- if (!(t = strndup(w, l)))
|
|
|
|
+ t = strndup(w, l);
|
|
|
|
+ if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = safe_atou(t, &cpu);
|
|
|
|
- free(t);
|
|
|
|
|
|
|
|
- if (!(c->cpuset))
|
|
|
|
- if (!(c->cpuset = cpu_set_malloc(&c->cpuset_ncpus)))
|
|
|
|
+ if (!c->cpuset) {
|
|
|
|
+ c->cpuset = cpu_set_malloc(&c->cpuset_ncpus);
|
|
|
|
+ if (!c->cpuset)
|
|
|
|
return -ENOMEM;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (r < 0 || cpu >= c->cpuset_ncpus) {
|
|
|
|
- log_error("[%s:%u] Failed to parse CPU affinity, ignoring: %s", filename, line, rvalue);
|
|
|
|
+ log_error("[%s:%u] Failed to parse CPU affinity %s, ignoring: %s",
|
|
|
|
+ filename, line, t, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -831,7 +832,8 @@ int config_parse_exec_secure_bits(
|
2013-01-23 14:44:07 +01:00
|
|
|
else if (first_word(w, "noroot-locked"))
|
|
|
|
c->secure_bits |= SECURE_NOROOT_LOCKED;
|
|
|
|
else {
|
|
|
|
- log_error("[%s:%u] Failed to parse secure bits, ignoring: %s", filename, line, rvalue);
|
|
|
|
+ log_error("[%s:%u] Failed to parse secure bits, ignoring: %s",
|
|
|
|
+ filename, line, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -872,7 +874,7 @@ int config_parse_bounding_set(
|
2013-01-23 14:44:07 +01:00
|
|
|
* interface. */
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
- char *t;
|
|
|
|
+ char _cleanup_free_ *t = NULL;
|
|
|
|
int r;
|
|
|
|
cap_value_t cap;
|
|
|
|
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -881,10 +883,9 @@ int config_parse_bounding_set(
|
2013-01-23 14:44:07 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
r = cap_from_name(t, &cap);
|
|
|
|
- free(t);
|
|
|
|
-
|
|
|
|
if (r < 0) {
|
|
|
|
- log_error("[%s:%u] Failed to parse capability bounding set, ignoring: %s", filename, line, rvalue);
|
|
|
|
+ log_error("[%s:%u] Failed to parse capability in bounding set, ignoring: %s",
|
|
|
|
+ filename, line, t);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -950,7 +951,7 @@ int config_parse_unit_cgroup(
|
2013-01-23 14:44:07 +01:00
|
|
|
char *state;
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
- char *t, *k;
|
|
|
|
+ char _cleanup_free_ *t = NULL, *k = NULL, *ku = NULL;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
t = strndup(w, l);
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -958,22 +959,17 @@ int config_parse_unit_cgroup(
|
2013-01-23 14:44:07 +01:00
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = unit_full_printf(u, t);
|
|
|
|
- free(t);
|
|
|
|
-
|
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
- t = cunescape(k);
|
|
|
|
- free(k);
|
|
|
|
-
|
|
|
|
- if (!t)
|
|
|
|
+ ku = cunescape(k);
|
|
|
|
+ if (!ku)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
- r = unit_add_cgroup_from_text(u, t);
|
|
|
|
- free(t);
|
|
|
|
-
|
|
|
|
+ r = unit_add_cgroup_from_text(u, ku);
|
|
|
|
if (r < 0) {
|
|
|
|
- log_error("[%s:%u] Failed to parse cgroup value, ignoring: %s", filename, line, rvalue);
|
|
|
|
+ log_error("[%s:%u] Failed to parse cgroup value %s, ignoring: %s",
|
|
|
|
+ filename, line, k, rvalue);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -1333,33 +1329,30 @@ int config_parse_service_sockets(
|
2013-01-23 14:44:07 +01:00
|
|
|
assert(data);
|
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
- char *t, *k;
|
|
|
|
+ char _cleanup_free_ *t = NULL, *k = NULL;
|
|
|
|
|
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
k = unit_name_printf(UNIT(s), t);
|
|
|
|
- free(t);
|
|
|
|
-
|
|
|
|
if (!k)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
if (!endswith(k, ".socket")) {
|
|
|
|
- log_error("[%s:%u] Unit must be of type socket, ignoring: %s", filename, line, rvalue);
|
|
|
|
- free(k);
|
|
|
|
+ log_error("[%s:%u] Unit must be of type socket, ignoring: %s",
|
|
|
|
+ filename, line, k);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
r = unit_add_two_dependencies_by_name(UNIT(s), UNIT_WANTS, UNIT_AFTER, k, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
- log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s", filename, line, k, strerror(-r));
|
|
|
|
+ log_error("[%s:%u] Failed to add dependency on %s, ignoring: %s",
|
|
|
|
+ filename, line, k, strerror(-r));
|
|
|
|
|
|
|
|
r = unit_add_dependency_by_name(UNIT(s), UNIT_TRIGGERED_BY, k, NULL, true);
|
|
|
|
if (r < 0)
|
|
|
|
return r;
|
|
|
|
-
|
|
|
|
- free(k);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
2013-03-20 11:29:34 +01:00
|
|
|
@@ -2087,17 +2080,17 @@ int config_parse_syscall_filter(
|
2013-01-23 14:44:07 +01:00
|
|
|
|
|
|
|
FOREACH_WORD_QUOTED(w, l, rvalue, state) {
|
|
|
|
int id;
|
|
|
|
- char *t;
|
|
|
|
+ char _cleanup_free_ *t = NULL;
|
|
|
|
|
|
|
|
t = strndup(w, l);
|
|
|
|
if (!t)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
id = syscall_from_name(t);
|
|
|
|
- free(t);
|
|
|
|
|
|
|
|
if (id < 0) {
|
|
|
|
- log_error("[%s:%u] Failed to parse syscall, ignoring: %s", filename, line, rvalue);
|
|
|
|
+ log_error("[%s:%u] Failed to parse syscall, ignoring: %s",
|
|
|
|
+ filename, line, t);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|