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.
This commit is contained in:
Lennart Poettering 2016-12-07 17:42:40 +01:00
parent 18b5886e56
commit 4827ab4854

View 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();