user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] daemon: sockname detects listeners correctly
@ 2016-03-05 22:42 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2016-03-05 22:42 UTC (permalink / raw)
  To: meta

This means we can avoid false-positives when inheriting multiple
Unix domain sockets.
---
 lib/PublicInbox/Daemon.pm | 4 ++++
 t/httpd-unix.t            | 8 ++++++++
 2 files changed, 12 insertions(+)

diff --git a/lib/PublicInbox/Daemon.pm b/lib/PublicInbox/Daemon.pm
index 5156262..a6707e8 100644
--- a/lib/PublicInbox/Daemon.pm
+++ b/lib/PublicInbox/Daemon.pm
@@ -185,6 +185,10 @@ sub sockname ($) {
 	my ($s) = @_;
 	my $addr = getsockname($s) or return;
 	my ($host, $port) = host_with_port($addr);
+	if ($port == 0 && $host eq '127.0.0.1') {
+		my ($path) = Socket::sockaddr_un($addr);
+		return $path;
+	}
 	"$host:$port";
 }
 
diff --git a/t/httpd-unix.t b/t/httpd-unix.t
index b336849..13df676 100644
--- a/t/httpd-unix.t
+++ b/t/httpd-unix.t
@@ -35,6 +35,14 @@ my $spawn_httpd = sub {
 	ok(defined $pid, 'forked httpd process successfully');
 };
 
+{
+	require PublicInbox::Daemon;
+	my $l = "$tmpdir/named.sock";
+	my $s = IO::Socket::UNIX->new(Listen => 5, Local => $l,
+					Type => SOCK_STREAM);
+	is(PublicInbox::Daemon::sockname($s), $l, 'sockname works for UNIX');
+}
+
 ok(!-S $unix, 'UNIX socket does not exist, yet');
 $spawn_httpd->("-l$unix");
 for (1..1000) {
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2016-03-05 22:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-05 22:42 [PATCH] daemon: sockname detects listeners correctly 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).