From: Lennart Poettering Date: Wed, 21 Dec 2022 15:50:18 +0000 (+0100) Subject: repart/makefs: port over to path_extract_filename() X-Git-Tag: v253-rc1~214^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7b2ffb593e57b4e3e13de06f0ce382bdd19d37cc;p=thirdparty%2Fsystemd.git repart/makefs: port over to path_extract_filename() --- diff --git a/src/partition/makefs.c b/src/partition/makefs.c index 3f54bbb0da0..2733763eb2f 100644 --- a/src/partition/makefs.c +++ b/src/partition/makefs.c @@ -13,12 +13,13 @@ #include "fd-util.h" #include "main-func.h" #include "mkfs-util.h" +#include "path-util.h" #include "process-util.h" #include "signal-util.h" #include "string-util.h" static int run(int argc, char *argv[]) { - _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL; + _cleanup_free_ char *device = NULL, *fstype = NULL, *detected = NULL, *label = NULL; _cleanup_close_ int lock_fd = -EBADF; sd_id128_t uuid; struct stat st; @@ -65,7 +66,11 @@ static int run(int argc, char *argv[]) { if (r < 0) return log_error_errno(r, "Failed to generate UUID for file system: %m"); - return make_filesystem(device, fstype, basename(device), NULL, uuid, true, NULL); + r = path_extract_filename(device, &label); + if (r < 0) + return log_error_errno(r, "Failed to extract file name from '%s': %m", device); + + return make_filesystem(device, fstype, label, NULL, uuid, true, NULL); } DEFINE_MAIN_FUNCTION(run); diff --git a/src/partition/repart.c b/src/partition/repart.c index 71018a79cc8..6feb6ca2a19 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -2580,10 +2580,8 @@ static int partition_hint(const Partition *p, const char *node, char **ret) { /* Tries really hard to find a suitable description for this partition */ - if (p->definition_path) { - buf = strdup(basename(p->definition_path)); - goto done; - } + if (p->definition_path) + return path_extract_filename(p->definition_path, ret); label = partition_label(p); if (!isempty(label)) {