mirror of
https://github.com/systemd/systemd.git
synced 2024-11-08 11:27:32 +03:00
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.
This commit is contained in:
parent
d4c8dcc47a
commit
4457c2279e
@ -433,8 +433,6 @@ static int config_parse_cpu_affinity2(
|
|||||||
void *data,
|
void *data,
|
||||||
void *userdata) {
|
void *userdata) {
|
||||||
|
|
||||||
const char *word, *state;
|
|
||||||
size_t l;
|
|
||||||
cpu_set_t *c = NULL;
|
cpu_set_t *c = NULL;
|
||||||
unsigned ncpus = 0;
|
unsigned ncpus = 0;
|
||||||
|
|
||||||
@ -442,16 +440,18 @@ static int config_parse_cpu_affinity2(
|
|||||||
assert(lvalue);
|
assert(lvalue);
|
||||||
assert(rvalue);
|
assert(rvalue);
|
||||||
|
|
||||||
FOREACH_WORD_QUOTED(word, l, rvalue, state) {
|
for (;;) {
|
||||||
char *t;
|
_cleanup_free_ char *word = NULL;
|
||||||
int r;
|
|
||||||
unsigned cpu;
|
unsigned cpu;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (!(t = strndup(word, l)))
|
r = extract_first_word(&rvalue, &word, WHITESPACE, EXTRACT_QUOTES);
|
||||||
return log_oom();
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
if (r == 0)
|
||||||
|
break;
|
||||||
|
|
||||||
r = safe_atou(t, &cpu);
|
r = safe_atou(word, &cpu);
|
||||||
free(t);
|
|
||||||
|
|
||||||
if (!c)
|
if (!c)
|
||||||
if (!(c = cpu_set_malloc(&ncpus)))
|
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);
|
CPU_SET_S(cpu, CPU_ALLOC_SIZE(ncpus), c);
|
||||||
}
|
}
|
||||||
if (!isempty(state))
|
if (!isempty(rvalue))
|
||||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
||||||
"Trailing garbage, ignoring.");
|
"Trailing garbage, ignoring.");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user