mirror of
https://github.com/systemd/systemd.git
synced 2025-03-11 20:58:27 +03:00
Merge pull request #14533 from poettering/swap-prio-fixes
Fix Priority= parsing in .swap units
This commit is contained in:
commit
cd6cf81b3f
@ -12,16 +12,23 @@
|
||||
#include "unit.h"
|
||||
|
||||
static int swap_get_priority(Swap *s) {
|
||||
if (s->from_proc_swaps)
|
||||
assert(s);
|
||||
|
||||
if (s->from_proc_swaps && s->parameters_proc_swaps.priority_set)
|
||||
return s->parameters_proc_swaps.priority;
|
||||
if (s->from_fragment)
|
||||
|
||||
if (s->from_fragment && s->parameters_fragment.priority_set)
|
||||
return s->parameters_fragment.priority;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static const char *swap_get_options(Swap *s) {
|
||||
assert(s);
|
||||
|
||||
if (s->from_fragment)
|
||||
return s->parameters_fragment.options;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -435,7 +435,7 @@ Automount.DirectoryMode, config_parse_mode, 0,
|
||||
Automount.TimeoutIdleSec, config_parse_sec_fix_0, 0, offsetof(Automount, timeout_idle_usec)
|
||||
m4_dnl
|
||||
Swap.What, config_parse_unit_path_printf, 0, offsetof(Swap, parameters_fragment.what)
|
||||
Swap.Priority, config_parse_int, 0, offsetof(Swap, parameters_fragment.priority)
|
||||
Swap.Priority, config_parse_swap_priority, 0, 0
|
||||
Swap.Options, config_parse_unit_string_printf, 0, offsetof(Swap, parameters_fragment.options)
|
||||
Swap.TimeoutSec, config_parse_sec_fix_0, 0, offsetof(Swap, timeout_usec)
|
||||
EXEC_CONTEXT_CONFIG_ITEMS(Swap)m4_dnl
|
||||
|
@ -5002,3 +5002,51 @@ int config_parse_crash_chvt(
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_swap_priority(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
Swap *s = userdata;
|
||||
int r, priority;
|
||||
|
||||
assert(s);
|
||||
assert(filename);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
s->parameters_fragment.priority = -1;
|
||||
s->parameters_fragment.priority_set = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = safe_atoi(rvalue, &priority);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, r, "Invalid swap pririty '%s', ignoring.", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (priority < -1) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Sorry, swap priorities smaller than -1 may only be assigned by the kernel itself, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (priority > 32767) {
|
||||
log_syntax(unit, LOG_ERR, filename, line, 0, "Swap priority out of range, ignoring: %s", rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
s->parameters_fragment.priority = priority;
|
||||
s->parameters_fragment.priority_set = true;
|
||||
return 0;
|
||||
}
|
||||
|
@ -121,6 +121,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_status_unit_format);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_output_restricted);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_crash_chvt);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_timeout_abort);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_swap_priority);
|
||||
|
||||
/* gperf prototypes */
|
||||
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
|
||||
|
@ -63,7 +63,6 @@ static void swap_unset_proc_swaps(Swap *s) {
|
||||
return;
|
||||
|
||||
s->parameters_proc_swaps.what = mfree(s->parameters_proc_swaps.what);
|
||||
|
||||
s->from_proc_swaps = false;
|
||||
}
|
||||
|
||||
@ -117,9 +116,6 @@ static void swap_init(Unit *u) {
|
||||
s->exec_context.std_output = u->manager->default_std_output;
|
||||
s->exec_context.std_error = u->manager->default_std_error;
|
||||
|
||||
s->parameters_proc_swaps.priority = s->parameters_fragment.priority = 0;
|
||||
s->parameters_fragment.priority_set = false;
|
||||
|
||||
s->control_command_id = _SWAP_EXEC_COMMAND_INVALID;
|
||||
|
||||
u->ignore_on_isolate = true;
|
||||
@ -772,17 +768,19 @@ static void swap_enter_activating(Swap *s) {
|
||||
|
||||
r = fstab_find_pri(s->parameters_fragment.options, &priority);
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to parse swap priority \"%s\", ignoring: %m", s->parameters_fragment.options);
|
||||
else if (r == 1 && s->parameters_fragment.priority_set)
|
||||
log_warning("Duplicate swap priority configuration by Priority and Options fields.");
|
||||
log_unit_warning_errno(UNIT(s), r, "Failed to parse swap priority \"%s\", ignoring: %m", s->parameters_fragment.options);
|
||||
else if (r > 0 && s->parameters_fragment.priority_set)
|
||||
log_unit_warning(UNIT(s), "Duplicate swap priority configuration by Priority= and Options= fields.");
|
||||
|
||||
if (r <= 0 && s->parameters_fragment.priority_set) {
|
||||
if (s->parameters_fragment.options)
|
||||
r = asprintf(&opts, "%s,pri=%i", s->parameters_fragment.options, s->parameters_fragment.priority);
|
||||
else
|
||||
r = asprintf(&opts, "pri=%i", s->parameters_fragment.priority);
|
||||
if (r < 0)
|
||||
if (r < 0) {
|
||||
r = -ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -792,7 +790,7 @@ static void swap_enter_activating(Swap *s) {
|
||||
|
||||
if (s->parameters_fragment.options || opts) {
|
||||
r = exec_command_append(s->control_command, "-o",
|
||||
opts ? : s->parameters_fragment.options, NULL);
|
||||
opts ?: s->parameters_fragment.options, NULL);
|
||||
if (r < 0)
|
||||
goto fail;
|
||||
}
|
||||
@ -808,7 +806,6 @@ static void swap_enter_activating(Swap *s) {
|
||||
goto fail;
|
||||
|
||||
swap_set_state(s, SWAP_ACTIVATING);
|
||||
|
||||
return;
|
||||
|
||||
fail:
|
||||
|
Loading…
x
Reference in New Issue
Block a user