chiark / gitweb /
cryptsetup: allow x-systemd.device-timeout
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 30 Jun 2014 22:41:17 +0000 (18:41 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 30 Jun 2014 22:41:17 +0000 (18:41 -0400)
https://bugs.freedesktop.org/show_bug.cgi?id=54210

src/core/unit.c
src/cryptsetup/cryptsetup-generator.c
src/shared/dropin.c
src/shared/dropin.h
src/shared/generator.c

index bace69f..0e4ebfd 100644 (file)
@@ -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, ...) {
index da16324..3233e15 100644 (file)
@@ -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;
index 7774236..ac09be9 100644 (file)
 #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);
 }
index 2958632..27a2b29 100644 (file)
   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, ...);
index 1db5f8f..5d5b6a0 100644 (file)
@@ -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);
 }