Changeset 903 for server/common/oursrc/execsys/gitproxy.pl
- Timestamp:
- Dec 28, 2008, 1:21:33 AM (15 years ago)
- File:
-
- 1 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) { }
Note: See TracChangeset
for help on using the changeset viewer.