Skip to content

Commit 037a98c

Browse files
rvkaEric Wong
authored andcommitted
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 <[email protected]> Acked-by: Eric Wong <[email protected]>
1 parent aa39b85 commit 037a98c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

git-svn.perl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2031,6 +2031,7 @@ package Git::SVN;
20312031
use Time::Local;
20322032
use Memoize; # core since 5.8.0, Jul 2002
20332033
use Memoize::Storable;
2034+
use POSIX qw(:signal_h);
20342035

20352036
my ($_gc_nr, $_gc_period);
20362037

@@ -4059,11 +4060,14 @@ sub rev_map_set {
40594060
length $commit == 40 or die "arg3 must be a full SHA1 hexsum\n";
40604061
my $db = $self->map_path($uuid);
40614062
my $db_lock = "$db.lock";
4062-
my $sig;
4063+
my $sigmask;
40634064
$update_ref ||= 0;
40644065
if ($update_ref) {
4065-
$SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} =
4066-
$SIG{USR1} = $SIG{USR2} = sub { $sig = $_[0] };
4066+
$sigmask = POSIX::SigSet->new();
4067+
my $signew = POSIX::SigSet->new(SIGINT, SIGHUP, SIGTERM,
4068+
SIGALRM, SIGPIPE, SIGUSR1, SIGUSR2);
4069+
sigprocmask(SIG_BLOCK, $signew, $sigmask) or
4070+
croak "Can't block signals: $!";
40674071
}
40684072
mkfile($db);
40694073

@@ -4102,9 +4106,8 @@ sub rev_map_set {
41024106
"$db_lock => $db ($!)\n";
41034107
delete $LOCKFILES{$db_lock};
41044108
if ($update_ref) {
4105-
$SIG{INT} = $SIG{HUP} = $SIG{TERM} = $SIG{ALRM} = $SIG{PIPE} =
4106-
$SIG{USR1} = $SIG{USR2} = 'DEFAULT';
4107-
kill $sig, $$ if defined $sig;
4109+
sigprocmask(SIG_SETMASK, $sigmask) or
4110+
croak "Can't restore signal mask: $!";
41084111
}
41094112
}
41104113

0 commit comments

Comments
 (0)