From: Andrey Rys Date: Sun, 28 Nov 2021 00:53:56 +0000 (+0100) Subject: -o logfile: logging to separate logfile instead of stderr. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=cd6f1f9a84c17dbdf6ab320a04eae300502b898d;p=tfcrypt.git -o logfile: logging to separate logfile instead of stderr. --- diff --git a/VERSION b/VERSION index 920a139..c739b42 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -43 +44 diff --git a/tfc_error.c b/tfc_error.c index 3d95eba..f69fdbe 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -298,6 +298,7 @@ void usage(void) tfc_say(" -E xall: turn on error actions above for all errors, not just EIO errors."); tfc_say(" -E xseek: ignore positioning and other seek related errors."); tfc_say(" Multiple -E specifiers may be given in separate options."); + tfc_say(" -o logfile: redirect all messages to logfile instead of stderr."); tfc_say(" -O opts: set options (comma separated list):"); tfc_say(" sync: request a synchronous I/O for a output,"); tfc_say(" fsync: on each write() call a corresponding fsync(fd),"); @@ -315,6 +316,7 @@ void usage(void) tfc_say(" prompt=str: set main password prompts to this string."); tfc_say(" macprompt=str: set MAC password prompts to this string."); tfc_say(" shorthex: with -H, do not print printable characters, dump only hex string."); + tfc_say(" logfile: (same as -o) redirect all messages to logfile instead of stderr."); tfc_say(" iobs=val: set IO block size value. Must not exceed %u bytes.", TFC_U(TFC_BLKSIZE)); tfc_say(" xtsblocks=val: use these nr of TF blocks per XTS block. Default is %u.", TFC_U(TFC_XTSBLOCKS)); tfc_say(" iseek=val: seek source file/device by these val bytes."); diff --git a/tfcrypt.c b/tfcrypt.c index 719eff8..b6bbe73 100644 --- a/tfcrypt.c +++ b/tfcrypt.c @@ -30,6 +30,18 @@ static tfc_byte svctr[TF_BLOCK_SIZE]; +static void open_log(const char *logfile) +{ + int fd; + + fd = open(logfile, O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC, 0666); + if (fd == -1) xerror(NO, NO, YES, "%s", logfile); + xclose(2); + if (dup2(fd, 2) == -1) xerror(NO, NO, YES, "dup2(%d, 2) for %s", fd, logfile); + xclose(fd); + do_statline_dynamic = NO; +} + static int getps_filter(struct getpasswd_state *getps, char chr, size_t pos) { if (chr == '\x03') { @@ -138,7 +150,7 @@ _baddfname: } opterr = 0; - while ((c = getopt(argc, argv, "L:s:aU:C:r:K:t:Pkzxc:l:qedn:vV:pwE:O:S:AmuM:R:Z:WHD:")) != -1) { + while ((c = getopt(argc, argv, "L:s:aU:C:r:K:t:Pkzxc:l:qedn:vV:pwE:o:O:S:AmuM:R:Z:WHD:")) != -1) { switch (c) { case 'L': read_defaults(optarg, NO); @@ -285,6 +297,9 @@ _baddfname: error_action = TFC_ERRACT_LSYNC; else xerror(NO, YES, YES, "invalid error action %s specified", optarg); break; + case 'o': + open_log(optarg); + break; case 'O': s = d = optarg; t = NULL; while ((s = strtok_r(d, ",", &t))) { @@ -317,6 +332,8 @@ _baddfname: do_full_key = YES; else if (!strcmp(s, "showsecrets")) show_secrets = YES; + else if (!strncmp(s, "logfile", 7) && *(s+7) == '=') + open_log(s+8); else if (!strncmp(s, "iobs", 4) && *(s+4) == '=') { s += 5; blksize = (size_t)tfc_humanfsize(s, &stoi);