From: Andrey Rys Date: Wed, 9 Aug 2023 18:12:10 +0000 (+0200) Subject: 51 broke -E logic completely, rewise it X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=HEAD;p=tfcrypt.git 51 broke -E logic completely, rewise it --- diff --git a/VERSION b/VERSION index 2bbd69c..39f5b69 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -70 +71 diff --git a/tfc_base64.c b/tfc_base64.c index b2edcbc..10b8f1a 100644 --- a/tfc_base64.c +++ b/tfc_base64.c @@ -36,8 +36,6 @@ void do_edbase64(char **fargv) struct base64_encodestate estate; size_t lread = 0; - xexit_no_nl = YES; - sfd = 0; dfd = 1; if (fargv[0]) { diff --git a/tfc_error.c b/tfc_error.c index 8e41482..b8cc432 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -28,8 +28,6 @@ #include "tfcrypt.h" -tfc_yesno xexit_no_nl; - void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *fmt, ...) { va_list ap; @@ -39,7 +37,7 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char * va_start(ap, fmt); - if (statline_was_shown == YES && do_statline_dynamic == YES) tfc_esay("\n"); + if (noexit == YES && (statline_was_shown == YES && do_statline_dynamic == YES)) tfc_esay("\n"); tfc_nfsay(stderr, "%s: ", tfc_format_pid(progname)); tfc_vfsay(stderr, NO, fmt, ap); @@ -52,12 +50,9 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char * va_end(ap); if (nostats == NO) { - print_crypt_status(-1); - tfc_esay("\n"); + print_crypt_status(TFC_SIGERR); } - xexit_no_nl = YES; - _do_sil_exit: if (noexit == YES) { errno = 0; @@ -102,7 +97,6 @@ _do_clean_and_exit: memset(pwdask, 0, sizeof(pwdask)); memset(pwdagain, 0, sizeof(pwdagain)); - if (xexit_no_nl == NO) tfc_esay("\n"); exit(status); } @@ -110,8 +104,6 @@ void usage(void) { tfc_yesno is_embedded_prog = NO; - xexit_no_nl = YES; - if (optopt == 'V') { tfc_say("tfcrypt toolkit, version %s.", _TFCRYPT_VERSION); if (do_edcrypt != TFC_DO_PLAIN) { diff --git a/tfc_random.c b/tfc_random.c index 99612d3..321f97a 100644 --- a/tfc_random.c +++ b/tfc_random.c @@ -30,15 +30,11 @@ static void print_crypt_status_genrnd(int signal) { - if (signal == SIGTERM || signal == SIGINT) { - if (xexit_no_nl == YES) xexit_no_nl = NO; - } print_crypt_status(signal); } static void exit_sigterm_genrnd(int signal) { - if (xexit_no_nl == YES) xexit_no_nl = NO; exit_sigterm(signal); } @@ -102,8 +98,6 @@ void gen_write_bytes(const char *foutname, tfc_fsize offset, tfc_fsize nrbytes) size_t lblock, lio, lrem; tfc_byte *pblk; - xexit_no_nl = YES; - for (x = 1; x < NSIG; x++) signal(x, SIG_IGN); memset(&sigact, 0, sizeof(sigact)); sigact.sa_flags = SA_RESTART; @@ -195,7 +189,7 @@ _wagain: lio = xwrite(fd, pblk, lrem); if (verbose) tfc_esay("done!"); if (verbose || status_timer) { - print_crypt_status(0); + print_crypt_status(TFC_SIGSTAT); tfc_esay("\n"); } diff --git a/tfc_signal.c b/tfc_signal.c index aaacb2b..a81aa1e 100644 --- a/tfc_signal.c +++ b/tfc_signal.c @@ -30,6 +30,7 @@ void exit_sigterm(int signal) { + tfc_esay("\n"); xexit(0); } @@ -55,10 +56,9 @@ void print_crypt_status(int signal) tfc_yesno finished = NO; if (last == YES) return; - if (signal <= 0) { + if (signal == TFC_SIGLAST) { + last = YES; finished = YES; - do_stop = YES; /* error path or sksum finished */ - if (signal == 0) last = YES; } switch (do_edcrypt) { @@ -130,6 +130,7 @@ void print_crypt_status(int signal) } if (do_stop == NO && do_statline_dynamic == NO) tfc_esay("\n"); + else if (signal == TFC_SIGLAST || signal == TFC_SIGERR) tfc_esay("\n"); statline_was_shown = YES; if ((signal == SIGINT || signal == SIGTERM) && do_stop == YES) exit_sigterm(signal); diff --git a/tfc_skein.c b/tfc_skein.c index 7886c2b..a368578 100644 --- a/tfc_skein.c +++ b/tfc_skein.c @@ -31,7 +31,6 @@ static void exit_sigterm_skein(int signal) { - if (xexit_no_nl == YES) xexit_no_nl = NO; exit_sigterm(signal); } @@ -118,7 +117,7 @@ _again: lio = xread(fd, pblk, lrem); skein_final(hash, &sk); if (ctr_mode == TFC_MODE_SKSUM) { if (verbose || status_timer) { - print_crypt_status(-1); + print_crypt_status(TFC_SIGSTAT); tfc_esay("\n"); } total_processed_src = total_processed_dst = delta_processed = 0; @@ -141,8 +140,6 @@ void do_sksum(char *spec, char **fargv) int x = 0, xx; size_t bits; - xexit_no_nl = YES; - if (macbits < TF_MAX_BITS) { bits = macbits; goto _dothat; diff --git a/tfcrypt.c b/tfcrypt.c index 9e0e629..590cb33 100644 --- a/tfcrypt.c +++ b/tfcrypt.c @@ -643,7 +643,6 @@ _baddfname: break; case 'q': quiet = YES; - xexit_no_nl = YES; verbose = NO; do_full_hexdump = NO; status_timer = 0; @@ -1474,7 +1473,7 @@ _macwagain: lio = xwrite(dfd, pblk, lrem); } else if (do_mac == TFC_MAC_DROP2) total_processed_src += SKEIN_DIGEST_SIZE; - if (verbose || status_timer || (do_stop == YES && quiet == NO)) print_crypt_status(0); + if (verbose || status_timer || (do_stop == YES && quiet == NO)) print_crypt_status(TFC_SIGLAST); xexit(exitcode); return -1; diff --git a/tfcrypt.h b/tfcrypt.h index 2dd2c68..acc31df 100644 --- a/tfcrypt.h +++ b/tfcrypt.h @@ -170,8 +170,6 @@ extern struct getpasswd_state getps; size_t xread(int fd, void *data, size_t szdata); size_t xwrite(int fd, const void *data, size_t szdata); -extern tfc_yesno xexit_no_nl; - void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char *fmt, ...); void xexit(int status); void usage(void); @@ -238,5 +236,6 @@ enum { }; enum { TFC_CTR_SHOW = 1, TFC_CTR_HEAD, TFC_CTR_RAND, TFC_CTR_ZERO, TFC_CTR_SSET }; enum { TFC_NO_FTRUNC, TFC_DO_FTRUNC, TFC_FTRUNC_TAIL }; +enum { TFC_SIGLAST = -2, TFC_SIGERR = -1, TFC_SIGSTAT = 0 }; #endif