Skip to content

Commit

Permalink
unit: when JobTimeoutSec= is turned off, implicitly turn off JobRunni…
Browse files Browse the repository at this point in the history
…ngTimeoutSec= too

We added JobRunningTimeoutSec= late, and Dracut configured only
JobTimeoutSec= to turn of root device timeouts before. With this change
we'll propagate a reset of JobTimeoutSec= into JobRunningTimeoutSec=,
but only if the latter wasn't set explicitly.

This should restore compatibility with older systemd versions.

Fixes: systemd#6402

(cherry picked from commit d8fdc62)

[mkoutny: resolved conflicts:
	src/basic/time-util.c
                drop parse_sec_fix_0 as we store infinity as 0
	src/core/load-fragment-gperf.gperf.m4
	        adjust context (remove aliases)
	src/core/load-fragment.c
	        adjust context, use parse_sec
	src/core/load-fragment.h
	        adjust context, use parse_sec
	src/core/unit.h
	        adjust context]
  • Loading branch information
poettering authored and Werkov committed Oct 23, 2017
1 parent 341e240 commit 7673a8d
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/core/load-fragment-gperf.gperf.m4
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ Unit.OnFailureJobMode, config_parse_job_mode, 0,
Unit.OnFailureIsolate, config_parse_job_mode_isolate, 0, offsetof(Unit, on_failure_job_mode)
Unit.IgnoreOnIsolate, config_parse_bool, 0, offsetof(Unit, ignore_on_isolate)
Unit.IgnoreOnSnapshot, config_parse_warn_compat, DISABLED_LEGACY, 0
Unit.JobTimeoutSec, config_parse_sec, 0, offsetof(Unit, job_timeout)
Unit.JobRunningTimeoutSec, config_parse_sec, 0, offsetof(Unit, job_running_timeout)
Unit.JobTimeoutSec, config_parse_job_timeout_sec, 0, 0
Unit.JobRunningTimeoutSec, config_parse_job_running_timeout_sec, 0, 0
Unit.JobTimeoutAction, config_parse_failure_action, 0, offsetof(Unit, job_timeout_action)
Unit.JobTimeoutRebootArgument, config_parse_string, 0, offsetof(Unit, job_timeout_reboot_arg)
Unit.ConditionPathExists, config_parse_unit_condition_path, CONDITION_PATH_EXISTS, offsetof(Unit, conditions)
Expand Down
72 changes: 72 additions & 0 deletions src/core/load-fragment.c
Original file line number Diff line number Diff line change
Expand Up @@ -3641,6 +3641,78 @@ int config_parse_protect_system(
return 0;
}

int config_parse_job_timeout_sec(
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) {

Unit *u = data;
usec_t usec;
int r;

assert(filename);
assert(lvalue);
assert(rvalue);
assert(u);

r = parse_sec(rvalue, &usec);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobTimeoutSec= parameter, ignoring: %s", rvalue);
return 0;
}

/* If the user explicitly changed JobTimeoutSec= also change JobRunningTimeoutSec=, for compatibility with old
* versions. If JobRunningTimeoutSec= was explicitly set, avoid this however as whatever the usec picked should
* count. */

if (!u->job_running_timeout_set)
u->job_running_timeout = usec;

u->job_timeout = usec;

return 0;
}

int config_parse_job_running_timeout_sec(
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) {

Unit *u = data;
usec_t usec;
int r;

assert(filename);
assert(lvalue);
assert(rvalue);
assert(u);

r = parse_sec(rvalue, &usec);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Failed to parse JobRunningTimeoutSec= parameter, ignoring: %s", rvalue);
return 0;
}

u->job_running_timeout = usec;
u->job_running_timeout_set = true;

return 0;
}

#define FOLLOW_MAX 8

static int open_follow(char **filename, FILE **_f, Set *names, char **_final) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/load-fragment.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ int config_parse_bus_name(const char* unit, const char *filename, unsigned line,
int config_parse_exec_utmp_mode(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);
int config_parse_working_directory(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);
int config_parse_fdname(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);
int config_parse_job_timeout_sec(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);
int config_parse_job_running_timeout_sec(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);

/* gperf prototypes */
const struct ConfigPerfItem* load_fragment_gperf_lookup(const char *key, GPERF_LEN_TYPE length);
Expand Down
1 change: 1 addition & 0 deletions src/core/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ struct Unit {
/* Job timeout and action to take */
usec_t job_timeout;
usec_t job_running_timeout;
bool job_running_timeout_set:1;
FailureAction job_timeout_action;
char *job_timeout_reboot_arg;

Expand Down

0 comments on commit 7673a8d

Please sign in to comment.