]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
cryptsetup-generator: unconfuse writing of the device timeout
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 3 Dec 2019 15:06:47 +0000 (16:06 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 3 Dec 2019 16:20:19 +0000 (17:20 +0100)
The code was using timeout=0 as the default option string. This option string
was ultimately passed to generator_write_timeouts(), which only looks for
comment=systemd.device-timeout= or x-systemd.device-timeout=, i.e. the whole
call path was bogus. Let's rework this: generator_write_timeouts() now writes
any timeouts if configured by the user. create_disk() writes out it's own
timeout, but with lower priority. Since the code path that was calling
timeout=0 was not effective, the only change is that we stop overwriting the
timeout if explicitly configured by the user.

In both code paths, ignore failure to write.

src/cryptsetup/cryptsetup-generator.c
src/shared/generator.c

index 811a9468c1757ccfbb619cdb11c66c41b97a995b..bf7a0fb2d54c7acbef0ec9b9ad9a1de7ef15812c 100644 (file)
@@ -362,7 +362,7 @@ static int create_disk(
 
         r = generator_write_timeouts(arg_dest, device, name, options, &filtered);
         if (r < 0)
-                return r;
+                log_warning_errno(r, "Failed to write device timeout drop-in: %m");
 
         if (filtered) {
                 filtered_escaped = specifier_escape(filtered);
@@ -415,11 +415,11 @@ static int create_disk(
                 return r;
 
         if (!noauto && !nofail) {
-                r = write_drop_in(arg_dest, dmname, 90, "device-timeout",
-                                  "# Automatically generated by systemd-cryptsetup-generator \n\n"
+                r = write_drop_in(arg_dest, dmname, 40, "device-timeout",
+                                  "# Automatically generated by systemd-cryptsetup-generator\n\n"
                                   "[Unit]\nJobTimeoutSec=0");
                 if (r < 0)
-                        return log_error_errno(r, "Failed to write device drop-in: %m");
+                        log_warning_errno(r, "Failed to write device timeout drop-in: %m");
         }
 
         return 0;
@@ -646,7 +646,6 @@ static int add_proc_cmdline_devices(void) {
         crypto_device *d;
 
         HASHMAP_FOREACH(d, arg_disks, i) {
-                const char *options;
                 _cleanup_free_ char *device = NULL;
 
                 if (!d->create)
@@ -662,14 +661,11 @@ static int add_proc_cmdline_devices(void) {
                 if (!device)
                         return log_oom();
 
-                if (d->options)
-                        options = d->options;
-                else if (arg_default_options)
-                        options = arg_default_options;
-                else
-                        options = "timeout=0";
-
-                r = create_disk(d->name, device, d->keyfile ?: arg_default_keyfile, d->keydev, options);
+                r = create_disk(d->name,
+                                device,
+                                d->keyfile ?: arg_default_keyfile,
+                                d->keydev,
+                                d->options ?: arg_default_options);
                 if (r < 0)
                         return r;
         }
index 5b571681f28469fb518ac871b1ab552824d34a27..06e1ab803125d342fc8db4569930b0e7001fc480 100644 (file)
@@ -237,10 +237,12 @@ int generator_write_timeouts(
                 return log_error_errno(r, "Failed to make unit name from path: %m");
 
         return write_drop_in_format(dir, unit, 50, "device-timeout",
-                                    "# Automatically generated by %s\n\n"
+                                    "# Automatically generated by %s\n"
+                                    "# from supplied options \"%s\"\n\n"
                                     "[Unit]\n"
                                     "JobRunningTimeoutSec=%s",
                                     program_invocation_short_name,
+                                    opts,
                                     timeout);
 }