user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 4/4] use defined-or in a few more places
  2021-01-25  6:41  5% [PATCH 0/4] miscidx: lazy transactions to fix tests Eric Wong
@ 2021-01-25  6:41  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2021-01-25  6:41 UTC (permalink / raw)
  To: meta

Mainly around fork() calls, but some nearby places as well.
---
 lib/PublicInbox/Spawn.pm      |  7 +++----
 lib/PublicInbox/TestCommon.pm | 10 ++++------
 lib/PublicInbox/Watch.pm      |  2 +-
 t/gcf2.t                      |  2 +-
 t/imap_tracker.t              |  2 +-
 t/run.perl                    |  2 +-
 xt/create-many-inboxes.t      |  3 +--
 7 files changed, 12 insertions(+), 16 deletions(-)

diff --git a/lib/PublicInbox/Spawn.pm b/lib/PublicInbox/Spawn.pm
index 86f66605..ef4885c1 100644
--- a/lib/PublicInbox/Spawn.pm
+++ b/lib/PublicInbox/Spawn.pm
@@ -352,8 +352,7 @@ sub which ($) {
 
 sub spawn ($;$$) {
 	my ($cmd, $env, $opts) = @_;
-	my $f = which($cmd->[0]);
-	defined $f or die "$cmd->[0]: command not found\n";
+	my $f = which($cmd->[0]) // die "$cmd->[0]: command not found\n";
 	my @env;
 	$opts ||= {};
 
@@ -365,7 +364,7 @@ sub spawn ($;$$) {
 	for my $child_fd (0..2) {
 		my $parent_fd = $opts->{$child_fd};
 		if (defined($parent_fd) && $parent_fd !~ /\A[0-9]+\z/) {
-			defined(my $fd = fileno($parent_fd)) or
+			my $fd = fileno($parent_fd) //
 					die "$parent_fd not an IO GLOB? $!";
 			$parent_fd = $fd;
 		}
@@ -374,7 +373,7 @@ sub spawn ($;$$) {
 	my $rlim = [];
 
 	foreach my $l (@RLIMITS) {
-		defined(my $v = $opts->{$l}) or next;
+		my $v = $opts->{$l} // next;
 		my $r = eval "require BSD::Resource; BSD::Resource::$l();";
 		unless (defined $r) {
 			warn "$l undefined by BSD::Resource: $@\n";
diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm
index 16ae2650..40c2dc9e 100644
--- a/lib/PublicInbox/TestCommon.pm
+++ b/lib/PublicInbox/TestCommon.pm
@@ -254,8 +254,7 @@ sub run_script ($;$$) {
 		my $cmd = [ key2script($key), @argv ];
 		my $pid = PublicInbox::Spawn::spawn($cmd, $env, $spawn_opt);
 		if (defined $pid) {
-			my $r = waitpid($pid, 0);
-			defined($r) or die "waitpid: $!";
+			my $r = waitpid($pid, 0) // die "waitpid: $!";
 			$r == $pid or die "waitpid: expected $pid, got $r";
 		}
 	} else { # localize and run everything in the same process:
@@ -367,7 +366,7 @@ sub start_script {
 			}
 		}
 		if (@paths) {
-			defined($tail_pid = fork) or die "fork: $!\n";
+			$tail_pid = fork // die "fork: $!";
 			if ($tail_pid == 0) {
 				# make sure files exist, first
 				open my $fh, '>>', $_ for @paths;
@@ -378,7 +377,7 @@ sub start_script {
 			wait_for_tail($tail_pid, scalar @paths);
 		}
 	}
-	defined(my $pid = fork) or die "fork: $!\n";
+	my $pid = fork // die "fork: $!\n";
 	if ($pid == 0) {
 		eval { PublicInbox::DS->Reset };
 		# pretend to be systemd (cf. sd_listen_fds(3))
@@ -440,8 +439,7 @@ sub join {
 	my ($self, $sig) = @_;
 	my $pid = delete $self->{pid} or return;
 	CORE::kill($sig, $pid) if defined $sig;
-	my $ret = waitpid($pid, 0);
-	defined($ret) or die "waitpid($pid): $!";
+	my $ret = waitpid($pid, 0) // die "waitpid($pid): $!";
 	$ret == $pid or die "waitpid($pid) != $ret";
 }
 
diff --git a/lib/PublicInbox/Watch.pm b/lib/PublicInbox/Watch.pm
index 1de5018d..2b44ba43 100644
--- a/lib/PublicInbox/Watch.pm
+++ b/lib/PublicInbox/Watch.pm
@@ -626,7 +626,7 @@ sub imap_idle_fork ($$) {
 	my ($url, $intvl) = @$url_intvl;
 	pipe(my ($r, $w)) or die "pipe: $!";
 	my $seed = rand(0xffffffff);
-	defined(my $pid = fork) or die "fork: $!";
+	my $pid = fork // die "fork: $!";
 	if ($pid == 0) {
 		srand($seed);
 		eval { Net::SSLeay::randomize() };
diff --git a/t/gcf2.t b/t/gcf2.t
index fa907c8b..d12a4420 100644
--- a/t/gcf2.t
+++ b/t/gcf2.t
@@ -114,7 +114,7 @@ SKIP: {
 		$w->blocking($blk);
 		seek($fh, 0, SEEK_SET) or BAIL_OUT "seek: $!";
 		truncate($fh, 0) or BAIL_OUT "truncate: $!";
-		defined(my $pid = fork) or BAIL_OUT "fork: $!";
+		my $pid = fork // BAIL_OUT "fork: $!";
 		if ($pid == 0) {
 			close $w;
 			tick; # wait for parent to block on writev
diff --git a/t/imap_tracker.t b/t/imap_tracker.t
index be7c6e65..90dea99f 100644
--- a/t/imap_tracker.t
+++ b/t/imap_tracker.t
@@ -29,7 +29,7 @@ SKIP: {
 	diag "TEST_STRESS_NPROC=$nproc TEST_STRESS_NR=$nr";
 	require POSIX;
 	for my $n (1..$nproc) {
-		defined(my $pid = fork) or BAIL_OUT "fork: $!";
+		my $pid = fork // BAIL_OUT "fork: $!";
 		if ($pid == 0) {
 			my $url = "imap://example.com/INBOX.$$";
 			my $uidval = time;
diff --git a/t/run.perl b/t/run.perl
index b7cb988b..96db3045 100755
--- a/t/run.perl
+++ b/t/run.perl
@@ -128,7 +128,7 @@ my $eof; # we stop respawning if true
 
 my $start_worker = sub {
 	my ($i, $j, $rd, $todo) = @_;
-	defined(my $pid = fork) or DIE "fork: $!";
+	my $pid = fork // DIE "fork: $!";
 	if ($pid == 0) {
 		$worker = $$;
 		while (1) {
diff --git a/xt/create-many-inboxes.t b/xt/create-many-inboxes.t
index 0c2de40d..f44334cc 100644
--- a/xt/create-many-inboxes.t
+++ b/xt/create-many-inboxes.t
@@ -68,7 +68,7 @@ my @children;
 for my $i (1..$nproc) {
 	my ($r, $w);
 	pipe($r, $w) or BAIL_OUT $!;
-	my $pid = fork;
+	my $pid = fork // BAIL_OUT "fork: $!";
 	if ($pid == 0) {
 		close $w;
 		while (my $i = <$r>) {
@@ -77,7 +77,6 @@ for my $i (1..$nproc) {
 		}
 		_exit(0);
 	}
-	defined $pid or BAIL_OUT "fork: $!";
 	close $r or BAIL_OUT $!;
 	push @children, [ $w, $pid ];
 	$w->autoflush(1);

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/4] miscidx: lazy transactions to fix tests
@ 2021-01-25  6:41  5% Eric Wong
  2021-01-25  6:41  7% ` [PATCH 4/4] use defined-or in a few more places Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2021-01-25  6:41 UTC (permalink / raw)
  To: meta

1/4 fixes a theoretical problem while search of a fix for 2/4
2/4 fixes a real problem with t/lei.t on a weak machine
The rest are some yak shaves I noticed while chasing 2/4

Eric Wong (4):
  lei: use Time::HiRes stat for nanosecond resolution
  miscidx: switch to lazy transactions
  spawn: split() on regexp, not a literal string
  use defined-or in a few more places

 lib/PublicInbox/ExtSearchIdx.pm |  3 +--
 lib/PublicInbox/LEI.pm          |  1 +
 lib/PublicInbox/MiscIdx.pm      | 19 ++++++++++++-------
 lib/PublicInbox/Spawn.pm        |  9 ++++-----
 lib/PublicInbox/TestCommon.pm   | 10 ++++------
 lib/PublicInbox/V2Writable.pm   |  4 ----
 lib/PublicInbox/Watch.pm        |  2 +-
 t/gcf2.t                        |  2 +-
 t/imap_tracker.t                |  2 +-
 t/miscsearch.t                  |  1 -
 t/run.perl                      |  2 +-
 xt/create-many-inboxes.t        |  3 +--
 12 files changed, 27 insertions(+), 31 deletions(-)

^ permalink raw reply	[relevance 5%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2021-01-25  6:41  5% [PATCH 0/4] miscidx: lazy transactions to fix tests Eric Wong
2021-01-25  6:41  7% ` [PATCH 4/4] use defined-or in a few more places Eric Wong

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