lift restrictions on partial "window" seeked signature verifying
[tfcrypt.git] / tfc_signal.c
index b2862eedcdaa53fab7f6c71b13b691dd3ff6563a..1e025349a52c70e73a6c945d1ac141353ad0bdcc 100644 (file)
@@ -35,7 +35,14 @@ void exit_sigterm(int signal)
 
 void handle_sigtstp(int signal)
 {
-       if (signal == SIGTSTP) kill(getpid(), SIGSTOP);
+       if (signal == SIGTSTP) {
+               tfc_useconds freeze_start, freeze_end;
+
+               tfc_getcurtime(&freeze_start);
+               kill(getpid(), SIGSTOP);
+               tfc_getcurtime(&freeze_end);
+               total_time -= (freeze_end - freeze_start);
+       }
 }
 
 void print_crypt_status(int signal)
@@ -45,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;
@@ -74,14 +86,12 @@ void print_crypt_status(int signal)
 
        if (bench_timer) {
                tfc_say("done!");
-               tfc_say("%s %s benchmark results:", progname, tfc_modename(ctr_mode));
+               tfc_say("%s %s benchmark results:", tfc_format_pid(progname), tfc_modename(ctr_mode));
                tfc_nfsay(stdout, "%s %llu (%.2f%s) bytes, "
                        "avg. speed %llu (%.2f%s) B/s, time %.4fs.",
                        oper_mode,
                        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));
-               tfc_esay("\n");
+                       wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), seconds);
                xexit(0);
        }
 
@@ -89,28 +99,28 @@ void print_crypt_status(int signal)
        else inplace = "";
 
        if (do_less_stats == YES) {
-               tfc_nfsay(stderr, "%s%s:"
+               tfc_nfsay(stderr, "%s%s%s:"
                        " %s %.2f%s,"
                        " %.2f%s B/s @%s",
-                       inplace, 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));
        }
        else {
-               if (ctr_mode <= TFC_MODE_PLAIN) tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
+               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, 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),
                        wr_speed, human_wr_speed, tfc_getscale(wr_speed_scale), tfc_format_time(total_time));
-               else tfc_nfsay(stderr, "%s%s: read: %llu (%.2f%s),"
+               else tfc_nfsay(stderr, "%s%s%s: read: %llu (%.2f%s),"
                        " %s %s %llu (%.2f%s) bytes,"
                        " written %llu (%.2f%s) bytes,"
                        " (%llu (%.2f%s) B/s), time %s",
-                       inplace, 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),
@@ -119,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);
@@ -154,7 +160,7 @@ void change_status_timer(int signal)
        else status_timer *= 2;
 
        if (verbose) tfc_esay("%s: status timer was changed to %.2fs",
-               progname, TFC_UTODSECS(status_timer));
+               tfc_format_pid(progname), TFC_UTODSECS(status_timer));
        setup_next_alarm(status_timer);
 }