summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nspawn/nspawn-util.c6
-rw-r--r--src/nspawn/nspawn.c13
2 files changed, 13 insertions, 6 deletions
diff --git a/src/nspawn/nspawn-util.c b/src/nspawn/nspawn-util.c
index 830ac39e73..6c3848916d 100644
--- a/src/nspawn/nspawn-util.c
+++ b/src/nspawn/nspawn-util.c
@@ -47,10 +47,14 @@ int systemd_installation_has_version(const char *root, const char *minimal_versi
*c = '\0'; /* truncate the glob part */
STRV_FOREACH(name, names) {
+ _cleanup_free_ char *bn = NULL;
/* This is most likely to run only once, hence let's not optimize anything. */
char *t, *t2;
- t = startswith(basename(*name), "libsystemd-shared-");
+ if (path_extract_filename(*name, &bn) < 0)
+ continue;
+
+ t = startswith(bn, "libsystemd-shared-");
if (!t)
continue;
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 067efbe3f0..551f8f975c 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -3045,16 +3045,19 @@ static int determine_names(void) {
else if (arg_image) {
char *e;
- arg_machine = strdup(basename(arg_image));
+ r = path_extract_filename(arg_image, &arg_machine);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract file name from '%s': %m", 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();
+ } else {
+ r = path_extract_filename(arg_directory, &arg_machine);
+ if (r < 0)
+ return log_error_errno(r, "Failed to extract file name from '%s': %m", arg_directory);
+ }
hostname_cleanup(arg_machine);
if (!hostname_is_valid(arg_machine, 0))