chiark / gitweb /
getty: move automatic serial getty logic into generator
[elogind.git] / src / cryptsetup-generator.c
index 3c3b99d..00f4800 100644 (file)
@@ -98,11 +98,11 @@ 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\n"
+                "BindTo=%s dev-mapper-%%i.device\n"
                 "After=systemd-readahead-collect.service systemd-readahead-replay.service %s\n"
-                "Before=dev-mapper-%%i.device shutdown.target\n",
+                "Before=dev-mapper-%%i.device shutdown.target cryptsetup.target\n",
                 d, d);
 
         if (password && (streq(password, "/dev/urandom") ||
@@ -122,13 +122,13 @@ static int create_disk(
 
         if (options && has_option(options, "tmp"))
                 fprintf(f,
-                        "ExecStartPost=/sbin/mke2fs '%s'",
-                        u);
+                        "ExecStartPost=/sbin/mke2fs '/dev/mapper/%s'",
+                        name);
 
         if (options && has_option(options, "swap"))
                 fprintf(f,
-                        "ExecStartPost=/sbin/mkswap '%s'",
-                        u);
+                        "ExecStartPost=/sbin/mkswap '/dev/mapper/%s'",
+                        name);
 
         fflush(f);
 
@@ -157,13 +157,32 @@ static int create_disk(
                         r = -errno;
                         goto fail;
                 }
+
+                free(to);
+                to = NULL;
+
+                if (!options || !has_option(options, "nofail")) {
+
+                        if (asprintf(&to, "%s/cryptsetup.target.wants/%s", arg_dest, n) < 0) {
+                                r = -ENOMEM;
+                                goto fail;
+                        }
+
+                        mkdir_parents(to, 0755);
+
+                        if (symlink(from, to) < 0) {
+                                log_error("Failed to create symlink '%s' to '%s': %m", from, to);
+                                r = -errno;
+                                goto fail;
+                        }
+                }
         }
 
         free(to);
         to = NULL;
 
         e = unit_name_escape(name);
-        if (asprintf(&to, "%s/dev-mapper-%s.device.wants/%s", arg_dest, e, n) < 0) {
+        if (asprintf(&to, "%s/dev-mapper-%s.device.requires/%s", arg_dest, e, n) < 0) {
                 r = -ENOMEM;
                 goto fail;
         }
@@ -203,7 +222,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();