git-svn: use POSIX::sigprocmask to block signals
In order to maintain consistency of the database mapping svn revision numbers to git commit ids, rev_map_set() defers signal processing until it's finished with an append transaction.[*] The conventional way to achieve this is through sigprocmask(), which is available in perl in the standard POSIX module. This is implemented by this patch. One important consequence of it is that the signal handlers won't be unconditionally set to SIG_DFL anymore upon the first invocation of rev_map_set() as they used to. As a result, the signals ignored by git-svn parent will remain ignored; otherwise the behavior remains the same. This patch paves the way to ignoring SIGPIPE throughout git-svn which will be done in the followup patch. [*] Deferring signals is not enough to ensure the database consistency: the program may die on SIGKILL or power loss, run out of disk space, etc. However that's a separate issue that this patch doesn't address. Signed-off-by: Roman Kagan <rkagan@mail.ru> Acked-by: Eric Wong <normalperson@yhbt.net>
This commit is contained in:
parent
aa39b858a3
commit
037a98cd3f
15
git-svn.perl
15
git-svn.perl
@ -2031,6 +2031,7 @@ use IPC::Open3;
|
|||||||
use Time::Local;
|
use Time::Local;
|
||||||
use Memoize; # core since 5.8.0, Jul 2002
|
use Memoize; # core since 5.8.0, Jul 2002
|
||||||
use Memoize::Storable;
|
use Memoize::Storable;
|
||||||
|
use POSIX qw(:signal_h);
|
||||||
|
|
||||||
my ($_gc_nr, $_gc_period);
|
my ($_gc_nr, $_gc_period);
|
||||||
|
|
||||||
@ -4059,11 +4060,14 @@ sub rev_map_set {
|
|||||||
length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
|
length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
|
||||||
my $db = $self->map_path($uuid);
|
my $db = $self->map_path($uuid);
|
||||||
my $db_lock = "$db.lock";
|
my $db_lock = "$db.lock";
|
||||||
my $sig;
|
my $sigmask;
|
||||||
$update_ref ||= 0;
|
$update_ref ||= 0;
|
||||||
if ($update_ref) {
|
if ($update_ref) {
|
||||||
$SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} =
|
$sigmask = POSIX::SigSet->new();
|
||||||
$SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] };
|
my $signew = POSIX::SigSet->new(SIGINT, SIGHUP, SIGTERM,
|
||||||
|
SIGALRM, SIGPIPE, SIGUSR1, SIGUSR2);
|
||||||
|
sigprocmask(SIG_BLOCK, $signew, $sigmask) or
|
||||||
|
croak "Can't block signals: $!";
|
||||||
}
|
}
|
||||||
mkfile($db);
|
mkfile($db);
|
||||||
|
|
||||||
@ -4102,9 +4106,8 @@ sub rev_map_set {
|
|||||||
"$db_lock => $db ($!)\n";
|
"$db_lock => $db ($!)\n";
|
||||||
delete $LOCKFILES{$db_lock};
|
delete $LOCKFILES{$db_lock};
|
||||||
if ($update_ref) {
|
if ($update_ref) {
|
||||||
$SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} =
|
sigprocmask(SIG_SETMASK, $sigmask) or
|
||||||
$SIG{USR1} = $SIG{USR2} = 'DEFAULT';
|
croak "Can't restore signal mask: $!";
|
||||||
kill $sig, $$ if defined $sig;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user