summaryrefslogtreecommitdiff
path: root/src/core/main.c
diff options
context:
space:
mode:
authorFilipe Brandenburger <filbranden@google.com>2015-08-30 20:22:37 -0700
committerFilipe Brandenburger <filbranden@google.com>2015-08-31 17:15:56 -0700
commit4457c2279e032832bccd6ec0895105e3d6e192cc (patch)
treeca92440337a29e2e9b4d2bfa092f33a226e9c015 /src/core/main.c
parentd4c8dcc47aab8da904b6998c53c457d3d9a7b227 (diff)
core: Use extract_first_word in config_parse_cpu_affinity2
Related to the TODO item to replace FOREACH_WORD_QUOTED with it. Tested by setting `CPUAfinity=0 1' (and other similar settings) in /etc/systemd/system.conf, booting the system with the patched binaries (and also using `systemctl daemon-reload` to reconfigure) and checking that /proc/1/status indicates only CPUs 0 and 1 are allowed for PID 1. No regressions observed in test cases.
Diffstat (limited to 'src/core/main.c')
-rw-r--r--src/core/main.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/core/main.c b/src/core/main.c
index e232be88c0..9c2b0c0897 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -433,8 +433,6 @@ static int config_parse_cpu_affinity2(
void *data,
void *userdata) {
- const char *word, *state;
- size_t l;
cpu_set_t *c = NULL;
unsigned ncpus = 0;
@@ -442,16 +440,18 @@ static int config_parse_cpu_affinity2(
assert(lvalue);
assert(rvalue);
- FOREACH_WORD_QUOTED(word, l, rvalue, state) {
- char *t;
- int r;
+ for (;;) {
+ _cleanup_free_ char *word = NULL;
unsigned cpu;
+ int r;
- if (!(t = strndup(word, l)))
- return log_oom();
+ r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
+ if (r < 0)
+ return r;
+ if (r == 0)
+ break;
- r = safe_atou(t, &cpu);
- free(t);
+ r = safe_atou(word, &cpu);
if (!c)
if (!(c = cpu_set_malloc(&ncpus)))
@@ -466,7 +466,7 @@ static int config_parse_cpu_affinity2(
CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
}
- if (!isempty(state))
+ if (!isempty(rvalue))
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Trailing garbage, ignoring.");