Define log callback function to use with libcryptsetup

Logs from libcryptsetup now go to stderr and this prevents issues like
the one reported in https://bugzilla.redhat.com/show_bug.cgi?id=1770395

Backport of upstream PR#12: https://github.com/latchset/luksmeta/pull/12
This commit is contained in:
Sergio Correia 2019-12-31 16:10:48 -03:00
parent 8041897aca
commit f180fbf71d
2 changed files with 55 additions and 3 deletions

View File

@ -0,0 +1,45 @@
From 70247ce7e47963bfbd6c4cdc584f35ca38ccf66d Mon Sep 17 00:00:00 2001
From: Sergio Correia <scorreia@redhat.com>
Date: Mon, 11 Nov 2019 18:06:13 -0500
Subject: [PATCH] Define log callback function to use with libcryptsetup
Logs from libcryptsetup now go to stderr and this prevents issues like
the one reported in https://bugzilla.redhat.com/show_bug.cgi?id=1770395
---
luksmeta.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
diff --git a/luksmeta.c b/luksmeta.c
index a79da82..1c72787 100644
--- a/luksmeta.c
+++ b/luksmeta.c
@@ -45,6 +45,17 @@ struct options {
int slot;
};
+#define LUKSMETA_LIBCRYPTSETUP_LOG_LEVEL CRYPT_LOG_ERROR
+
+static void
+luksmeta_libcryptsetup_log(int level, const char *msg, void *usrptr)
+{
+ if (level != LUKSMETA_LIBCRYPTSETUP_LOG_LEVEL) {
+ return;
+ }
+ fprintf(stderr, "%s", msg);
+}
+
static int
cmd_test(const struct options *opts, struct crypt_device *cd)
{
@@ -485,6 +496,8 @@ main(int argc, char *argv[])
return EX_IOERR;
}
+ crypt_set_log_callback(cd, luksmeta_libcryptsetup_log, NULL);
+
r = crypt_load(cd, NULL, NULL);
if (r != 0) {
fprintf(stderr, "Unable to read LUKSv1 header (%s): %s\n",
--
2.23.0

View File

@ -1,13 +1,15 @@
Name: luksmeta
Version: 9
Release: 5%{?dist}
Release: 6%{?dist}
Summary: Utility for storing small metadata in the LUKSv1 header
License: LGPLv2+
URL: https://github.com/latchset/%{name}
Source0: https://github.com/latchset/%{name}/releases/download/v%{version}/%{name}-%{version}.tar.bz2
Patch0: luksmeta-9-tests.patch
Patch1: luksmeta-9-relax-layout-assumptions.patch
Patch01: luksmeta-9-tests.patch
Patch02: luksmeta-9-relax-layout-assumptions.patch
Patch03: Define-log-callback-function-to-use-with-libcryptset.patch
BuildRequires: gcc
BuildRequires: asciidoc
@ -65,6 +67,11 @@ make %{?_smp_mflags} check
%{_libdir}/pkgconfig/luksmeta.pc
%changelog
* Tue Dec 31 2019 Sergio Correia <scorreia@redhat.com> - 9-6
- Define log callback function to use with libcryptsetup
Logs from libcryptsetup now go to stderr and this prevents issues like
the one reported in https://bugzilla.redhat.com/show_bug.cgi?id=1770395
* Thu Jul 25 2019 Fedora Release Engineering <releng@fedoraproject.org> - 9-5
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild