diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 0fce812b400..871d79e0d25 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1029,20 +1029,18 @@ static uint64_t cgroup_context_io_weight(CGroupContext *c, ManagerState state) { if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && c->startup_io_weight != CGROUP_WEIGHT_INVALID) return c->startup_io_weight; - else if (c->io_weight != CGROUP_WEIGHT_INVALID) + if (c->io_weight != CGROUP_WEIGHT_INVALID) return c->io_weight; - else - return CGROUP_WEIGHT_DEFAULT; + return CGROUP_WEIGHT_DEFAULT; } static uint64_t cgroup_context_blkio_weight(CGroupContext *c, ManagerState state) { if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) && c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) return c->startup_blockio_weight; - else if (c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) + if (c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID) return c->blockio_weight; - else - return CGROUP_BLKIO_WEIGHT_DEFAULT; + return CGROUP_BLKIO_WEIGHT_DEFAULT; } static uint64_t cgroup_weight_blkio_to_io(uint64_t blkio_weight) { diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 7e95f0e3907..4fc4fb00216 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -1439,12 +1439,11 @@ int bus_cgroup_set_property( } else if (STR_IN_SET(name, "BlockIOReadBandwidth", "BlockIOWriteBandwidth")) { const char *path; - bool read = true; unsigned n = 0; uint64_t u64; + bool read; - if (streq(name, "BlockIOWriteBandwidth")) - read = false; + read = streq(name, "BlockIOReadBandwidth"); r = sd_bus_message_enter_container(message, 'a', "(st)"); if (r < 0) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 313f667cd79..92e99e7d536 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -4211,11 +4211,16 @@ int config_parse_io_device_weight( r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(p)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract device path and weight from '%s', ignoring.", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid device path or weight specified in '%s', ignoring.", rvalue); + return 0; + } r = unit_path_printf(userdata, path, &resolved); if (r < 0) { @@ -4280,11 +4285,16 @@ int config_parse_io_device_latency( r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(p)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract device path and latency from '%s', ignoring.", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid device path or latency specified in '%s', ignoring.", rvalue); + return 0; + } r = unit_path_printf(userdata, path, &resolved); if (r < 0) { @@ -4350,11 +4360,16 @@ int config_parse_io_limit( r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(p)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue); + return 0; + } r = unit_path_printf(userdata, path, &resolved); if (r < 0) { @@ -4435,11 +4450,16 @@ int config_parse_blockio_device_weight( r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(p)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract device node and weight from '%s', ignoring.", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid device node or weight specified in '%s', ignoring.", rvalue); + return 0; + } r = unit_path_printf(userdata, path, &resolved); if (r < 0) { @@ -4508,11 +4528,16 @@ int config_parse_blockio_bandwidth( r = extract_first_word(&p, &path, NULL, EXTRACT_UNQUOTE); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(p)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract device node and bandwidth from '%s', ignoring.", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, + "Invalid device node or bandwidth specified in '%s', ignoring.", rvalue); + return 0; + } r = unit_path_printf(userdata, path, &resolved); if (r < 0) { @@ -4728,8 +4753,12 @@ int config_parse_set_credential( r = extract_first_word(&p, &word, ":", EXTRACT_DONT_COALESCE_SEPARATORS); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || !p) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid syntax, ignoring: %s", rvalue); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to extract credential name, ignoring: %s", rvalue); + return 0; + } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax, ignoring: %s", rvalue); return 0; } @@ -5208,7 +5237,7 @@ int config_parse_bind_paths( if (r == -ENOMEM) return log_oom(); if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s: %s", lvalue, rvalue); + log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse %s=, ignoring: %s", lvalue, rvalue); return 0; } @@ -5858,6 +5887,7 @@ int config_parse_bpf_foreign_program( void *userdata) { _cleanup_free_ char *resolved = NULL, *word = NULL; CGroupContext *c = data; + const char *p = rvalue; Unit *u = userdata; int attach_type, r; @@ -5872,13 +5902,17 @@ int config_parse_bpf_foreign_program( return 0; } - r = extract_first_word(&rvalue, &word, ":", 0); + r = extract_first_word(&p, &word, ":", 0); if (r == -ENOMEM) return log_oom(); - if (r <= 0 || isempty(rvalue)) { + if (r < 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse foreign BPF program, ignoring: %s", rvalue); return 0; } + if (r == 0 || isempty(p)) { + log_syntax(unit, LOG_WARNING, filename, line, 0, "Invalid syntax in %s=, ignoring: %s", lvalue, rvalue); + return 0; + } attach_type = bpf_cgroup_attach_type_from_string(word); if (attach_type < 0) { @@ -5886,9 +5920,9 @@ int config_parse_bpf_foreign_program( return 0; } - r = unit_path_printf(u, rvalue, &resolved); + r = unit_path_printf(u, p, &resolved); if (r < 0) { - log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %m", rvalue); + log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to resolve unit specifiers in '%s', ignoring: %s", p, rvalue); return 0; }