diff options
author | Lennart Poettering <lennart@poettering.net> | 2022-12-21 16:48:25 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2022-12-23 15:04:19 +0100 |
commit | 451f0dba60b04c6a20a82e683ba117efa609b814 (patch) | |
tree | 0af63fbdae6eb9e4c27abae540baba5ec1fe74d6 /src/mount | |
parent | journalctl: port COMM= matching to path_extract_filename() (diff) | |
download | systemd-451f0dba60b04c6a20a82e683ba117efa609b814.tar.xz systemd-451f0dba60b04c6a20a82e683ba117efa609b814.zip |
mount-tool: port over basename() → path_extract_filename()
Diffstat (limited to 'src/mount')
-rw-r--r-- | src/mount/mount-tool.c | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/mount/mount-tool.c b/src/mount/mount-tool.c index f7dd705c5e..ea6d528189 100644 --- a/src/mount/mount-tool.c +++ b/src/mount/mount-tool.c @@ -1104,12 +1104,13 @@ static const char* get_label(sd_device *d) { static int acquire_mount_where(sd_device *d) { const char *v; + int r; if (arg_mount_where) return 0; if (sd_device_get_property_value(d, "SYSTEMD_MOUNT_WHERE", &v) < 0) { - _cleanup_free_ char *escaped = NULL; + _cleanup_free_ char *escaped = NULL, *devname_bn = NULL; const char *name; name = get_label(d); @@ -1121,7 +1122,11 @@ static int acquire_mount_where(sd_device *d) { if (sd_device_get_devname(d, &dn) < 0) return 0; - name = basename(dn); + r = path_extract_filename(dn, &devname_bn); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from '%s': %m", dn); + + name = devname_bn; } escaped = xescape(name, "\\"); @@ -1253,12 +1258,16 @@ static int discover_loop_backing_file(void) { return log_error_errno(errno, "Can't get loop device for %s: %m", arg_mount_what); if (r == -ENXIO) { - _cleanup_free_ char *escaped = NULL; + _cleanup_free_ char *escaped = NULL, *bn = NULL; if (arg_mount_where) return 0; - escaped = xescape(basename(arg_mount_what), "\\"); + r = path_extract_filename(arg_mount_what, &bn); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from backing file path '%s': %m", arg_mount_what); + + escaped = xescape(bn, "\\"); if (!escaped) return log_oom(); if (!filename_is_valid(escaped)) |