Skip to content

Commit

Permalink
Define log callback function to use with libcryptsetup
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sergio-correia committed Nov 13, 2019
1 parent dc5601b commit 7193022
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions luksmeta.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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",
Expand Down

0 comments on commit 7193022

Please sign in to comment.