about summary refs log tree commit
diff options
context:
space:
mode:
authorDavid Golden <xdg@xdg.me>2015-12-25 21:47:18 -0500
committerDavid Golden <xdg@xdg.me>2015-12-25 22:08:23 -0500
commit0543d6c234ef5287a87137be740cc7319ecae0df (patch)
tree577d8be11348d60fbcacec8fb38758345a042a48
parent852982580b27fdc9e90d03215913b6652dccdfa9 (diff)
downloadperl-libnet-0543d6c234ef5287a87137be740cc7319ecae0df.tar.gz
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.
-rw-r--r--lib/Net/Cmd.pm26
1 files 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'};