]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: make sure --template= and --machine= my be combined 1039/head
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Aug 2015 18:26:51 +0000 (20:26 +0200)
committerLennart Poettering <lennart@poettering.net>
Tue, 25 Aug 2015 18:28:31 +0000 (20:28 +0200)
Fixes #1018.

Based on a patch from Seth Jennings.

src/nspawn/nspawn.c

index e8a023d023b6748f46ae1cc623d31eacafa5e5b3..837947ee285980e0742060b1a848ec4f5aca3b42 100644 (file)
@@ -559,9 +559,9 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case 'M':
-                        if (isempty(optarg)) {
+                        if (isempty(optarg))
                                 arg_machine = mfree(arg_machine);
-                        else {
+                        else {
                                 if (!machine_name_is_valid(optarg)) {
                                         log_error("Invalid machine name: %s", optarg);
                                         return -EINVAL;
@@ -4002,6 +4002,17 @@ static int on_orderly_shutdown(sd_event_source *s, const struct signalfd_siginfo
 static int determine_names(void) {
         int r;
 
+        if (arg_template && !arg_directory && arg_machine) {
+
+                /* If --template= was specified then we should not
+                 * search for a machine, but instead create a new one
+                 * in /var/lib/machine. */
+
+                arg_directory = strjoin("/var/lib/machines/", arg_machine, NULL);
+                if (!arg_directory)
+                        return log_oom();
+        }
+
         if (!arg_image && !arg_directory) {
                 if (arg_machine) {
                         _cleanup_(image_unrefp) Image *i = NULL;