]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: change 'basename' to 'path_extract_filename'
authorJordan Rome <jordalgo@meta.com>
Thu, 25 May 2023 21:40:58 +0000 (14:40 -0700)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 26 May 2023 06:45:58 +0000 (15:45 +0900)
This is part of a cleanup effort in the TODO doc.

Tested locally: `meson compile -C build && meson test -C build`

src/core/load-fragment.c

index ebfe98d7cc9ab86dc718d77c39d56e21a9d4e4d0..554180f1e3152360c11d1f1b6a2ce59a37866cec 100644 (file)
@@ -6173,10 +6173,14 @@ int unit_load_fragment(Unit *u) {
          * declared in the file system. In particular, this is true (and frequent) for device and swap units.
          */
         const char *id = u->id;
-        _cleanup_free_ char *free_id = NULL;
+        _cleanup_free_ char *filename = NULL, *free_id = NULL;
 
         if (fragment) {
-                id = basename(fragment);
+                r = path_extract_filename(fragment, &filename);
+                if (r < 0)
+                        return log_debug_errno(r, "Failed to extract filename from fragment '%s': %m", fragment);
+                id = filename;
+
                 if (unit_name_is_valid(id, UNIT_NAME_TEMPLATE)) {
                         assert(u->instance); /* If we're not trying to use a template for non-instanced unit,
                                               * this must be set. */