Changeset 903
- Timestamp:
- Dec 28, 2008, 1:21:33 AM (16 years ago)
- Location:
- server/common/oursrc/execsys
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
server/common/oursrc/execsys/gitproxy.pl
r851 r903 2 2 # 3 3 # gitproxy: Wrapper around git daemon for Git virtual hosting. 4 # version 1. 0, released 2008-10-084 # version 1.1, released 2008-12-28 5 5 # Copyright © 2008 Anders Kaseorg <andersk@mit.edu> 6 6 # … … 23 23 use IPC::Open2; 24 24 use Errno qw(EINTR); 25 use IO::Poll qw(POLLIN POLLOUT POLLHUP); 25 26 26 27 # Receive the first message from the client, and parse out the URL. … … 46 47 47 48 # Now start the real git daemon based on the URL. 48 open2(\*IN, \*OUT, '/usr/local/sbin/ldapize.pl', "git://$host/") or die "$0: open: $!";49 my $pid = open2(\*IN, \*OUT, '/usr/local/sbin/ldapize.pl', "git://$host/") or die "$0: open: $!"; 49 50 50 # Finally, go into a selectloop to transfer the remaining data51 # Finally, go into a poll loop to transfer the remaining data 51 52 # (STDIN -> OUT, IN -> STDOUT), including the client's message to git daemon. 52 53 my ($cbuf, $sbuf) = ($msg, ''); 53 my ($rin, $win, $ein) = ('', '', ''); 54 my ($stdout, $out, $stdin, $in) = (fileno(STDOUT), fileno(OUT), fileno(STDIN), fileno(IN)); 55 vec($win, $stdout, 1) = 0; 56 vec($win, $out, 1) = 1; 57 vec($rin, $stdin, 1) = 0; 58 vec($rin, $in, 1) = 1; 59 while (vec($win, $stdout, 1) or vec($win, $out, 1) or 60 vec($rin, $stdin, 1) or vec($rin, $in, 1)) { 61 my $n = select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); 54 my $poll = new IO::Poll; 55 $poll->mask(\*STDOUT => POLLHUP); 56 $poll->mask(\*OUT => POLLOUT); 57 $poll->remove(\*STDIN); 58 $poll->mask(\*IN => POLLIN); 59 while ($poll->handles()) { 60 my $n = $poll->poll(); 62 61 next if $n < 0 and $! == EINTR; 63 62 $n >= 0 or die "select: $!"; 64 if ( vec($rout, $stdin, 1)) {63 if ($poll->events(\*STDIN)) { 65 64 my $n = sysread(STDIN, $cbuf, 4096); 66 65 next if $n < 0 and $! == EINTR; 67 66 $n >= 0 or die "read: $!"; 68 vec($rin, $stdin, 1) = 0;69 vec($win, $out, 1) = 1;70 } elsif ( vec($rout, $in, 1)) {67 $poll->remove(\*STDIN); 68 $poll->mask(\*OUT => POLLOUT); 69 } elsif ($poll->events(\*IN)) { 71 70 my $n = sysread(IN, $sbuf, 4096); 72 71 next if $n < 0 and $! == EINTR; 73 72 $n >= 0 or die "read: $!"; 74 vec($rin, $in, 1) = 0;75 vec($win, $stdout, 1) = 1;76 } elsif ( vec($wout, $stdout, 1)&& $sbuf ne '') {73 $poll->remove(\*IN); 74 $poll->mask(\*STDOUT => POLLOUT); 75 } elsif ($poll->events(\*STDOUT) & POLLOUT && $sbuf ne '') { 77 76 my $n = syswrite(STDOUT, $sbuf); 78 77 next if $n < 0 and $! == EINTR; … … 80 79 $sbuf = substr($sbuf, $n); 81 80 if ($sbuf eq '') { 82 vec($win, $stdout, 1) = 0;83 vec($rin, $in, 1) = 1;81 $poll->mask(\*STDOUT => POLLHUP); 82 $poll->mask(\*IN => POLLIN); 84 83 } 85 } elsif (vec($wout, $stdout, 1)) { 86 vec($win, $stdout, 1) = 0; 84 } elsif ($poll->events(\*STDOUT)) { 85 $poll->remove(\*STDOUT); 86 $poll->remove(\*IN); 87 87 close(STDOUT) or die "close: $!"; 88 88 close(IN) or die "close: $!"; 89 } elsif ( vec($wout, $out, 1)&& $cbuf ne '') {89 } elsif ($poll->events(\*OUT) & POLLOUT && $cbuf ne '') { 90 90 my $n = syswrite(OUT, $cbuf); 91 91 next if $n < 0 and $! == EINTR; … … 93 93 $cbuf = substr($cbuf, $n); 94 94 if ($cbuf eq '') { 95 vec($win, $out, 1) = 0;96 vec($rin, $stdin, 1) = 1;95 $poll->mask(\*OUT => POLLHUP); 96 $poll->mask(\*STDIN => POLLIN); 97 97 } 98 } elsif (vec($wout, $out, 1)) { 99 vec($win, $out, 1) = 0; 98 } elsif ($poll->events(\*OUT)) { 99 $poll->remove(\*OUT); 100 $poll->remove(\*STDIN); 100 101 close(OUT) or die "close: $!"; 101 102 close(STDIN) or die "close: $!"; 102 103 } 103 104 } 105 106 while (waitpid($pid, 0) == -1 && $! == EINTR) { } -
server/common/oursrc/execsys/svnproxy.pl
r835 r903 2 2 # 3 3 # svnproxy: Wrapper around svnserve for Subversion virtual hosting. 4 # version 1. 0, released 2008-08-294 # version 1.1, released 2008-12-28 5 5 # Copyright © 2008 Anders Kaseorg <andersk@mit.edu> 6 6 # … … 23 23 use IPC::Open2; 24 24 use Errno qw(EINTR); 25 use IO::Poll qw(POLLIN POLLOUT POLLHUP); 25 26 26 27 # Read the initial greeting from a dummy svnserve process. … … 71 72 72 73 # Now start the real svnserve based on the URL. 73 open2(\*IN, \*OUT, '/usr/local/sbin/ldapize.pl', $url) or die "$0: open: $!";74 $pid = open2(\*IN, \*OUT, '/usr/local/sbin/ldapize.pl', $url) or die "$0: open: $!"; 74 75 75 76 # Read the greeting, expecting it to be identical to the dummy greeting. … … 85 86 # (STDIN -> OUT, IN -> STDOUT), including the client's response to svnserve. 86 87 my ($cbuf, $sbuf) = ($response, ''); 87 my ($rin, $win, $ein) = ('', '', ''); 88 my ($stdout, $out, $stdin, $in) = (fileno(STDOUT), fileno(OUT), fileno(STDIN), fileno(IN)); 89 vec($win, $stdout, 1) = 0; 90 vec($win, $out, 1) = 1; 91 vec($rin, $stdin, 1) = 0; 92 vec($rin, $in, 1) = 1; 93 while (vec($win, $stdout, 1) or vec($win, $out, 1) or 94 vec($rin, $stdin, 1) or vec($rin, $in, 1)) { 95 my $n = select(my $rout = $rin, my $wout = $win, my $eout = $ein, undef); 88 my $poll = new IO::Poll; 89 $poll->mask(\*STDOUT => POLLHUP); 90 $poll->mask(\*OUT => POLLOUT); 91 $poll->remove(\*STDIN); 92 $poll->mask(\*IN => POLLIN); 93 while ($poll->handles()) { 94 my $n = $poll->poll(); 96 95 next if $n < 0 and $! == EINTR; 97 96 $n >= 0 or die "select: $!"; 98 if ( vec($rout, $stdin, 1)) {97 if ($poll->events(\*STDIN)) { 99 98 my $n = sysread(STDIN, $cbuf, 4096); 100 99 next if $n < 0 and $! == EINTR; 101 100 $n >= 0 or die "read: $!"; 102 vec($rin, $stdin, 1) = 0;103 vec($win, $out, 1) = 1;104 } elsif ( vec($rout, $in, 1)) {101 $poll->remove(\*STDIN); 102 $poll->mask(\*OUT => POLLOUT); 103 } elsif ($poll->events(\*IN)) { 105 104 my $n = sysread(IN, $sbuf, 4096); 106 105 next if $n < 0 and $! == EINTR; 107 106 $n >= 0 or die "read: $!"; 108 vec($rin, $in, 1) = 0;109 vec($win, $stdout, 1) = 1;110 } elsif ( vec($wout, $stdout, 1)&& $sbuf ne '') {107 $poll->remove(\*IN); 108 $poll->mask(\*STDOUT => POLLOUT); 109 } elsif ($poll->events(\*STDOUT) & POLLOUT && $sbuf ne '') { 111 110 my $n = syswrite(STDOUT, $sbuf); 112 111 next if $n < 0 and $! == EINTR; … … 114 113 $sbuf = substr($sbuf, $n); 115 114 if ($sbuf eq '') { 116 vec($win, $stdout, 1) = 0;117 vec($rin, $in, 1) = 1;115 $poll->mask(\*STDOUT => POLLHUP); 116 $poll->mask(\*IN => POLLIN); 118 117 } 119 } elsif (vec($wout, $stdout, 1)) { 120 vec($win, $stdout, 1) = 0; 118 } elsif ($poll->events(\*STDOUT)) { 119 $poll->remove(\*STDOUT); 120 $poll->remove(\*IN); 121 121 close(STDOUT) or die "close: $!"; 122 122 close(IN) or die "close: $!"; 123 } elsif ( vec($wout, $out, 1)&& $cbuf ne '') {123 } elsif ($poll->events(\*OUT) & POLLOUT && $cbuf ne '') { 124 124 my $n = syswrite(OUT, $cbuf); 125 125 next if $n < 0 and $! == EINTR; … … 127 127 $cbuf = substr($cbuf, $n); 128 128 if ($cbuf eq '') { 129 vec($win, $out, 1) = 0;130 vec($rin, $stdin, 1) = 1;129 $poll->mask(\*OUT => POLLHUP); 130 $poll->mask(\*STDIN => POLLIN); 131 131 } 132 } elsif (vec($wout, $out, 1)) { 133 vec($win, $out, 1) = 0; 132 } elsif ($poll->events(\*OUT)) { 133 $poll->remove(\*OUT); 134 $poll->remove(\*STDIN); 134 135 close(OUT) or die "close: $!"; 135 136 close(STDIN) or die "close: $!"; 136 137 } 137 138 } 139 140 while (waitpid($pid, 0) == -1 && $! == EINTR) { }
Note: See TracChangeset
for help on using the changeset viewer.