cryptsetup: allow x-systemd.device-timeout
https://bugs.freedesktop.org/show_bug.cgi?id=54210
This commit is contained in:
parent
b3208b6629
commit
8eea868708
|
@ -2998,7 +2998,7 @@ static int unit_drop_in_file(Unit *u,
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return drop_in_file(dir, u->id, name, p, q);
|
return drop_in_file(dir, u->id, 50, name, p, q);
|
||||||
}
|
}
|
||||||
|
|
||||||
int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
|
int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *data) {
|
||||||
|
@ -3015,7 +3015,7 @@ int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, co
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
return write_drop_in(dir, u->id, name, data);
|
return write_drop_in(dir, u->id, 50, name, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) {
|
int unit_write_drop_in_format(Unit *u, UnitSetPropertiesMode mode, const char *name, const char *format, ...) {
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
#include "strv.h"
|
#include "strv.h"
|
||||||
#include "fileio.h"
|
#include "fileio.h"
|
||||||
#include "path-util.h"
|
#include "path-util.h"
|
||||||
|
#include "dropin.h"
|
||||||
|
#include "generator.h"
|
||||||
|
|
||||||
static const char *arg_dest = "/tmp";
|
static const char *arg_dest = "/tmp";
|
||||||
static bool arg_enabled = true;
|
static bool arg_enabled = true;
|
||||||
|
@ -73,7 +75,8 @@ static int create_disk(
|
||||||
const char *password,
|
const char *password,
|
||||||
const char *options) {
|
const char *options) {
|
||||||
|
|
||||||
_cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *to = NULL, *e = NULL;
|
_cleanup_free_ char *p = NULL, *n = NULL, *d = NULL, *u = NULL, *to = NULL, *e = NULL,
|
||||||
|
*filtered = NULL;
|
||||||
_cleanup_fclose_ FILE *f = NULL;
|
_cleanup_fclose_ FILE *f = NULL;
|
||||||
bool noauto, nofail, tmp, swap;
|
bool noauto, nofail, tmp, swap;
|
||||||
char *from;
|
char *from;
|
||||||
|
@ -172,6 +175,10 @@ static int create_disk(
|
||||||
"RequiresMountsFor=%s\n",
|
"RequiresMountsFor=%s\n",
|
||||||
u);
|
u);
|
||||||
|
|
||||||
|
r = generator_write_timeouts(arg_dest, device, name, options, &filtered);
|
||||||
|
if (r < 0)
|
||||||
|
return r;
|
||||||
|
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"\n[Service]\n"
|
"\n[Service]\n"
|
||||||
"Type=oneshot\n"
|
"Type=oneshot\n"
|
||||||
|
@ -179,7 +186,7 @@ static int create_disk(
|
||||||
"TimeoutSec=0\n" /* the binary handles timeouts anyway */
|
"TimeoutSec=0\n" /* the binary handles timeouts anyway */
|
||||||
"ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
|
"ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
|
||||||
"ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
|
"ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
|
||||||
name, u, strempty(password), strempty(options),
|
name, u, strempty(password), strempty(filtered),
|
||||||
name);
|
name);
|
||||||
|
|
||||||
if (tmp)
|
if (tmp)
|
||||||
|
@ -239,17 +246,9 @@ static int create_disk(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!noauto && !nofail) {
|
if (!noauto && !nofail) {
|
||||||
|
r = write_drop_in(arg_dest, name, 90, "device-timeout",
|
||||||
free(p);
|
"# Automatically generated by systemd-cryptsetup-generator \n\n"
|
||||||
p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL);
|
"[Unit]\nJobTimeoutSec=0");
|
||||||
if (!p)
|
|
||||||
return log_oom();
|
|
||||||
|
|
||||||
mkdir_parents_label(p, 0755);
|
|
||||||
r = write_string_file(p,
|
|
||||||
"# Automatically generated by systemd-cryptsetup-generator\n\n"
|
|
||||||
"[Unit]\n"
|
|
||||||
"JobTimeoutSec=0\n"); /* the binary handles timeouts anyway */
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
log_error("Failed to write device drop-in: %s", strerror(-r));
|
log_error("Failed to write device drop-in: %s", strerror(-r));
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -24,17 +24,21 @@
|
||||||
#include "mkdir.h"
|
#include "mkdir.h"
|
||||||
#include "fileio-label.h"
|
#include "fileio-label.h"
|
||||||
|
|
||||||
int drop_in_file(const char *dir, const char *unit,
|
int drop_in_file(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, char **_p, char **_q) {
|
const char *name, char **_p, char **_q) {
|
||||||
|
|
||||||
_cleanup_free_ char *b = NULL;
|
_cleanup_free_ char *b = NULL;
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
|
|
||||||
|
char prefix[DECIMAL_STR_MAX(unsigned)];
|
||||||
|
|
||||||
assert(unit);
|
assert(unit);
|
||||||
assert(name);
|
assert(name);
|
||||||
assert(_p);
|
assert(_p);
|
||||||
assert(_q);
|
assert(_q);
|
||||||
|
|
||||||
|
sprintf(prefix, "%u", level);
|
||||||
|
|
||||||
b = xescape(name, "/.");
|
b = xescape(name, "/.");
|
||||||
if (!b)
|
if (!b)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -46,7 +50,7 @@ int drop_in_file(const char *dir, const char *unit,
|
||||||
if (!p)
|
if (!p)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
q = strjoin(p, "/90-", b, ".conf", NULL);
|
q = strjoin(p, "/", prefix, "-", b, ".conf", NULL);
|
||||||
if (!q) {
|
if (!q) {
|
||||||
free(p);
|
free(p);
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
@ -57,7 +61,7 @@ int drop_in_file(const char *dir, const char *unit,
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_drop_in(const char *dir, const char *unit,
|
int write_drop_in(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, const char *data) {
|
const char *name, const char *data) {
|
||||||
|
|
||||||
_cleanup_free_ char *p = NULL, *q = NULL;
|
_cleanup_free_ char *p = NULL, *q = NULL;
|
||||||
|
@ -68,7 +72,7 @@ int write_drop_in(const char *dir, const char *unit,
|
||||||
assert(name);
|
assert(name);
|
||||||
assert(data);
|
assert(data);
|
||||||
|
|
||||||
r = drop_in_file(dir, unit, name, &p, &q);
|
r = drop_in_file(dir, unit, level, name, &p, &q);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
|
@ -76,7 +80,7 @@ int write_drop_in(const char *dir, const char *unit,
|
||||||
return write_string_file_atomic_label(q, data);
|
return write_string_file_atomic_label(q, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int write_drop_in_format(const char *dir, const char *unit,
|
int write_drop_in_format(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, const char *format, ...) {
|
const char *name, const char *format, ...) {
|
||||||
_cleanup_free_ char *p = NULL;
|
_cleanup_free_ char *p = NULL;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
|
@ -94,5 +98,5 @@ int write_drop_in_format(const char *dir, const char *unit,
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
return write_drop_in(dir, unit, name, p);
|
return write_drop_in(dir, unit, level, name, p);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,11 +21,11 @@
|
||||||
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
***/
|
***/
|
||||||
|
|
||||||
int drop_in_file(const char *dir, const char *unit,
|
int drop_in_file(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, char **_p, char **_q);
|
const char *name, char **_p, char **_q);
|
||||||
|
|
||||||
int write_drop_in(const char *dir, const char *unit,
|
int write_drop_in(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, const char *data);
|
const char *name, const char *data);
|
||||||
|
|
||||||
int write_drop_in_format(const char *dir, const char *unit,
|
int write_drop_in_format(const char *dir, const char *unit, unsigned level,
|
||||||
const char *name, const char *format, ...);
|
const char *name, const char *format, ...);
|
||||||
|
|
|
@ -108,7 +108,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
|
||||||
timeout = start + 25;
|
timeout = start + 25;
|
||||||
else {
|
else {
|
||||||
if (filtered) {
|
if (filtered) {
|
||||||
*filtered = strdup(opts);
|
*filtered = strdup(opts ?: "");
|
||||||
if (!*filtered)
|
if (!*filtered)
|
||||||
return log_oom();
|
return log_oom();
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,9 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
|
||||||
if (!unit)
|
if (!unit)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
||||||
return write_drop_in_format(dir, unit, "device-timeout",
|
return write_drop_in_format(dir, unit, 50, "device-timeout",
|
||||||
"[Unit]\nJobTimeoutSec=%u", u / USEC_PER_SEC);
|
"# Automatically generated by %s\n\n"
|
||||||
|
"[Unit]\nJobTimeoutSec=%u",
|
||||||
|
program_invocation_short_name,
|
||||||
|
u / USEC_PER_SEC);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue