summaryrefslogtreecommitdiff
path: root/src/nspawn
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-12-07 17:42:40 +0100
committerLennart Poettering <lennart@poettering.net>2016-12-07 18:38:41 +0100
commit4827ab4854d3107d05b65194ac72729955fb3585 (patch)
tree356587b861abff5269330e5dec9a1f7ae83b68fd /src/nspawn
parent18b5886e562a3702ed8923e568a7555d2ab1880a (diff)
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.
Diffstat (limited to 'src/nspawn')
-rw-r--r--src/nspawn/nspawn.c16
1 files 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();