]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
nspawn: when generating a machine name from an image name, truncate .raw suffix
authorLennart Poettering <lennart@poettering.net>
Wed, 7 Dec 2016 16:42:40 +0000 (17:42 +0100)
committerLennart Poettering <lennart@poettering.net>
Wed, 7 Dec 2016 17:38:41 +0000 (18:38 +0100)
Let's prettify the machine name we generate for image-based containers: let's
chop off the .raw suffix before using it as machine name.

src/nspawn/nspawn.c

index 035456f45be71d39d488548242accd77b85dab3b..9168228f4a5551702dc6c13e24b06b9b20cb77f4 100644 (file)
@@ -1951,10 +1951,22 @@ static int determine_names(void) {
         }
 
         if (!arg_machine) {
+
                 if (arg_directory && path_equal(arg_directory, "/"))
                         arg_machine = gethostname_malloc();
-                else
-                        arg_machine = strdup(basename(arg_image ?: arg_directory));
+                else {
+                        if (arg_image) {
+                                char *e;
+
+                                arg_machine = strdup(basename(arg_image));
+
+                                /* Truncate suffix if there is one */
+                                e = endswith(arg_machine, ".raw");
+                                if (e)
+                                        *e = 0;
+                        } else
+                                arg_machine = strdup(basename(arg_directory));
+                }
                 if (!arg_machine)
                         return log_oom();