X-Git-Url: https://jxself.org/git/?a=blobdiff_plain;f=tfcrypt.c;h=6b9055f346b7def9984a34863a86cc15cff6f577;hb=f98c367a4cf1ed9f0c6d7620e3f1988596945495;hp=6ac7bdceb4da6879c98df6f6483e4cf4d3026559;hpb=a2ba0ca55c0bccf3695f9fdfacfbd991a2a73cf1;p=tfcrypt.git diff --git a/tfcrypt.c b/tfcrypt.c index 6ac7bdc..6b9055f 100644 --- a/tfcrypt.c +++ b/tfcrypt.c @@ -30,6 +30,18 @@ static tfc_byte svctr[TF_BLOCK_SIZE]; +static void open_log(const char *logfile) +{ + int fd; + + fd = open(logfile, O_WRONLY | O_CREAT | O_LARGEFILE | O_TRUNC, 0666); + if (fd == -1) xerror(NO, NO, YES, "%s", logfile); + xclose(2); + if (dup2(fd, 2) == -1) xexit(2); + xclose(fd); + do_statline_dynamic = NO; +} + static int getps_filter(struct getpasswd_state *getps, char chr, size_t pos) { if (chr == '\x03') { @@ -138,7 +150,7 @@ _baddfname: } opterr = 0; - while ((c = getopt(argc, argv, "L:s:aU:C:r:K:t:Pkzxc:l:qedn:vV:pwE:O:S:AmuM:R:Z:WHD:")) != -1) { + while ((c = getopt(argc, argv, "L:s:aU:C:r:K:t:Pkzxc:l:qedn:vV:pwE:o:O:S:AmuM:R:Z:WHD:")) != -1) { switch (c) { case 'L': read_defaults(optarg, NO); @@ -285,6 +297,9 @@ _baddfname: error_action = TFC_ERRACT_LSYNC; else xerror(NO, YES, YES, "invalid error action %s specified", optarg); break; + case 'o': + open_log(optarg); + break; case 'O': s = d = optarg; t = NULL; while ((s = strtok_r(d, ",", &t))) { @@ -317,6 +332,8 @@ _baddfname: do_full_key = YES; else if (!strcmp(s, "showsecrets")) show_secrets = YES; + else if (!strncmp(s, "logfile", 7) && *(s+7) == '=') + open_log(s+8); else if (!strncmp(s, "iobs", 4) && *(s+4) == '=') { s += 5; blksize = (size_t)tfc_humanfsize(s, &stoi); @@ -1071,9 +1088,8 @@ _plain: sigact.sa_flags = SA_RESTART; sigact.sa_handler = print_crypt_status; sigaction(SIGUSR1, &sigact, NULL); - sigaction(SIGTSTP, &sigact, NULL); sigaction(SIGALRM, &sigact, NULL); - if (status_timer) setup_next_alarm(status_timer); + if (status_timer) setup_next_alarm(status_timer > 1000000 ? 1000000 : status_timer); sigact.sa_handler = change_status_width; sigaction(SIGQUIT, &sigact, NULL); sigact.sa_handler = change_status_timer; @@ -1082,11 +1098,14 @@ _plain: sigact.sa_handler = print_crypt_status; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); + sigaction(SIGTSTP, &sigact, NULL); } else { sigact.sa_handler = exit_sigterm; sigaction(SIGINT, &sigact, NULL); sigaction(SIGTERM, &sigact, NULL); + sigact.sa_handler = handle_sigtstp; + sigaction(SIGTSTP, &sigact, NULL); } memset(&sigact, 0, sizeof(struct sigaction)); @@ -1217,7 +1236,10 @@ _wagain: lio = xwrite(dfd, pblk, lrem); _nowrite: total_processed_dst += ldone; delta_processed += ldone; - if (maxlen != NOFSIZE && total_processed_src >= maxlen) break; + if (maxlen != NOFSIZE && total_processed_src >= maxlen) { + do_stop = YES; + break; + } } errno = 0; @@ -1372,15 +1394,7 @@ _macwagain: lio = xwrite(dfd, pblk, lrem); memset(tmpdata, 0, sizeof(tmpdata)); } - if (verbose || status_timer || do_stop == YES) print_crypt_status(0); - - if (do_preserve_time) fcopy_matime(dfd, &s_stat); - 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); - } - xclose(dfd); + if (verbose || status_timer || (do_stop == YES && quiet == NO)) print_crypt_status(0); xexit(exitcode); return -1;