unofficial mirror of meta@public-inbox.org
 help / color / mirror / Atom feed
* [PATCH 0/8] another round of HTTP-related fixes
@ 2016-02-29  1:40 Eric Wong
  2016-02-29  1:41 ` [PATCH 1/8] http: error check for sysseek on input Eric Wong
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:40 UTC (permalink / raw)
  To: meta

git clone for Smart HTTP now works properly when using Apache2 \o/

Eric Wong (8):
      http: error check for sysseek on input
      http: document event_write usage
      http: avoid needless time2str calls
      distinguish error messages intended for users vs developers
      favor procedural calls for most private functions
      git-http-backend: stricter parsing of CRLF
      spawnpp: use env(1) for mod_perl compatibility
      git-http-backend: fixes for mod_perl

 lib/PublicInbox/Config.pm         |  6 +++---
 lib/PublicInbox/Daemon.pm         | 18 ++++++++----------
 lib/PublicInbox/GitHTTPBackend.pm | 12 ++++++------
 lib/PublicInbox/HTTP.pm           | 40 ++++++++++++++++++++++-----------------
 lib/PublicInbox/NNTP.pm           | 30 ++++++++++++++---------------
 lib/PublicInbox/Spawn.pm          |  3 ++-
 lib/PublicInbox/SpawnPP.pm        |  9 ++-------
 lib/PublicInbox/WWW.pm            |  2 +-
 script/public-inbox-httpd         |  2 +-
 9 files changed, 61 insertions(+), 61 deletions(-)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/8] http: error check for sysseek on input
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 2/8] http: document event_write usage Eric Wong
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

Just in case we screwed up somewhere, we need to match up
syswrite to sysseek and we also favor procedural calls for
native types.
---
 lib/PublicInbox/HTTP.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 928c0f2..4d771f2 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -109,7 +109,7 @@ sub app_dispatch ($) {
 		$host =~ s/:(\d+)\z// and $env->{SERVER_PORT} = $1;
 		$env->{SERVER_NAME} = $host;
 	}
-	$env->{'psgi.input'}->seek(0, SEEK_SET);
+	sysseek($env->{'psgi.input'}, 0, SEEK_SET) or die "input seek failed: $!";
 	my $res = Plack::Util::run_app($self->{httpd}->{app}, $env);
 	eval {
 		if (ref($res) eq 'CODE') {
@@ -204,7 +204,7 @@ sub event_write {
 	if ($self->{rbuf} eq '') {
 		$self->watch_read(1);
 	} else {
-		# avoid recursion
+		# avoid recursion for pipelined requests
 		Danga::Socket->AddTimer(0, sub { rbuf_process($self) });
 	}
 }
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/8] http: document event_write usage
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
  2016-02-29  1:41 ` [PATCH 1/8] http: error check for sysseek on input Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 3/8] http: avoid needless time2str calls Eric Wong
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

It may not be obvious where we are when we enter the event_write
callback.  Hopefully this clarifies things.
---
 lib/PublicInbox/HTTP.pm | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 4d771f2..a472388 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -201,10 +201,9 @@ sub event_write {
 	# only continue watching for readability when we are done writing:
 	return if $self->write(undef) != 1;
 
-	if ($self->{rbuf} eq '') {
+	if ($self->{rbuf} eq '') { # wait for next request
 		$self->watch_read(1);
-	} else {
-		# avoid recursion for pipelined requests
+	} else { # avoid recursion for pipelined requests
 		Danga::Socket->AddTimer(0, sub { rbuf_process($self) });
 	}
 }
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/8] http: avoid needless time2str calls
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
  2016-02-29  1:41 ` [PATCH 1/8] http: error check for sysseek on input Eric Wong
  2016-02-29  1:41 ` [PATCH 2/8] http: document event_write usage Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 4/8] distinguish error messages intended for users vs developers Eric Wong
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

Checking the time is nearly free on modern systems with
vDSO/vsyscall/similar while sprintf is always expensive.
---
 lib/PublicInbox/HTTP.pm | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index a472388..14971f4 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -17,7 +17,6 @@ use HTTP::Parser::XS qw(parse_http_request); # supports pure Perl fallback
 use HTTP::Status qw(status_message);
 use HTTP::Date qw(time2str);
 use IO::File;
-my $null_io = IO::File->new('/dev/null', '<');
 use constant {
 	CHUNK_START => -1,   # [a-f0-9]+\r\n
 	CHUNK_END => -2,     # \r\n
@@ -25,6 +24,14 @@ use constant {
 	CHUNK_MAX_HDR => 256,
 };
 
+my $null_io = IO::File->new('/dev/null', '<');
+my $http_date;
+my $prev = 0;
+sub http_date () {
+	my $now = time;
+	$now == $prev ? $http_date : ($http_date = time2str($prev = $now));
+}
+
 sub new ($$$) {
 	my ($class, $sock, $addr, $httpd) = @_;
 	my $self = fields::new($class);
@@ -148,7 +155,7 @@ sub response_header_write {
 			($conn =~ /\bkeep-alive\b/i);
 
 	$h .= 'Connection: ' . ($alive ? 'keep-alive' : 'close');
-	$h .= "\r\nDate: " . time2str(time) . "\r\n\r\n";
+	$h .= "\r\nDate: " . http_date() . "\r\n\r\n";
 
 	if (($len || $chunked) && $env->{REQUEST_METHOD} ne 'HEAD') {
 		more($self, $h);
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/8] distinguish error messages intended for users vs developers
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
                   ` (2 preceding siblings ...)
  2016-02-29  1:41 ` [PATCH 3/8] http: avoid needless time2str calls Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 5/8] favor procedural calls for most private functions Eric Wong
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

For error messages intended to show user error (e.g. giving
invalid options), we add a newline ("\n") at the end to
polluting the output with location information.

However, for diagnosing non-user-triggered errors, we should
show the location of where the error occured.
---
 lib/PublicInbox/Config.pm |  6 +++---
 lib/PublicInbox/Daemon.pm | 18 ++++++++----------
 lib/PublicInbox/NNTP.pm   |  2 +-
 lib/PublicInbox/WWW.pm    |  2 +-
 4 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index b511638..f84a955 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -73,7 +73,7 @@ sub git_config_dump {
 	my @cmd = (qw/git config/, "--file=$file", '-l');
 	my $cmd = join(' ', @cmd);
 	my $pid = open(my $fh, '-|', @cmd);
-	defined $pid or die "$cmd failed: $!\n";
+	defined $pid or die "$cmd failed: $!";
 	my %rv;
 	foreach my $line (<$fh>) {
 		chomp $line;
@@ -90,8 +90,8 @@ sub git_config_dump {
 			$rv{$k} = $v;
 		}
 	}
-	close $fh or die "failed to close ($cmd) pipe: $!\n";
-	$? and warn "$$ $cmd exited with: ($pid) $?\n";
+	close $fh or die "failed to close ($cmd) pipe: $!";
+	$? and warn "$$ $cmd exited with: ($pid) $?";
 	\%rv;
 }
 
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index b8482d3..45c1563 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -67,12 +67,12 @@ sub daemon_prepare ($) {
 			warn "error binding $l: $!\n";
 		}
 	}
-	die 'No listeners bound' unless @listeners;
+	die "No listeners bound\n" unless @listeners;
 }
 
 sub daemonize () {
-	chdir '/' or die "chdir failed: $!\n";
-	open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!\n";
+	chdir '/' or die "chdir failed: $!";
+	open(STDIN, '+<', '/dev/null') or die "redirect stdin failed: $!";
 
 	return unless (defined $pid_file || defined $group || defined $user
 			|| $daemonize);
@@ -238,12 +238,10 @@ sub do_fork () {
 	my $new = POSIX::SigSet->new;
 	$new->fillset;
 	my $old = POSIX::SigSet->new;
-	POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new, $old) or
-				die "SIG_BLOCK: $!\n";
+	POSIX::sigprocmask(&POSIX::SIG_BLOCK, $new, $old) or die "SIG_BLOCK: $!";
 	my $pid = fork;
 	my $err = $!;
-	POSIX::sigprocmask(&POSIX::SIG_SETMASK, $old) or
-				die "SIG_SETMASK: $!\n";
+	POSIX::sigprocmask(&POSIX::SIG_SETMASK, $old) or die "SIG_SETMASK: $!";
 	($pid, $err);
 }
 
@@ -254,7 +252,7 @@ sub upgrade_aborted ($) {
 	return unless $pid_file;
 
 	my $file = $pid_file;
-	$file =~ s/\.oldbin\z// or die "BUG: no '.oldbin' suffix in $file\n";
+	$file =~ s/\.oldbin\z// or die "BUG: no '.oldbin' suffix in $file";
 	unlink_pid_file_safe_ish($$, $pid_file);
 	$pid_file = $file;
 	eval { write_pid($pid_file) };
@@ -289,8 +287,8 @@ sub unlink_pid_file_safe_ish ($$) {
 }
 
 sub master_loop {
-	pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!\n";
-	pipe(my ($r, $w)) or die "failed to create self-pipe: $!\n";
+	pipe(my ($p0, $p1)) or die "failed to create parent-pipe: $!";
+	pipe(my ($r, $w)) or die "failed to create self-pipe: $!";
 	IO::Handle::blocking($w, 0);
 	my $set_workers = $worker_processes;
 	my @caught;
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index bcce770..fbf8f7f 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -229,7 +229,7 @@ sub parse_time ($$;$) {
 	use Time::Local qw();
 	my ($hh, $mm, $ss) = unpack('A2A2A2', $time);
 	if (defined $gmt) {
-		$gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt\n";
+		$gmt =~ /\A(?:UTC|GMT)\z/i or die "GM invalid: $gmt";
 		$gmt = 1;
 	}
 	my @now = $gmt ? gmtime : localtime;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 2da819b..98e33fd 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -244,7 +244,7 @@ sub get_thread {
 sub ctx_get {
 	my ($ctx, $key) = @_;
 	my $val = $ctx->{$key};
-	(defined $val && $val ne '') or die "BUG: bad ctx, $key unusable\n";
+	(defined $val && $val ne '') or die "BUG: bad ctx, $key unusable";
 	$val;
 }
 
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/8] favor procedural calls for most private functions
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
                   ` (3 preceding siblings ...)
  2016-02-29  1:41 ` [PATCH 4/8] distinguish error messages intended for users vs developers Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 6/8] git-http-backend: stricter parsing of CRLF Eric Wong
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

This makes for better compile-time checking and also helps
document which calls are private for HTTP and NNTP.

While we're at it, use IO::Handle::* functions procedurally,
too, since we know we're working with native glob handles.
---
 lib/PublicInbox/HTTP.pm   | 22 +++++++++++-----------
 lib/PublicInbox/NNTP.pm   | 28 ++++++++++++++--------------
 lib/PublicInbox/Spawn.pm  |  3 ++-
 script/public-inbox-httpd |  2 +-
 4 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index 14971f4..aaae7ab 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -68,7 +68,7 @@ sub rbuf_process {
 
 	# We do not support Trailers in chunked requests, for now
 	# (they are rarely-used and git (as of 2.7.2) does not use them)
-	return $self->quit(400) if $r == -1 || $env{HTTP_TRAILER};
+	return quit($self, 400) if $r == -1 || $env{HTTP_TRAILER};
 	return $self->watch_read(1) if $r < 0; # incomplete
 	$self->{rbuf} = substr($self->{rbuf}, $r);
 	my $len = input_prepare($self, \%env);
@@ -90,7 +90,7 @@ sub event_read_input ($) {
 	while ($len > 0) {
 		if ($$rbuf ne '') {
 			my $w = write_in_full($input, $rbuf, $len);
-			return $self->write_err unless $w;
+			return write_err($self) unless $w;
 			$len -= $w;
 			die "BUG: $len < 0 (w=$w)" if $len < 0;
 			if ($len == 0) { # next request may be pipelined
@@ -100,7 +100,7 @@ sub event_read_input ($) {
 			$$rbuf = '';
 		}
 		my $r = sysread($sock, $$rbuf, 8192);
-		return $self->recv_err($r, $len) unless $r;
+		return recv_err($self, $r, $len) unless $r;
 		# continue looping if $r > 0;
 	}
 	app_dispatch($self);
@@ -238,7 +238,7 @@ sub write_err {
 	my $err = $self->{env}->{'psgi.errors'};
 	my $msg = $! || '(zero write)';
 	$err->print("error buffering to input: $msg\n");
-	$self->quit(500);
+	quit($self, 500);
 }
 
 sub recv_err {
@@ -250,7 +250,7 @@ sub recv_err {
 	}
 	my $err = $self->{env}->{'psgi.errors'};
 	$err->print("error reading for input: $! ($len bytes remaining)\n");
-	$self->quit(500);
+	quit($self, 500);
 }
 
 sub write_in_full {
@@ -278,20 +278,20 @@ sub event_read_input_chunked { # unlikely...
 	while (1) { # chunk start
 		if ($len == CHUNK_ZEND) {
 			return app_dispatch($self) if $$rbuf =~ s/\A\r\n//s;
-			return $self->quit(400) if length($$rbuf) > 2;
+			return quit($self, 400) if length($$rbuf) > 2;
 		}
 		if ($len == CHUNK_END) {
 			if ($$rbuf =~ s/\A\r\n//s) {
 				$len = CHUNK_START;
 			} elsif (length($$rbuf) > 2) {
-				return $self->quit(400);
+				return quit($self, 400);
 			}
 		}
 		if ($len == CHUNK_START) {
 			if ($$rbuf =~ s/\A([a-f0-9]+).*?\r\n//i) {
 				$len = hex $1;
 			} elsif (length($$rbuf) > CHUNK_MAX_HDR) {
-				return $self->quit(400);
+				return quit($self, 400);
 			}
 			# will break from loop since $len >= 0
 		}
@@ -299,7 +299,7 @@ sub event_read_input_chunked { # unlikely...
 		if ($len < 0) { # chunk header is trickled, read more
 			my $off = length($$rbuf);
 			my $r = sysread($sock, $$rbuf, 8192, $off);
-			return $self->recv_err($r, $len) unless $r;
+			return recv_err($self, $r, $len) unless $r;
 			# (implicit) goto chunk_start if $r > 0;
 		}
 		$len = CHUNK_ZEND if $len == 0;
@@ -308,7 +308,7 @@ sub event_read_input_chunked { # unlikely...
 		until ($len <= 0) {
 			if ($$rbuf ne '') {
 				my $w = write_in_full($input, $rbuf, $len);
-				return $self->write_err unless $w;
+				return write_err($self) unless $w;
 				$len -= $w;
 				if ($len == 0) {
 					# we may have leftover data to parse
@@ -324,7 +324,7 @@ sub event_read_input_chunked { # unlikely...
 			if ($$rbuf eq '') {
 				# read more of current chunk
 				my $r = sysread($sock, $$rbuf, 8192);
-				return $self->recv_err($r, $len) unless $r;
+				return recv_err($self, $r, $len) unless $r;
 			}
 		}
 	}
diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index fbf8f7f..8740377 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -212,7 +212,7 @@ sub cmd_listgroup ($;$) {
 	}
 
 	$self->{ng} or return '412 no newsgroup selected';
-	$self->long_response(0, long_response_limit, sub {
+	long_response($self, 0, long_response_limit, sub {
 		my ($i) = @_;
 		my $nr = $self->{ng}->mm->id_batch($$i, sub {
 			my ($ary) = @_;
@@ -322,7 +322,7 @@ sub cmd_newnews ($$$$;$$) {
 
 	$ts .= '..';
 	my $opts = { asc => 1, limit => 1000, offset => 0 };
-	$self->long_response(0, long_response_limit, sub {
+	long_response($self, 0, long_response_limit, sub {
 		my ($i) = @_;
 		my $srch = $srch[0];
 		my $res = $srch->query($ts, $opts);
@@ -462,7 +462,7 @@ sub set_art {
 
 sub cmd_article ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 1);
+	my $r = art_lookup($self, $art, 1);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -474,7 +474,7 @@ sub cmd_article ($;$) {
 
 sub cmd_head ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 2);
+	my $r = art_lookup($self, $art, 2);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -485,7 +485,7 @@ sub cmd_head ($;$) {
 
 sub cmd_body ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 0);
+	my $r = art_lookup($self, $art, 0);
 	return $r unless ref $r;
 	my ($n, $mid, $s) = @$r;
 	set_art($self, $art);
@@ -495,7 +495,7 @@ sub cmd_body ($;$) {
 
 sub cmd_stat ($;$) {
 	my ($self, $art) = @_;
-	my $r = $self->art_lookup($art, 0);
+	my $r = art_lookup($self, $art, 0);
 	return $r unless ref $r;
 	my ($n, $mid, undef) = @$r;
 	set_art($self, $art);
@@ -612,7 +612,7 @@ sub hdr_message_id ($$$) { # optimize XHDR Message-ID [range] for slrnpull.
 		my $mm = $self->{ng}->mm;
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $mid = $mm->mid_for($$i);
 			more($self, "$$i <$mid>") if defined $mid;
@@ -655,7 +655,7 @@ sub hdr_xref ($$$) { # optimize XHDR Xref [range] for rtin
 		my $mm = $ng->mm;
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $mid = $mm->mid_for($$i);
 			more($self, "$$i ".xref($ng, $$i)) if defined $mid;
@@ -686,7 +686,7 @@ sub hdr_searchmsg ($$$$) {
 		my ($beg, $end) = @$r;
 		more($self, $xhdr ? r221 : r225);
 		my $off = 0;
-		$self->long_response($beg, $end, sub {
+		long_response($self, $beg, $end, sub {
 			my ($i) = @_;
 			my $res = $srch->query_xover($beg, $end, $off);
 			my $msgs = $res->{msgs};
@@ -772,7 +772,7 @@ sub cmd_xrover ($;$) {
 	my $mm = $ng->mm;
 	my $srch = $ng->search;
 	more($self, '224 Overview information follows');
-	$self->long_response($beg, $end, sub {
+	long_response($self, $beg, $end, sub {
 		my ($i) = @_;
 		my $mid = $mm->mid_for($$i) or return;
 		my $h = search_header_for($srch, $mid, 'references');
@@ -822,7 +822,7 @@ sub cmd_xover ($;$) {
 	more($self, "224 Overview information follows for $beg to $end");
 	my $srch = $self->{ng}->search;
 	my $off = 0;
-	$self->long_response($beg, $end, sub {
+	long_response($self, $beg, $end, sub {
 		my ($i) = @_;
 		my $res = $srch->query_xover($beg, $end, $off);
 		my $msgs = $res->{msgs};
@@ -896,7 +896,7 @@ sub do_more ($$) {
 			$data = substr($data, $n, $dlen - $n);
 		}
 	}
-	$self->do_write($data);
+	do_write($self, $data);
 }
 
 # callbacks for Danga::Socket
@@ -924,7 +924,7 @@ sub event_read {
 		my $line = $1;
 		my $t0 = now();
 		my $fd = $self->{fd};
-		$r = eval { $self->process_line($line) };
+		$r = eval { process_line($self, $line) };
 		my $d = $self->{long_res} ?
 			" deferred[$fd]" : '';
 		out($self, "[$fd] %s - %0.6f$d", $line, now() - $t0);
@@ -947,7 +947,7 @@ sub watch_read {
 		# another long response.
 		Danga::Socket->AddTimer(0, sub {
 			if (&Danga::Socket::POLLIN & $self->{event_watch}) {
-				$self->event_read;
+				event_read($self);
 			}
 		});
 	}
diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 02c5446..23f303f 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -15,6 +15,7 @@ use strict;
 use warnings;
 use base qw(Exporter);
 use Symbol qw(gensym);
+use IO::Handle;
 use PublicInbox::ProcessPipe;
 our @EXPORT_OK = qw/which spawn popen_rd/;
 
@@ -168,7 +169,7 @@ sub popen_rd {
 	pipe(my ($r, $w)) or die "pipe: $!\n";
 	$opts ||= {};
 	my $blocking = $opts->{Blocking};
-	$r->blocking($blocking) if defined $blocking;
+	IO::Handle::blocking($r, $blocking) if defined $blocking;
 	$opts->{1} = fileno($w);
 	my $pid = spawn($cmd, $env, $opts);
 	return ($r, $pid) if wantarray;
diff --git a/script/public-inbox-httpd b/script/public-inbox-httpd
index 19315bb..f1a5d79 100755
--- a/script/public-inbox-httpd
+++ b/script/public-inbox-httpd
@@ -68,7 +68,7 @@ use fields qw(cb);
 sub new {
 	my ($class, $io, $cb) = @_;
 	my $self = fields::new($class);
-	$io->blocking(0);
+	IO::Handle::blocking($io, 0);
 	$self->SUPER::new($io);
 	$self->{cb} = $cb;
 	$self->watch_read(1);
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/8] git-http-backend: stricter parsing of CRLF
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
                   ` (4 preceding siblings ...)
  2016-02-29  1:41 ` [PATCH 5/8] favor procedural calls for most private functions Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 7/8] spawnpp: use env(1) for mod_perl compatibility Eric Wong
  2016-02-29  1:41 ` [PATCH 8/8] git-http-backend: fixes for mod_perl Eric Wong
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

It is not needed as we know git uses CRLF termination.
---
 lib/PublicInbox/GitHTTPBackend.pm | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 6e8ad95..8e6d8b6 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -201,11 +201,11 @@ sub serve_smart {
 		if ($fh) { # stream body from git-http-backend to HTTP client
 			$fh->write($buf);
 			$buf = '';
-		} elsif ($buf =~ s/\A(.*?)\r?\n\r?\n//s) { # parse headers
+		} elsif ($buf =~ s/\A(.*?)\r\n\r\n//s) { # parse headers
 			my $h = $1;
 			my $code = 200;
 			my @h;
-			foreach my $l (split(/\r?\n/, $h)) {
+			foreach my $l (split(/\r\n/, $h)) {
 				my ($k, $v) = split(/:\s*/, $l, 2);
 				if ($k =~ /\AStatus\z/i) {
 					$code = int($v);
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 7/8] spawnpp: use env(1) for mod_perl compatibility
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
                   ` (5 preceding siblings ...)
  2016-02-29  1:41 ` [PATCH 6/8] git-http-backend: stricter parsing of CRLF Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  2016-02-29  1:41 ` [PATCH 8/8] git-http-backend: fixes for mod_perl Eric Wong
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

We cannot modify %ENV directly under mod_perl (even after forking!),
so use env(1) instead to pass the environment.
---
 lib/PublicInbox/SpawnPP.pm | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/lib/PublicInbox/SpawnPP.pm b/lib/PublicInbox/SpawnPP.pm
index 288625d..dc2ef36 100644
--- a/lib/PublicInbox/SpawnPP.pm
+++ b/lib/PublicInbox/SpawnPP.pm
@@ -19,13 +19,8 @@ sub public_inbox_fork_exec ($$$$$$) {
 		if ($err != 2) {
 			dup2($err, 2) or die "dup2 failed for stderr: $!";
 		}
-		%ENV = ();
-		foreach my $e (@$env) {
-			my ($k, $v) = split('=', $e, 2);
-			$ENV{$k} = $v;
-		}
-		exec @$cmd;
-		die "exec $cmd->[0] failed: $!\n";
+		exec qw(env -i), @$env, @$cmd;
+		die "exec env -i ... $cmd->[0] failed: $!\n";
 	}
 	$pid;
 }
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 8/8] git-http-backend: fixes for mod_perl
  2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
                   ` (6 preceding siblings ...)
  2016-02-29  1:41 ` [PATCH 7/8] spawnpp: use env(1) for mod_perl compatibility Eric Wong
@ 2016-02-29  1:41 ` Eric Wong
  7 siblings, 0 replies; 9+ messages in thread
From: Eric Wong @ 2016-02-29  1:41 UTC (permalink / raw)
  To: meta

Apache2 mod_perl does not give us a real file handle, so
we must translate that before giving that to git-http-backend(1).

Also, parse the Status: correctly for errors since we failed to
set %ENV properly before the previous fix for SpawnPP
---
 lib/PublicInbox/GitHTTPBackend.pm | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/GitHTTPBackend.pm b/lib/PublicInbox/GitHTTPBackend.pm
index 8e6d8b6..56bf24f 100644
--- a/lib/PublicInbox/GitHTTPBackend.pm
+++ b/lib/PublicInbox/GitHTTPBackend.pm
@@ -132,9 +132,10 @@ sub serve_smart {
 	my $buf;
 	my $in;
 	my $err = $env->{'psgi.errors'};
-	if (fileno($input) >= 0) {
+	my $fd = eval { fileno($input) };
+	if (defined $fd && $fd >= 0) {
 		$in = $input;
-	} else { # FIXME untested
+	} else {
 		$in = input_to_file($env) or return r(500);
 	}
 	my ($rpipe, $wpipe);
@@ -208,7 +209,7 @@ sub serve_smart {
 			foreach my $l (split(/\r\n/, $h)) {
 				my ($k, $v) = split(/:\s*/, $l, 2);
 				if ($k =~ /\AStatus\z/i) {
-					$code = int($v);
+					($code) = ($v =~ /\b(\d+)\b/);
 				} else {
 					push @h, $k, $v;
 				}
@@ -233,7 +234,6 @@ sub serve_smart {
 	}
 }
 
-# FIXME: untested, our -httpd _always_ gives a real file handle
 sub input_to_file {
 	my ($env) = @_;
 	my $in = IO::File->new_tmpfile;
-- 
EW


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2016-02-29  1:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-29  1:40 [PATCH 0/8] another round of HTTP-related fixes Eric Wong
2016-02-29  1:41 ` [PATCH 1/8] http: error check for sysseek on input Eric Wong
2016-02-29  1:41 ` [PATCH 2/8] http: document event_write usage Eric Wong
2016-02-29  1:41 ` [PATCH 3/8] http: avoid needless time2str calls Eric Wong
2016-02-29  1:41 ` [PATCH 4/8] distinguish error messages intended for users vs developers Eric Wong
2016-02-29  1:41 ` [PATCH 5/8] favor procedural calls for most private functions Eric Wong
2016-02-29  1:41 ` [PATCH 6/8] git-http-backend: stricter parsing of CRLF Eric Wong
2016-02-29  1:41 ` [PATCH 7/8] spawnpp: use env(1) for mod_perl compatibility Eric Wong
2016-02-29  1:41 ` [PATCH 8/8] git-http-backend: fixes for mod_perl Eric Wong

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).