From 0543d6c234ef5287a87137be740cc7319ecae0df Mon Sep 17 00:00:00 2001 From: David Golden Date: Fri, 25 Dec 2015 21:47:18 -0500 Subject: Make other syswrites use _syswrite_with_timeout Two other methods in Net::Cmd did syswrite() calls, both without a loop or timeout. This replaces those with a call to the new, common _syswrite_with_timeout() method, which does both correctly and restarts after EINTR. --- lib/Net/Cmd.pm | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/lib/Net/Cmd.pm b/lib/Net/Cmd.pm index bd4857b..3c9ca59 100644 --- a/lib/Net/Cmd.pm +++ b/lib/Net/Cmd.pm @@ -279,8 +279,6 @@ sub command { if (exists ${*$cmd}{'net_cmd_last_ch'}); if (scalar(@_)) { - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - my $str = join( " ", map { @@ -292,17 +290,13 @@ sub command { $str = $cmd->toascii($str) if $tr; $str .= "\015\012"; - my $len = length $str; - my $swlen; - $cmd->debug_print(1, $str) if ($cmd->debug); - unless (defined($swlen = syswrite($cmd,$str,$len)) && $swlen == $len) { - $cmd->close; - $cmd->_set_status_closed; - return $cmd; - } + # though documented to return undef on failure, the legacy behavior + # was to turn $cmd even on failure, so this odd construct does that + $cmd->_syswrite_with_timeout($str) + or return $cmd; } $cmd; @@ -563,19 +557,11 @@ sub dataend { $tosend .= ".\015\012"; - local $SIG{PIPE} = 'IGNORE' unless $^O eq 'MacOS'; - $cmd->debug_print(1, ".\n") if ($cmd->debug); - my $len = length $tosend; - my $w = syswrite($cmd, $tosend, $len); - unless (defined($w) && $w == $len) - { - $cmd->close; - $cmd->_set_status_closed; - return 0; - } + $cmd->_syswrite_with_timeout($tosend) + or return 0; delete ${*$cmd}{'net_cmd_last_ch'}; -- cgit v1.2.3-24-ge0c7