user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH] localize $/ in more places to avoid potential problems
Date: Sat, 21 May 2016 05:31:05 +0000	[thread overview]
Message-ID: <20160521053105.GA12422@dcvr.yhbt.net> (raw)
In-Reply-To: <20160521030317.24152-1-e@80x24.org>

This hopefully makes the intent of the code clearer, too.
The the HTTP use of the numeric reference for getline
caused problems in Git.pm, already.
---
 lib/PublicInbox/Config.pm    | 1 +
 lib/PublicInbox/Daemon.pm    | 1 +
 lib/PublicInbox/Feed.pm      | 2 ++
 lib/PublicInbox/Git.pm       | 1 +
 lib/PublicInbox/SearchIdx.pm | 2 ++
 t/httpd-corner.psgi          | 2 ++
 t/httpd-unix.t               | 1 +
 7 files changed, 10 insertions(+)

diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm
index b5f0fcb..b38f444 100644
--- a/lib/PublicInbox/Config.pm
+++ b/lib/PublicInbox/Config.pm
@@ -80,6 +80,7 @@ sub git_config_dump {
 	my $pid = open(my $fh, '-|', @cmd);
 	defined $pid or die "$cmd failed: $!";
 	my %rv;
+	local $/ = "\n";
 	foreach my $line (<$fh>) {
 		chomp $line;
 		my ($k, $v) = split(/=/, $line, 2);
diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 8de7ff2..dc81010 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -350,6 +350,7 @@ sub unlink_pid_file_safe_ish ($$) {
 	return unless defined $unlink_pid && $unlink_pid == $$;
 
 	open my $fh, '<', $file or return;
+	local $/ = "\n";
 	defined(my $read_pid = <$fh>) or return;
 	chomp $read_pid;
 	if ($read_pid == $unlink_pid) {
diff --git a/lib/PublicInbox/Feed.pm b/lib/PublicInbox/Feed.pm
index e2df97b..6ed0085 100644
--- a/lib/PublicInbox/Feed.pm
+++ b/lib/PublicInbox/Feed.pm
@@ -224,6 +224,7 @@ sub each_recent_blob {
 	my $nr = 0;
 	my ($cur_commit, $first_commit, $last_commit);
 	my ($ts, $subj, $u);
+	local $/ = "\n";
 	while (defined(my $line = <$log>)) {
 		if ($line =~ /$addmsg/o) {
 			my $add = $1;
@@ -244,6 +245,7 @@ sub each_recent_blob {
 	}
 
 	if ($last) {
+		local $/ = "\n";
 		while (my $line = <$log>) {
 			if ($line =~ /^(${hex}{7,40})/o) {
 				$last_commit = $1;
diff --git a/lib/PublicInbox/Git.pm b/lib/PublicInbox/Git.pm
index 473cdff..bc0e506 100644
--- a/lib/PublicInbox/Git.pm
+++ b/lib/PublicInbox/Git.pm
@@ -122,6 +122,7 @@ sub popen {
 sub qx {
 	my ($self, @cmd) = @_;
 	my $fh = $self->popen(@cmd);
+	local $/ = "\n";
 	return <$fh> if wantarray;
 	local $/;
 	<$fh>
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 9192bb0..4a4b2bd 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -338,6 +338,7 @@ sub rlog {
 				--raw -r --no-abbrev/, $range);
 	my $latest;
 	my $bytes;
+	local $/ = "\n";
 	while (defined(my $line = <$log>)) {
 		if ($line =~ /$addmsg/o) {
 			my $mime = do_cat_mail($git, $1, \$bytes) or next;
@@ -445,6 +446,7 @@ sub _read_git_config_perm {
 	my ($self) = @_;
 	my @cmd = qw(config core.sharedRepository);
 	my $fh = PublicInbox::Git->new($self->{git_dir})->popen(@cmd);
+	local $/ = "\n";
 	my $perm = <$fh>;
 	chomp $perm if defined $perm;
 	$perm;
diff --git a/t/httpd-corner.psgi b/t/httpd-corner.psgi
index 2f7be83..222b9e0 100644
--- a/t/httpd-corner.psgi
+++ b/t/httpd-corner.psgi
@@ -30,6 +30,7 @@ my $app = sub {
 			return sub {
 				open my $f, '<', $fifo or
 						die "open $fifo: $!\n";
+				local $/ = "\n";
 				my @r = <$f>;
 				$_[0]->([200, $h, \@r ]);
 			};
@@ -38,6 +39,7 @@ my $app = sub {
 				my $fh = $_[0]->([200, $h]);
 				open my $f, '<', $fifo or
 						die "open $fifo: $!\n";
+				local $/ = "\n";
 				while (defined(my $l = <$f>)) {
 					$fh->write($l);
 				}
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index 00adf13..16f7bdd 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -103,6 +103,7 @@ SKIP: {
 
 	ok(-f "$tmpdir/pid", 'pid file written');
 	open my $fh, '<', "$tmpdir/pid" or die "open failed: $!";
+	local $/ = "\n";
 	my $rpid = <$fh>;
 	chomp $rpid;
 	like($rpid, qr/\A\d+\z/s, 'pid file looks like a pid');

      parent reply	other threads:[~2016-05-21  5:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-21  3:03 [PATCH 0/2] http: start migrating to pull-based I/O Eric Wong
2016-05-21  3:03 ` [PATCH 1/2] http: reduce over-buffering for getline responses Eric Wong
2016-05-21  3:03 ` [PATCH 2/2] mbox: switch generation over to pull model Eric Wong
2016-05-21  4:43 ` [PATCH 4/1] unsubscribe: prevent decrypt from showing random crap Eric Wong
2016-05-21  5:31 ` Eric Wong [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160521053105.GA12422@dcvr.yhbt.net \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

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).