[opendemo-cvs] CVS: opendemo/tools pwrap.pl,1.2,1.3
Status: Beta
Brought to you by:
girlich
From: Uwe G. <gi...@us...> - 2004-10-22 20:05:22
|
Update of /cvsroot/opendemo/opendemo/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3335 Modified Files: pwrap.pl Log Message: only write, if the write fs is open for writing. Index: pwrap.pl =================================================================== RCS file: /cvsroot/opendemo/opendemo/tools/pwrap.pl,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** pwrap.pl 11 Mar 2004 21:17:58 -0000 1.2 --- pwrap.pl 22 Oct 2004 20:05:11 -0000 1.3 *************** *** 79,95 **** } open(my $stdin, "<&=STDIN") || die "can't reopen STDIN for reading: $!\n"; use IO::Select; use Errno qw(EINTR ECHILD); while (!$loop_end) { my $read = IO::Select->new(); my $error = IO::Select->new(); if ($stdin) { $read->add($stdin); } ! if (!$stdout_up && !$stderr_up) { ! $loop_end = 1; ! last; } if ($stdout_up) { --- 79,106 ---- } open(my $stdin, "<&=STDIN") || die "can't reopen STDIN for reading: $!\n"; + open(my $stdout, ">&=STDOUT") || die "can't reopen STDOUT for writing: $!\n"; + open(my $stderr, ">&=STDERR") || die "can't reopen STDERR for writing: $!\n"; use IO::Select; use Errno qw(EINTR ECHILD); + my $stdin_buffer = ""; + my $stdout_buffer = ""; + my $stderr_buffer = ""; while (!$loop_end) { + if (!$stdout_up && !$stderr_up) { + $loop_end = 1; + last; + } my $read = IO::Select->new(); + my $write = IO::Select->new(); my $error = IO::Select->new(); if ($stdin) { $read->add($stdin); + $error->add($stdin); } ! if ($stdin_up) { ! $write->add($stdin_up); ! $error->add($stdin_up); } if ($stdout_up) { *************** *** 97,105 **** $error->add($stdout_up); } if ($stderr_up) { $read->add($stderr_up); $error->add($stderr_up); } ! my @res = IO::Select::select($read,undef,undef); if (scalar @res == 0) { # warn "select had an error: $!\n"; --- 108,124 ---- $error->add($stdout_up); } + if ($stdout) { + $write->add($stdout); + $error->add($stdout); + } if ($stderr_up) { $read->add($stderr_up); $error->add($stderr_up); } ! if ($stderr) { ! $write->add($stderr); ! $error->add($stderr); ! } ! my @res = IO::Select::select($read,$write,$error); if (scalar @res == 0) { # warn "select had an error: $!\n"; *************** *** 110,118 **** foreach my $fd (@{$canread}) { if ($stdin && ($fd == $stdin)) { ! my $res = sysread $stdin, my $buffer, 1000; ! if ($res) { ! syswrite $stdin_up, $buffer; ! } ! else { if ($! != EINTR) { $stdin_up->close(); --- 129,134 ---- foreach my $fd (@{$canread}) { if ($stdin && ($fd == $stdin)) { ! my $res = sysread $stdin, $stdin_buffer, 1000, length($stdin_buffer); ! if (!$res) { if ($! != EINTR) { $stdin_up->close(); *************** *** 123,132 **** } if ($stdout_up && ($fd == $stdout_up)) { ! my $res = sysread $stdout_up, my $buffer, 1000; ! if ($res) { ! syswrite STDOUT, $buffer; ! } ! else { if ($! != EINTR) { $stdout_up->close(); $stdout_up = undef; --- 139,146 ---- } if ($stdout_up && ($fd == $stdout_up)) { ! my $res = sysread $stdout_up, $stdout_buffer, 1000, length($stdout_buffer); ! if (!$res) { if ($! != EINTR) { + # $stdout->close(); $stdout_up->close(); $stdout_up = undef; *************** *** 135,144 **** } if ($stderr_up && ($fd == $stderr_up)) { ! my $res = sysread $stderr_up, my $buffer, 1000; ! if ($res) { ! syswrite STDERR, $buffer; ! } ! else { if ($! != EINTR) { $stderr_up->close(); $stderr_up = undef; --- 149,156 ---- } if ($stderr_up && ($fd == $stderr_up)) { ! my $res = sysread $stderr_up, $stderr_buffer, 1000, length($stderr_buffer); ! if (!$res) { if ($! != EINTR) { + # $stderr->close(); $stderr_up->close(); $stderr_up = undef; *************** *** 147,150 **** --- 159,182 ---- } } + foreach my $fd (@{$canwrite}) { + if ($stdin_up && ($fd == $stdin_up) && length($stdin_buffer)>0) { + my $res = syswrite $stdin_up, $stdin_buffer; + if ($res>0) { + substr $stdin_buffer, 0, $res, ""; + } + } + if ($stdout && ($fd == $stdout) && length($stdout_buffer)>0) { + my $res = syswrite $stdout, $stdout_buffer; + if ($res>0) { + substr $stdout_buffer, 0, $res, ""; + } + } + if ($stderr && ($fd == $stderr) && length($stderr_buffer)>0) { + my $res = syswrite $stderr, $stderr_buffer; + if ($res>0) { + substr $stderr_buffer, 0, $res, ""; + } + } + } foreach my $fd (@{$haserror}) { if ($stdout_up && ($fd == $stdout_up)) { |