From: Andrey Rys Date: Sun, 28 Nov 2021 13:36:30 +0000 (+0100) Subject: change atexit newline print policy X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=e16562d4f4180c1364181c92d6d8f285f322f12c;p=tfcrypt.git change atexit newline print policy --- diff --git a/VERSION b/VERSION index e373ee6..82cced2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -50 +51 diff --git a/tfc_base64.c b/tfc_base64.c index c76fdd9..68f0677 100644 --- a/tfc_base64.c +++ b/tfc_base64.c @@ -36,6 +36,8 @@ void do_edbase64(char **fargv) struct base64_encodestate estate; size_t lread = 0; + xexit_no_nl = YES; + sfd = 0; dfd = 1; if (fargv[0]) { @@ -148,7 +150,6 @@ _wagain: lio = xwrite(dfd, pblk, lrem); memset(&estate, 0, sizeof(struct base64_encodestate)); memset(&dstate, 0, sizeof(struct base64_decodestate)); - if (do_preserve_time) fcopy_matime(dfd, &s_stat); xexit(0); } diff --git a/tfc_error.c b/tfc_error.c index 9bface1..ad14e7d 100644 --- a/tfc_error.c +++ b/tfc_error.c @@ -28,12 +28,14 @@ #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; char *s; - if (quiet) goto _ex; + if (quiet) goto _do_sil_exit; va_start(ap, fmt); @@ -49,9 +51,14 @@ void xerror(tfc_yesno noexit, tfc_yesno noerrno, tfc_yesno nostats, const char * va_end(ap); - if (nostats == NO) print_crypt_status(-1); + if (nostats == NO) { + print_crypt_status(-1); + tfc_esay("\n"); + } + + xexit_no_nl = YES; -_ex: +_do_sil_exit: if (noexit == YES) { errno = 0; return; @@ -64,15 +71,16 @@ void xexit(int status) { if (status > 1) goto _do_clean_and_exit; - xclose(sfd); if (do_ftrunc > TFC_NO_FTRUNC) { if (do_ftrunc == TFC_FTRUNC_TAIL) ftrunc_dfd = total_processed_dst; if (ftruncate(dfd, (off_t)ftrunc_dfd) == -1) xerror(YES, NO, YES, "ftruncate(%d)", dfd); } if (do_preserve_time) fcopy_matime(dfd, &s_stat); - xclose(dfd); _do_clean_and_exit: + xclose(sfd); + xclose(dfd); + memset(srcblk, 0, sizeof(srcblk)); memset(dstblk, 0, sizeof(dstblk)); @@ -94,6 +102,7 @@ _do_clean_and_exit: memset(pwdask, 0, sizeof(pwdask)); memset(pwdagain, 0, sizeof(pwdagain)); + if (xexit_no_nl == NO) tfc_esay("\n"); exit(status); } @@ -101,6 +110,8 @@ 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 (ctr_mode != TFC_MODE_PLAIN) { diff --git a/tfc_random.c b/tfc_random.c index 9f9105a..d3f2ee3 100644 --- a/tfc_random.c +++ b/tfc_random.c @@ -88,6 +88,8 @@ 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; @@ -180,6 +182,7 @@ _wagain: lio = xwrite(fd, pblk, lrem); if (verbose) tfc_esay("done!"); if (verbose || status_timer) print_crypt_status(0); + if (verbose) tfc_esay("\n"); xclose(fd); xexit(0); diff --git a/tfc_signal.c b/tfc_signal.c index 25d765e..1e02534 100644 --- a/tfc_signal.c +++ b/tfc_signal.c @@ -52,9 +52,14 @@ void print_crypt_status(int signal) int src_scale_idx, dst_scale_idx, wri_scale_idx, wr_speed_scale; const char *oper_mode, *inplace; static tfc_yesno last; + tfc_yesno finished = NO; if (last == YES) return; - if (signal == 0 || signal == -1) last = YES; + if (signal <= 0) { + finished = YES; + do_stop = YES; /* error path or sksum finished */ + if (signal == 0) last = YES; + } switch (do_edcrypt) { case TFC_DO_ENCRYPT: oper_mode = "encrypted"; break; @@ -87,7 +92,6 @@ void print_crypt_status(int signal) oper_mode, total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx), wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), seconds); - tfc_esay("\n"); xexit(0); } @@ -98,7 +102,7 @@ void print_crypt_status(int signal) tfc_nfsay(stderr, "%s%s%s:" " %s %.2f%s," " %.2f%s B/s @%s", - inplace, (last && show_when_done) ? "finished: " : "", tfc_format_pid(progname), + inplace, (finished && show_when_done) ? "finished: " : "", tfc_format_pid(progname), oper_mode, human_totalproc_dst, tfc_getscale(dst_scale_idx), human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time)); @@ -107,7 +111,7 @@ void print_crypt_status(int signal) if (ctr_mode <= TFC_MODE_PLAIN) tfc_nfsay(stderr, "%s%s%s: read: %llu (%.2f%s)," " %s %llu (%.2f%s) bytes," " (%llu (%.2f%s) B/s), time %s", - inplace, (last && show_when_done) ? "finished: " : "", tfc_format_pid(progname), + inplace, (finished && show_when_done) ? "finished: " : "", tfc_format_pid(progname), total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx), oper_mode, total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx), @@ -116,7 +120,7 @@ void print_crypt_status(int signal) " %s %s %llu (%.2f%s) bytes," " written %llu (%.2f%s) bytes," " (%llu (%.2f%s) B/s), time %s", - inplace, (last && show_when_done) ? "finished: " : "", tfc_format_pid(progname), + inplace, (finished && show_when_done) ? "finished: " : "", tfc_format_pid(progname), total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx), tfc_modename(ctr_mode), oper_mode, total_processed_dst, human_totalproc_dst, tfc_getscale(dst_scale_idx), @@ -125,13 +129,9 @@ void print_crypt_status(int signal) } if (do_stop == NO && do_statline_dynamic == NO) tfc_esay("\n"); - if (last) tfc_esay("\n"); statline_was_shown = YES; - if ((signal == SIGINT || signal == SIGTERM) && do_stop == YES) { - tfc_esay("\n"); - exit_sigterm(signal); - } + if ((signal == SIGINT || signal == SIGTERM) && do_stop == YES) exit_sigterm(signal); delta_processed = 0; tfc_getcurtime(&delta_time); diff --git a/tfc_skein.c b/tfc_skein.c index 58cd36e..e2c31f9 100644 --- a/tfc_skein.c +++ b/tfc_skein.c @@ -47,7 +47,6 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize of tfc_byte *pblk; size_t ldone, lblock, lrem, lio; tfc_fsize total = 0; - tfc_yesno stop; if (ctr_mode == TFC_MODE_SKSUM) total_processed_src = total_processed_dst = delta_processed = 0; @@ -68,15 +67,15 @@ tfc_yesno skeinfd(void *hash, size_t bits, const void *key, int fd, tfc_fsize of else skein_init(&sk, bits); errno = 0; - stop = NO; + do_stop = NO; while (1) { - if (stop) break; + if (do_stop) break; pblk = skblk; lblock = lrem = blk_len_adj(readto, total, TFC_BLKSIZE); ldone = 0; if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(fd); _again: lio = xread(fd, pblk, lrem); - if (lio == 0) stop = YES; + if (lio == 0) do_stop = YES; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) goto _fail; @@ -112,7 +111,10 @@ _again: lio = xread(fd, pblk, lrem); skein_final(hash, &sk); if (ctr_mode == TFC_MODE_SKSUM) { - if (verbose || status_timer) print_crypt_status(-1); + if (verbose || status_timer) { + print_crypt_status(-1); + tfc_esay("\n"); + } total_processed_src = total_processed_dst = delta_processed = 0; } memset(skblk, 0, TFC_BLKSIZE); @@ -133,6 +135,8 @@ 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 dd137ae..facb507 100644 --- a/tfcrypt.c +++ b/tfcrypt.c @@ -576,6 +576,7 @@ _baddfname: break; case 'q': quiet = YES; + xexit_no_nl = YES; verbose = NO; do_full_hexdump = NO; status_timer = 0; diff --git a/tfcrypt.h b/tfcrypt.h index 569e82c..a571397 100644 --- a/tfcrypt.h +++ b/tfcrypt.h @@ -170,6 +170,8 @@ 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);