Skip to content

Commit

Permalink
Bugfix for Linux and MacOS: prevent realsync death (hang) when a SIGP…
Browse files Browse the repository at this point in the history
…IPE is received (e.g. when a remote SSH process is disconnected unexpectedly; may be reproduced via ifdown+ifup).
  • Loading branch information
dimikot committed Nov 5, 2011
1 parent abf5cac commit bfb7cea
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion realsync
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ sub mainloop {
binmode(STDERR); STDERR->autoflush(1);

$SIG{CHLD} = 'IGNORE'; # later, if you use system(), reset this signal!
$SIG{PIPE} = 'IGNORE'; # do not kill the whole realsync if remote SSH dies
$SIG{INT} = $SIG{TERM} = $SIG{KILL} = sub { onexit(); exit; };

if (!-d $DIR_PRIVATE || !-f $FILE_CONFIG) {
Expand Down Expand Up @@ -226,6 +227,7 @@ sub do_rsync {
logger($msg);
#logger(join(" ", map { /\s|\*/s? '"' . $_ . '"' : $_ } @rsync_cmd));
local $SIG{CHLD}; # else system() does not work
local $SIG{PIPE}; # to be on a safe side
my $exitcode = system(@rsync_cmd);
if (!defined $exitcode || $exitcode < 0) {
logger("Failed to run rsync: $!\n");
Expand Down Expand Up @@ -254,7 +256,7 @@ sub do_run_ssh {
(-f $FILE_IDENTITY? ("-i", $FILE_IDENTITY) : ()),
@SSH_OPTIONS,
cfg("user") . '@' . cfg("host"),
"perl -we '$REM_SCRIPT' 2>&1"
"exec perl -we '$REM_SCRIPT' 2>&1"
);
# Unfortunately on Win32 we cannot read from a handle returned
# from the first open2's argument - Perl hangs even if buffering
Expand Down Expand Up @@ -302,6 +304,7 @@ sub do_watch {
#
sub do_install {
local $SIG{CHLD}; # else system() does not work
local $SIG{PIPE}; # to be on a safe side

my $step_num = 1;
my $step_max = 6;
Expand Down Expand Up @@ -1303,6 +1306,7 @@ while (1) {
sub readln {
my $s = <STDIN>;
die "STDIN closed, the remote process is finished.\n" if !defined $s;
chomp($s);
return $s;
}
Expand Down

0 comments on commit bfb7cea

Please sign in to comment.