SIGTERM, SIGINT: exit immediately, don't try to postprocess even in verbose mode.
authorAndrey Rys <rys@lynxlynx.ru>
Sat, 27 Nov 2021 12:02:47 +0000 (13:02 +0100)
committerAndrey Rys <rys@lynxlynx.ru>
Sat, 27 Nov 2021 12:02:47 +0000 (13:02 +0100)
- Just report stats and exit afterwards,
- MAC signing is disabled naturally due to exit path before it happening.

VERSION
tfc_base64.c
tfc_io.c
tfc_signal.c
tfcrypt.c
tfcrypt.h

diff --git a/VERSION b/VERSION
index 81b5c5d06cc0b8290c264b408abb32cc0986e8f2..e522732c77ec94723e739d22f28df549b0231f5f 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-37
+38
index d2b3333ca9b5ab833a3b61824e799eb198cee296..c76fdd90dfe912e809dd8d5d2cc257fb72f198fd 100644 (file)
@@ -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;
        }
 
index 2d3fd30e89c65cd0f5a6e8668547ed5134a89ab3..e849581222f0fb9d5161b628e1462b5893381fe8 100644 (file)
--- 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);
 
index a2120f0d1712512b9bb2126d203427aeb88a156e..659e9381ec181514d8cddacf785ad79ef898f03c 100644 (file)
@@ -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(&current_time);
+       tfc_getcurtime(&current_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(&current_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(&current_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);
 }
index 604a6bf990247abd61c19f996a83dea63d989002..83f6c69869a689b2505b691abf8b07c92dc2cca1 100644 (file)
--- 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);
index 85ed79a5890f4f142d2a828f607586ebe68394b8..db11b1df6ffed60782c3b528dbde90b3a747dde8 100644 (file)
--- 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 };