From 4827ab4854d3107d05b65194ac72729955fb3585 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Dec 2016 17:42:40 +0100 Subject: nspawn: when generating a machine name from an image name, truncate .raw suffix 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 035456f45b..9168228f4a 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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(); -- cgit v1.2.3-54-g00ecf