chiark / gitweb /
hostnamed: introduce systemd-hostnamed
[elogind.git] / src / cryptsetup-generator.c
index c5e54d0988270a8d657fab064fbc03f71c89b460..f7c3f23f5e7cda669e6cb48da2b46340fa3eb6a3 100644 (file)
@@ -33,6 +33,11 @@ static bool has_option(const char *haystack, const char *needle) {
         const char *f = haystack;
         size_t l;
 
+        assert(needle);
+
+        if (!haystack)
+                return false;
+
         l = strlen(needle);
 
         while ((f = strstr(f, needle))) {
@@ -98,7 +103,7 @@ static int create_disk(
 
         fprintf(f,
                 "[Unit]\n"
-                "Description=Cryptography Setup for %%f\n"
+                "Description=Cryptography Setup for %%I\n"
                 "DefaultDependencies=no\n"
                 "BindTo=%s dev-mapper-%%i.device\n"
                 "After=systemd-readahead-collect.service systemd-readahead-replay.service %s\n"
@@ -115,20 +120,21 @@ static int create_disk(
                 "\n[Service]\n"
                 "Type=oneshot\n"
                 "RemainAfterExit=yes\n"
+                "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);
 
-        if (options && has_option(options, "tmp"))
+        if (has_option(options, "tmp"))
                 fprintf(f,
-                        "ExecStartPost=/sbin/mke2fs '%s'",
-                        u);
+                        "ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'\n",
+                        name);
 
-        if (options && has_option(options, "swap"))
+        if (has_option(options, "swap"))
                 fprintf(f,
-                        "ExecStartPost=/sbin/mkswap '%s'",
-                        u);
+                        "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'\n",
+                        name);
 
         fflush(f);
 
@@ -143,7 +149,7 @@ static int create_disk(
                 goto fail;
         }
 
-        if (!options || !has_option(options, "noauto")) {
+        if (!has_option(options, "noauto")) {
 
                 if (asprintf(&to, "%s/%s.wants/%s", arg_dest, d, n) < 0) {
                         r = -ENOMEM;
@@ -161,7 +167,7 @@ static int create_disk(
                 free(to);
                 to = NULL;
 
-                if (!options || !has_option(options, "nofail")) {
+                if (!has_option(options, "nofail")) {
 
                         if (asprintf(&to, "%s/cryptsetup.target.wants/%s", arg_dest, n) < 0) {
                                 r = -ENOMEM;
@@ -222,7 +228,8 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        arg_dest = argv[1];
+        if (argc > 1)
+                arg_dest = argv[1];
 
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
         log_parse_environment();