SHA256
1
0
forked from pool/cryptsetup
cryptsetup/cryptsetup-luks-libnostderr.diff

48 lines
1.8 KiB
Diff
Raw Normal View History

use set_error instead of printf in library to report errors.
From: Ludwig Nussel <ludwig.nussel@suse.de>
Signed-off-by: Ludwig Nussel <ludwig.nussel@suse.de>
---
lib/utils.c | 2 +-
luks/keyencryption.c | 5 +++--
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/lib/utils.c b/lib/utils.c
index fbf34bc..b9fc006 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -227,7 +227,7 @@ ssize_t read_blockwise(int fd, void *orig_buf, size_t count) {
while(count) {
r = read(fd,padbuf,bsize);
if(r < 0 || r != bsize) {
- fprintf(stderr, "read failed in read_blockwise.\n");
+ set_error("read failed in read_blockwise()");
goto out;
}
step = count<bsize?count:bsize;
diff --git a/luks/keyencryption.c b/luks/keyencryption.c
index f154a01..de02f50 100644
--- a/luks/keyencryption.c
+++ b/luks/keyencryption.c
@@ -58,7 +58,7 @@ static int setup_mapping(const char *cipher, const char *name,
* device's sector size, otherwise the mapping will be refused.
*/
if(device_sector_size < 0) {
- fprintf(stderr,_("Unable to obtain sector size for %s"),device);
+ set_error(_("Unable to obtain sector size for %s"),device);
return -EINVAL;
}
options->size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
@@ -138,7 +138,8 @@ static int LUKS_endec_template(char *src, size_t srcLength,
r = setup_mapping(dmCipherSpec,name,device,hdr->payloadOffset,key,keyLength,sector,srcLength,backend,mode);
if(r < 0) {
- fprintf(stderr,"Failed to setup dm-crypt key mapping.\nCheck kernel for support for the %s cipher spec and verify that %s contains at least %d sectors.\n",
+ if(!get_error())
+ set_error("Failed to setup dm-crypt key mapping.\nCheck kernel for support for the %s cipher spec and verify that %s contains at least %d sectors",
dmCipherSpec,
device,
sector + div_round_up(srcLength,SECTOR_SIZE));