aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-30 18:41:17 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-06-30 18:41:17 -0400
commit8eea868708923a092ee85d6146ba4c04b7baea06 (patch)
treefcbb03789d329522d5ef87242608fa6467595b62
parentfstab-generator: allow x-systemd.device-timeout for swap units (diff)
downloadsystemd-8eea868708923a092ee85d6146ba4c04b7baea06.tar.gz
systemd-8eea868708923a092ee85d6146ba4c04b7baea06.tar.bz2
systemd-8eea868708923a092ee85d6146ba4c04b7baea06.zip
cryptsetup: allow x-systemd.device-timeout
https://bugs.freedesktop.org/show_bug.cgi?id=54210
-rw-r--r--src/core/unit.c4
-rw-r--r--src/cryptsetup/cryptsetup-generator.c25
-rw-r--r--src/shared/dropin.c16
-rw-r--r--src/shared/dropin.h6
-rw-r--r--src/shared/generator.c9
5 files changed, 33 insertions, 27 deletions
diff --git a/src/core/unit.c b/src/core/unit.c
index bace69f46..0e4ebfde9 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -2998,7 +2998,7 @@ static int unit_drop_in_file(Unit *u,
if (r < 0)
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) {
@@ -3015,7 +3015,7 @@ int unit_write_drop_in(Unit *u, UnitSetPropertiesMode mode, const char *name, co
if (r < 0)
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, ...) {
diff --git a/src/cryptsetup/cryptsetup-generator.c b/src/cryptsetup/cryptsetup-generator.c
index da1632459..3233e15f4 100644
--- a/src/cryptsetup/cryptsetup-generator.c
+++ b/src/cryptsetup/cryptsetup-generator.c
@@ -30,6 +30,8 @@
#include "strv.h"
#include "fileio.h"
#include "path-util.h"
+#include "dropin.h"
+#include "generator.h"
static const char *arg_dest = "/tmp";
static bool arg_enabled = true;
@@ -73,7 +75,8 @@ static int create_disk(
const char *password,
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;
bool noauto, nofail, tmp, swap;
char *from;
@@ -172,6 +175,10 @@ static int create_disk(
"RequiresMountsFor=%s\n",
u);
+ r = generator_write_timeouts(arg_dest, device, name, options, &filtered);
+ if (r < 0)
+ return r;
+
fprintf(f,
"\n[Service]\n"
"Type=oneshot\n"
@@ -179,7 +186,7 @@ static int create_disk(
"TimeoutSec=0\n" /* the binary handles timeouts anyway */
"ExecStart=" SYSTEMD_CRYPTSETUP_PATH " attach '%s' '%s' '%s' '%s'\n"
"ExecStop=" SYSTEMD_CRYPTSETUP_PATH " detach '%s'\n",
- name, u, strempty(password), strempty(options),
+ name, u, strempty(password), strempty(filtered),
name);
if (tmp)
@@ -239,17 +246,9 @@ static int create_disk(
}
if (!noauto && !nofail) {
-
- free(p);
- p = strjoin(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf", NULL);
- 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 */
+ r = write_drop_in(arg_dest, name, 90, "device-timeout",
+ "# Automatically generated by systemd-cryptsetup-generator \n\n"
+ "[Unit]\nJobTimeoutSec=0");
if (r < 0) {
log_error("Failed to write device drop-in: %s", strerror(-r));
return r;
diff --git a/src/shared/dropin.c b/src/shared/dropin.c
index 7774236f7..ac09be984 100644
--- a/src/shared/dropin.c
+++ b/src/shared/dropin.c
@@ -24,17 +24,21 @@
#include "mkdir.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) {
_cleanup_free_ char *b = NULL;
char *p, *q;
+ char prefix[DECIMAL_STR_MAX(unsigned)];
+
assert(unit);
assert(name);
assert(_p);
assert(_q);
+ sprintf(prefix, "%u", level);
+
b = xescape(name, "/.");
if (!b)
return -ENOMEM;
@@ -46,7 +50,7 @@ int drop_in_file(const char *dir, const char *unit,
if (!p)
return -ENOMEM;
- q = strjoin(p, "/90-", b, ".conf", NULL);
+ q = strjoin(p, "/", prefix, "-", b, ".conf", NULL);
if (!q) {
free(p);
return -ENOMEM;
@@ -57,7 +61,7 @@ int drop_in_file(const char *dir, const char *unit,
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) {
_cleanup_free_ char *p = NULL, *q = NULL;
@@ -68,7 +72,7 @@ int write_drop_in(const char *dir, const char *unit,
assert(name);
assert(data);
- r = drop_in_file(dir, unit, name, &p, &q);
+ r = drop_in_file(dir, unit, level, name, &p, &q);
if (r < 0)
return r;
@@ -76,7 +80,7 @@ int write_drop_in(const char *dir, const char *unit,
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, ...) {
_cleanup_free_ char *p = NULL;
va_list ap;
@@ -94,5 +98,5 @@ int write_drop_in_format(const char *dir, const char *unit,
if (r < 0)
return -ENOMEM;
- return write_drop_in(dir, unit, name, p);
+ return write_drop_in(dir, unit, level, name, p);
}
diff --git a/src/shared/dropin.h b/src/shared/dropin.h
index 295863296..27a2b2953 100644
--- a/src/shared/dropin.h
+++ b/src/shared/dropin.h
@@ -21,11 +21,11 @@
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);
-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);
-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, ...);
diff --git a/src/shared/generator.c b/src/shared/generator.c
index 1db5f8fb6..5d5b6a0a6 100644
--- a/src/shared/generator.c
+++ b/src/shared/generator.c
@@ -108,7 +108,7 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
timeout = start + 25;
else {
if (filtered) {
- *filtered = strdup(opts);
+ *filtered = strdup(opts ?: "");
if (!*filtered)
return log_oom();
}
@@ -146,6 +146,9 @@ int generator_write_timeouts(const char *dir, const char *what, const char *wher
if (!unit)
return -ENOMEM;
- return write_drop_in_format(dir, unit, "device-timeout",
- "[Unit]\nJobTimeoutSec=%u", u / USEC_PER_SEC);
+ return write_drop_in_format(dir, unit, 50, "device-timeout",
+ "# Automatically generated by %s\n\n"
+ "[Unit]\nJobTimeoutSec=%u",
+ program_invocation_short_name,
+ u / USEC_PER_SEC);
}