From: Andrey Rys Date: Sat, 27 Nov 2021 12:02:47 +0000 (+0100) Subject: SIGTERM, SIGINT: exit immediately, don't try to postprocess even in verbose mode. X-Git-Url: https://jxself.org/git/?a=commitdiff_plain;h=a874fa08a172c1d5006d15d05e494e1b9fbda211;p=tfcrypt.git SIGTERM, SIGINT: exit immediately, don't try to postprocess even in verbose mode. - Just report stats and exit afterwards, - MAC signing is disabled naturally due to exit path before it happening. --- diff --git a/VERSION b/VERSION index 81b5c5d..e522732 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -37 +38 diff --git a/tfc_base64.c b/tfc_base64.c index d2b3333..c76fdd9 100644 --- a/tfc_base64.c +++ b/tfc_base64.c @@ -28,6 +28,8 @@ #include "tfcrypt.h" +enum { TFB64_STOP1 = 1, TFB64_STOPF }; + void do_edbase64(char **fargv) { struct base64_decodestate dstate; @@ -70,7 +72,7 @@ void do_edbase64(char **fargv) ldone = 0; if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(sfd); _again: lio = xread(sfd, pblk, lrem); - if (lio == 0) do_stop = YES; + if (lio == 0) do_stop = TFB64_STOP1; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) @@ -108,7 +110,7 @@ _again: lio = xread(sfd, pblk, lrem); pblk = dstblk; if (ldone == 0) { - do_stop = TFC_STOP_FULL; + do_stop = TFB64_STOPF; break; } lrem = ldone; @@ -118,7 +120,7 @@ _wagain: lio = xwrite(dfd, pblk, lrem); else xerror(NO, NO, NO, "%s", fargv[1]); if (do_edcrypt == TFC_DO_ENCRYPT) { size_t t; - if (lread >= lblock || do_stop == TFC_STOP_FULL) { + if (lread >= lblock || do_stop == TFB64_STOPF) { t = xwrite(dfd, "\n", 1); if (t != NOSIZE) lio += t; else lio = NOSIZE; @@ -134,13 +136,13 @@ _wagain: lio = xwrite(dfd, pblk, lrem); } } - if (do_edcrypt == TFC_DO_ENCRYPT && do_stop == TFC_STOP_BEGAN) { + if (do_edcrypt == TFC_DO_ENCRYPT && do_stop == TFB64_STOP1) { size_t t = estate.count; pblk = dstblk + estate.count; base64_encode_blockend((char *)dstblk, &estate); lrem = estate.count - t; ldone = 0; - do_stop = TFC_STOP_FULL; + do_stop = TFB64_STOPF; goto _wagain; } diff --git a/tfc_io.c b/tfc_io.c index 2d3fd30..e849581 100644 --- a/tfc_io.c +++ b/tfc_io.c @@ -5,6 +5,7 @@ size_t xread(int fd, void *data, size_t szdata) size_t x; do { + errno = 0; x = (size_t)read(fd, data, szdata); } while (x == NOSIZE && errno == EINTR); @@ -16,6 +17,7 @@ size_t xwrite(int fd, const void *data, size_t szdata) size_t x; do { + errno = 0; x = (size_t)write(fd, data, szdata); } while (x == NOSIZE && errno == EINTR); diff --git a/tfc_signal.c b/tfc_signal.c index a2120f0..659e938 100644 --- a/tfc_signal.c +++ b/tfc_signal.c @@ -39,10 +39,10 @@ void print_crypt_status(int signal) double seconds, human_totalproc_src, human_totalproc_dst, human_wr_speed; int src_scale_idx, dst_scale_idx, wr_speed_scale; const char *oper_mode, *inplace; - static tfc_yesno last, was_sigint; + static tfc_yesno last; if (last == YES) return; - if (signal == 0) last = YES; + if (signal == 0 || signal == -1) last = YES; switch (do_edcrypt) { case TFC_DO_ENCRYPT: oper_mode = "encrypted"; break; @@ -55,16 +55,10 @@ void print_crypt_status(int signal) } if (signal == SIGINT || signal == SIGTERM) { - if (signal == SIGINT) was_sigint = YES; - if (do_stop == TFC_STOP_FULL) xexit(0); - do_stop = TFC_STOP_FULL; - status_timer = 0; - verbose = NO; - if (bench_timer) goto _out; - return; + do_stop = YES; } -_out: tfc_getcurtime(¤t_time); + tfc_getcurtime(¤t_time); total_time += (current_time - delta_time); seconds = TFC_UTODSECS(current_time - delta_time); wr_speed = delta_processed / seconds; @@ -81,7 +75,7 @@ _out: tfc_getcurtime(¤t_time); total_processed_src, human_totalproc_src, tfc_getscale(src_scale_idx), wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), TFC_UTODSECS(current_time - delta_time)); - if (was_sigint == NO) tfc_esay("\n"); + tfc_esay("\n"); xexit(0); } @@ -116,16 +110,19 @@ _out: tfc_getcurtime(¤t_time); wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time)); } - if ((do_statline_dynamic == NO || last == YES || signal == -1) && was_sigint == NO) tfc_esay("\n"); + 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); + } + delta_processed = 0; tfc_getcurtime(&delta_time); - if (signal == SIGTSTP) { - tfc_esay("stopping."); - kill(getpid(), SIGSTOP); - } + if (signal == SIGTSTP) kill(getpid(), SIGSTOP); if (status_timer) setup_next_alarm(status_timer); } diff --git a/tfcrypt.c b/tfcrypt.c index 604a6bf..83f6c69 100644 --- a/tfcrypt.c +++ b/tfcrypt.c @@ -641,7 +641,7 @@ _nosalt: lrem = lblock = sizeof(tmpdata); if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(mkfd); _mkragain: lio = xread(mkfd, pblk, lrem); - if (lio == 0) do_stop = YES; + if (lio == 0 && do_stop == NO) do_stop = YES; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) @@ -1115,7 +1115,7 @@ _ctrwagain: lio = xwrite(dfd, pblk, lrem); lrem = lblock = blk_len_adj(maxlen, total_processed_src, blksize); if (error_action == TFC_ERRACT_SYNC) rdpos = tfc_fdgetpos(sfd); _ragain: lio = xread(sfd, pblk, lrem); - if (lio == 0) do_stop = TFC_STOP_BEGAN; + if (lio == 0) do_stop = YES; if (lio != NOSIZE) ldone += lio; else { if (errno != EIO && catch_all_errors != YES) @@ -1195,8 +1195,6 @@ _nowrite: total_processed_dst += ldone; if (maxlen != NOFSIZE && total_processed_src >= maxlen) break; } - if (do_stop == TFC_STOP_FULL) goto _nomac; - errno = 0; if (do_mac >= TFC_MAC_VRFY) { if (!do_mac_file) { @@ -1341,8 +1339,7 @@ _macwagain: lio = xwrite(dfd, pblk, lrem); memset(tmpdata, 0, sizeof(tmpdata)); } -_nomac: - if (verbose || status_timer || do_stop == TFC_STOP_FULL) print_crypt_status(0); + if (verbose || status_timer || do_stop == YES) print_crypt_status(0); if (do_preserve_time) fcopy_matime(dfd, &s_stat); xclose(sfd); diff --git a/tfcrypt.h b/tfcrypt.h index 85ed79a..db11b1d 100644 --- a/tfcrypt.h +++ b/tfcrypt.h @@ -218,7 +218,6 @@ void do_benchmark(tfc_useconds useconds, double dseconds); enum { NO, YES }; enum { TFC_ERRACT_EXIT, TFC_ERRACT_CONT, TFC_ERRACT_SYNC, TFC_ERRACT_LSYNC }; -enum { TFC_STOP_BEGAN = 1, TFC_STOP_FULL }; enum { TFC_DO_PLAIN, TFC_DO_ENCRYPT, TFC_DO_DECRYPT }; enum { TFC_MAC_DROP = -1, TFC_MAC_SIGN = 1, TFC_MAC_VRFY, TFC_MAC_JUST_VRFY }; enum { TFC_MACKEY_RAWKEY = 1, TFC_MACKEY_PASSWORD, TFC_MACKEY_FILE };