]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mount-tool: port over basename() → path_extract_filename()
authorLennart Poettering <lennart@poettering.net>
Wed, 21 Dec 2022 15:48:25 +0000 (16:48 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 23 Dec 2022 14:04:19 +0000 (15:04 +0100)
src/mount/mount-tool.c

index f7dd705c5e6865b2844b7c7a2defbb9bbf27987e..ea6d528189a10c13f82d34a38b62a8c923c279f9 100644 (file)
@@ -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))