J
jgraber
Are there any gotcha's on this demo script to
revert an inplace edit when catching a HUP signal,
or on a full disk error?
Is there a variable that holds the backup filename,
that would also handle format -i'dir/*.bak' ?
demo appears to filter correctly without HUP,
revert on catching kill -HUP,
revert on catching fake full disk.
On kill -KILL, demo leaves a backup file,
but not a filtered file.
run on linux like this:
% cp demo junk
% perl -i~ demo junk &
[1] 27622
% kill -HUP 27622
demo caught ' fake full disk', reverting by rename 'junk~' to 'junk' status (1=ok): 1, and quit now
#!/usr/local/bin/perl
use warnings;
use strict;
$SIG{HUP} = \&sig_hup_handler;
sub sig_hup_handler{
local $" = ' '; # $" is list sep
die "$0 caught '@_', reverting by rename '$ARGV$^I' to '$ARGV' status (1=ok): ",
rename( $ARGV . $^I, $ARGV),
", and quit now\n"; }
my $i = 0;
while(<>){
s/$/"# $i"/e; # add line number
print;
sleep 1 if ++$i < 10;
if (eof) {print "# last line\n";
$i = 0; # then send full disk error to sig_hup
sig_hup_handler($!) if not close ;
# sig_hup_handler(' fake full disk') if not 0;
}
}
revert an inplace edit when catching a HUP signal,
or on a full disk error?
Is there a variable that holds the backup filename,
that would also handle format -i'dir/*.bak' ?
demo appears to filter correctly without HUP,
revert on catching kill -HUP,
revert on catching fake full disk.
On kill -KILL, demo leaves a backup file,
but not a filtered file.
run on linux like this:
% cp demo junk
% perl -i~ demo junk &
[1] 27622
% kill -HUP 27622
demo caught ' fake full disk', reverting by rename 'junk~' to 'junk' status (1=ok): 1, and quit now
#!/usr/local/bin/perl
use warnings;
use strict;
$SIG{HUP} = \&sig_hup_handler;
sub sig_hup_handler{
local $" = ' '; # $" is list sep
die "$0 caught '@_', reverting by rename '$ARGV$^I' to '$ARGV' status (1=ok): ",
rename( $ARGV . $^I, $ARGV),
", and quit now\n"; }
my $i = 0;
while(<>){
s/$/"# $i"/e; # add line number
print;
sleep 1 if ++$i < 10;
if (eof) {print "# last line\n";
$i = 0; # then send full disk error to sig_hup
sig_hup_handler($!) if not close ;
# sig_hup_handler(' fake full disk') if not 0;
}
}