mirror of https://github.com/digint/btrbk
btrbk: add eval_quiet(), a simple wrapper around eval, disabling $SIG_(__DIE__)
parent
47eb14f5fb
commit
7e7c28f8f1
40
btrbk
40
btrbk
|
@ -322,6 +322,11 @@ sub ABORTED($;$)
|
||||||
$config->{ABORTED} = $abrt;
|
$config->{ABORTED} = $abrt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub eval_quiet(&)
|
||||||
|
{
|
||||||
|
local $SIG{__DIE__};
|
||||||
|
return eval { $_[0]->() }
|
||||||
|
}
|
||||||
|
|
||||||
sub init_transaction_log($$)
|
sub init_transaction_log($$)
|
||||||
{
|
{
|
||||||
|
@ -338,15 +343,14 @@ sub init_transaction_log($$)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(defined($config_syslog_facility) && (not $dryrun)) {
|
if(defined($config_syslog_facility) && (not $dryrun)) {
|
||||||
eval {
|
DEBUG "Opening syslog";
|
||||||
local $SIG{'__DIE__'};
|
if(eval_quiet { require Sys::Syslog; }) {
|
||||||
require Sys::Syslog;
|
|
||||||
};
|
|
||||||
if($@) {
|
|
||||||
WARN "Syslog disabled: $@";
|
|
||||||
} else {
|
|
||||||
$syslog_enabled = 1;
|
$syslog_enabled = 1;
|
||||||
Sys::Syslog::openlog("btrbk", "", $config_syslog_facility);
|
Sys::Syslog::openlog("btrbk", "", $config_syslog_facility);
|
||||||
|
DEBUG "Syslog enabled";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
WARN "Syslog disabled: $@";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action("startup", status => "v$VERSION", message => "$VERSION_INFO");
|
action("startup", status => "v$VERSION", message => "$VERSION_INFO");
|
||||||
|
@ -359,9 +363,8 @@ sub close_transaction_log()
|
||||||
close $tlog_fh || ERROR "Failed to close transaction log: $!";
|
close $tlog_fh || ERROR "Failed to close transaction log: $!";
|
||||||
}
|
}
|
||||||
if($syslog_enabled) {
|
if($syslog_enabled) {
|
||||||
eval { local $SIG{'__DIE__'};
|
DEBUG "Closing syslog";
|
||||||
Sys::Syslog::closelog();
|
eval_quiet { Sys::Syslog::closelog(); };
|
||||||
};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -406,13 +409,9 @@ sub end_transaction($$)
|
||||||
|
|
||||||
sub syslog($)
|
sub syslog($)
|
||||||
{
|
{
|
||||||
my $line = shift;
|
|
||||||
return undef unless($syslog_enabled);
|
return undef unless($syslog_enabled);
|
||||||
eval {
|
my $line = shift;
|
||||||
local $SIG{'__DIE__'};
|
eval_quiet { Sys::Syslog::syslog("info", $line); };
|
||||||
Sys::Syslog::syslog("info", $line);
|
|
||||||
};
|
|
||||||
if($@) { WARN "syslog failed: $@"; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub safe_cmd($)
|
sub safe_cmd($)
|
||||||
|
@ -1590,15 +1589,12 @@ sub add_btrbk_filename_info($;$)
|
||||||
my $zz = $+{zz};
|
my $zz = $+{zz};
|
||||||
|
|
||||||
my $time;
|
my $time;
|
||||||
eval {
|
|
||||||
local $SIG{'__DIE__'};
|
|
||||||
if(defined($zz)) {
|
if(defined($zz)) {
|
||||||
$time = timegm(@tm);
|
eval_quiet { $time = timegm(@tm); };
|
||||||
} else {
|
} else {
|
||||||
$time = timelocal(@tm);
|
eval_quiet { $time = timelocal(@tm); };
|
||||||
}
|
}
|
||||||
};
|
unless(defined($time)) {
|
||||||
if($@) {
|
|
||||||
WARN "Illegal timestamp on subvolume \"$node->{REL_PATH}\", ignoring";
|
WARN "Illegal timestamp on subvolume \"$node->{REL_PATH}\", ignoring";
|
||||||
# WARN "$@"; # sadly Time::Local croaks, which also prints the line number from here.
|
# WARN "$@"; # sadly Time::Local croaks, which also prints the line number from here.
|
||||||
return undef;
|
return undef;
|
||||||
|
|
Loading…
Reference in New Issue