From: Jan "Yenya" Kasprzak Date: Mon, 19 Dec 2022 14:26:40 +0000 (+0100) Subject: run: sigint handling, native backups X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?p=aoc.git;a=commitdiff_plain;h=74af6297f8c634799bce09a785e3c38b51622048 run: sigint handling, native backups --- diff --git a/2022/run b/2022/run index 40a45a6..9dc85ce 100755 --- a/2022/run +++ b/2022/run @@ -6,7 +6,7 @@ use strict; use Time::HiRes qw(sleep); use Linux::Inotify2; -use POSIX qw(strftime); +use POSIX qw(strftime WIFSIGNALED WTERMSIG SIGINT); use Mojo::File; use Y::AoC qw(grey red); @@ -16,12 +16,20 @@ my $backup = "backup/$cmd"; $cmd = "./$cmd" if $cmd !~ /\//; my $last_backup; +my $file = Mojo::File->new($cmd); +my $mtime; while (1) { my $b = "$backup-".strftime("%H-%M-%S", localtime(time)); - system 'cp', $cmd, $b; + $file->copy_to($b); + $mtime = $file->stat->mtime; say grey("\nrunning $cmd @ARGV... ============================"); system $cmd, @ARGV; - if ($?) { + if ($? && WIFSIGNALED($?) && WTERMSIG($?) == SIGINT) { + say red(" Got SIGINT"); + if ($file->stat->mtime > $mtime) { + next; + } + } elsif ($?) { say grey("FAILED: $?"); } else { say grey("finished OK");