1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-06 13:17:44 +03:00

nspawn: port over basename() → path_extract_filename()

This commit is contained in:
Lennart Poettering 2022-12-21 16:49:03 +01:00
parent 451f0dba60
commit b36e39d2eb
2 changed files with 13 additions and 6 deletions

View File

@ -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;

View File

@ -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))