]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
gpt-auto-generator: use write_drop_in_format() helper and downgrade failure
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 28 Nov 2019 12:20:58 +0000 (13:20 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 30 Nov 2019 16:33:34 +0000 (17:33 +0100)
If we fail to write the timeout, let's not exit. (This might happen if another
generator writes the same dropin.) No need to make this fatal.

Since this is non-fatal now and the name doesn't need to be unique, let's make
the drop-in name shorter.

src/gpt-auto-generator/gpt-auto-generator.c

index 5f27edc9ee13359a9d07724ac504421e15e99d2c..99b5da17f5a2c52efaf6b3518e9a1730bd4c1690 100644 (file)
@@ -13,6 +13,7 @@
 #include "device-util.h"
 #include "dirent-util.h"
 #include "dissect-image.h"
+#include "dropin.h"
 #include "efi-loader.h"
 #include "fd-util.h"
 #include "fileio.h"
@@ -166,28 +167,25 @@ static int add_cryptsetup(const char *id, const char *what, bool rw, bool requir
         if (r < 0)
                 return r;
 
-        if (require) {
-                const char *dmname;
+        const char *dmname;
+        dmname = strjoina("dev-mapper-", e, ".device");
 
+        if (require) {
                 r = generator_add_symlink(arg_dest, "cryptsetup.target", "requires", n);
                 if (r < 0)
                         return r;
 
-                dmname = strjoina("dev-mapper-", e, ".device");
                 r = generator_add_symlink(arg_dest, dmname, "requires", n);
                 if (r < 0)
                         return r;
         }
 
-        p = strjoina(arg_dest, "/dev-mapper-", e, ".device.d/50-job-timeout-sec-0.conf");
-        mkdir_parents_label(p, 0755);
-        r = write_string_file(p,
-                        "# Automatically generated by systemd-gpt-auto-generator\n\n"
-                        "[Unit]\n"
-                        "JobTimeoutSec=0\n",
-                        WRITE_STRING_FILE_CREATE); /* the binary handles timeouts anyway */
+        r = write_drop_in_format(arg_dest, dmname, 50, "job-timeout",
+                                 "# Automatically generated by systemd-gpt-auto-generator\n\n"
+                                 "[Unit]\n"
+                                 "JobTimeoutSec=0"); /* the binary handles timeouts anyway */
         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, ignoring: %m");
 
         if (device) {
                 char *ret;