From: Mike Yuan Date: Sat, 6 Sep 2025 15:23:27 +0000 (+0200) Subject: cryptsetup: port from setmntent() to libmount parser X-Git-Tag: v259-rc1~501^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=69fa2b63038f74285df7d37c7c2ab9f7a43b5102;p=thirdparty%2Fsystemd.git cryptsetup: port from setmntent() to libmount parser --- diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c index 357ee786954..c7897a2f208 100644 --- a/src/cryptsetup/cryptsetup.c +++ b/src/cryptsetup/cryptsetup.c @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: LGPL-2.1-or-later */ #include -#include #include #include #include @@ -33,6 +32,7 @@ #include "hexdecoct.h" #include "json-util.h" #include "libfido2-util.h" +#include "libmount-util.h" #include "log.h" #include "main-func.h" #include "memory-util.h" @@ -732,26 +732,37 @@ static char* disk_description(const char *path) { return NULL; } -static char *disk_mount_point(const char *label) { +static char* disk_mount_point(const char *label) { + _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL; + _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL; _cleanup_free_ char *device = NULL; - _cleanup_endmntent_ FILE *f = NULL; - struct mntent *m; + int r; /* Yeah, we don't support native systemd unit files here for now */ + assert(label); + device = strjoin("/dev/mapper/", label); if (!device) return NULL; - f = setmntent(fstab_path(), "re"); - if (!f) + r = libmount_parse_fstab(&table, &iter); + if (r < 0) return NULL; - while ((m = getmntent(f))) - if (path_equal(m->mnt_fsname, device)) - return strdup(m->mnt_dir); + for (;;) { + struct libmnt_fs *fs; - return NULL; + r = mnt_table_next_fs(table, iter, &fs); + if (r != 0) + return NULL; + + if (path_equal(mnt_fs_get_source(fs), device)) { + const char *target = mnt_fs_get_target(fs); + if (target) + return strdup(target); + } + } } static char *friendly_disk_name(const char *src, const char *vol) { diff --git a/src/cryptsetup/meson.build b/src/cryptsetup/meson.build index c2f4dc90653..cb47fd94172 100644 --- a/src/cryptsetup/meson.build +++ b/src/cryptsetup/meson.build @@ -19,6 +19,7 @@ executables += [ 'sources' : systemd_cryptsetup_sources, 'dependencies' : [ libcryptsetup, + libmount, libopenssl, libp11kit_cflags, ],