From 70e47aaa42a7f29ae5bc2df2bc21e57a1336cace Mon Sep 17 00:00:00 2001 From: Vojtech Trefny Date: Fri, 16 Oct 2026 16:07:36 +0200 Subject: [PATCH] crypto: Set libdevmapper logging in crypto plugin too The plugin doesn't use libdevmapper directly, but libcryptsetup uses it and with recent changes around logging and threads in libdevmapper, it is possible that libcryptsetup will fail to set up logging on their site (libdevmapper allows logging set up only from the main thread and in udisks all libcryptsetup calls run from separate threads) so we want to make sure that someone sets logging. We prefix all log messages so this shouldn't cause any confusion. --- configure.ac | 2 +- src/plugins/Makefile.am | 10 +++++----- src/plugins/crypto.c | 12 ++++++++++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index e5d65d8b2..2f00ba279 100644 --- a/configure.ac +++ b/configure.ac @@ -221,7 +221,7 @@ AS_IF([test "x$with_crypto" != "xno"], ], []) -AS_IF([test "x$with_dm" != "xno" -o "x$with_lvm" != "xno" -o "x$with_lvm_dbus" != "xno" -o "x$with_mpath" != "xno"], +AS_IF([test "x$with_crypto" != "xno" -o "x$with_dm" != "xno" -o "x$with_lvm" != "xno" -o "x$with_lvm_dbus" != "xno" -o "x$with_mpath" != "xno"], [LIBBLOCKDEV_PKG_CHECK_MODULES([DEVMAPPER], [devmapper >= 1.02.93])], []) diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am index 52e89597c..114cd2ef1 100644 --- a/src/plugins/Makefile.am +++ b/src/plugins/Makefile.am @@ -64,15 +64,15 @@ endif if WITH_CRYPTO if WITH_ESCROW -libbd_crypto_la_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS) $(CRYPTSETUP_CFLAGS) $(BLKID_CFLAGS) $(NSS_CFLAGS) -Wall -Wextra -Werror -libbd_crypto_la_LIBADD = ${builddir}/../utils/libbd_utils.la $(GLIB_LIBS) $(GIO_LIBS) $(CRYPTSETUP_LIBS) $(NSS_LIBS) $(BLKID_LIBS) -lkeyutils -lvolume_key +libbd_crypto_la_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS) $(CRYPTSETUP_CFLAGS) $(DEVMAPPER_CFLAGS) $(BLKID_CFLAGS) $(NSS_CFLAGS) -Wall -Wextra -Werror +libbd_crypto_la_LIBADD = ${builddir}/../utils/libbd_utils.la $(GLIB_LIBS) $(GIO_LIBS) $(CRYPTSETUP_LIBS) $(DEVMAPPER_LIBS) $(NSS_LIBS) $(BLKID_LIBS) -lkeyutils -lvolume_key else -libbd_crypto_la_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS) $(CRYPTSETUP_CFLAGS) $(BLKID_CFLAGS) -Wall -Wextra -Werror -libbd_crypto_la_LIBADD = ${builddir}/../utils/libbd_utils.la $(GLIB_LIBS) $(GIO_LIBS) $(CRYPTSETUP_LIBS) $(BLKID_LIBS) -lkeyutils +libbd_crypto_la_CFLAGS = $(GLIB_CFLAGS) $(GIO_CFLAGS) $(CRYPTSETUP_CFLAGS) $(DEVMAPPER_CFLAGS) $(BLKID_CFLAGS) -Wall -Wextra -Werror +libbd_crypto_la_LIBADD = ${builddir}/../utils/libbd_utils.la $(GLIB_LIBS) $(GIO_LIBS) $(CRYPTSETUP_LIBS) $(DEVMAPPER_LIBS) $(BLKID_LIBS) -lkeyutils endif libbd_crypto_la_LDFLAGS = -L${srcdir}/../utils/ -version-info 3:0:0 -Wl,--no-undefined -export-symbols-regex '^bd_.*' libbd_crypto_la_CPPFLAGS = -I${builddir}/../../include/ -libbd_crypto_la_SOURCES = crypto.c crypto.h +libbd_crypto_la_SOURCES = crypto.c crypto.h dm_logging.c dm_logging.h endif if WITH_DM diff --git a/src/plugins/crypto.c b/src/plugins/crypto.c index e801e30a3..b7004af34 100644 --- a/src/plugins/crypto.c +++ b/src/plugins/crypto.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -30,6 +31,7 @@ #include #include #include +#include #ifdef WITH_BD_ESCROW #include @@ -41,6 +43,7 @@ #endif #include "crypto.h" +#include "dm_logging.h" #ifdef __clang__ #define ZERO_INIT {} @@ -344,6 +347,13 @@ static void crypto_log_redirect (gint level, const gchar *msg, void *usrptr G_GN * */ gboolean bd_crypto_init (void) { + dm_log_with_errno_init ((dm_log_with_errno_fn) redirect_dm_log); +#ifdef DEBUG + dm_log_init_verbose (LOG_DEBUG); +#else + dm_log_init_verbose (LOG_INFO); +#endif + #ifdef DEBUG crypt_set_debug_level (CRYPT_DEBUG_ALL); #endif @@ -364,6 +374,8 @@ void bd_crypto_close (void) { c_locale = (locale_t) 0; crypt_set_log_callback (NULL, NULL, NULL); crypt_set_debug_level (CRYPT_DEBUG_NONE); + dm_log_with_errno_init (NULL); + dm_log_init_verbose (0); } /**