]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: sockname detects listeners correctly
authorEric Wong <e@80x24.org>
Sat, 5 Mar 2016 22:42:16 +0000 (22:42 +0000)
committerEric Wong <e@80x24.org>
Sat, 5 Mar 2016 22:42:38 +0000 (22:42 +0000)
This means we can avoid false-positives when inheriting multiple
Unix domain sockets.

lib/PublicInbox/Daemon.pm
t/httpd-unix.t

index 51562624847852f56abeb4cab5c15f3ec0a88d6e..a6707e832621812c055ec380a07b527b3e7be0d2 100644 (file)
@@ -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";
 }
 
index b3368491b14bb892efa813e790999fff92155486..13df676b5fcf361a60493acfbf6aa9b440981ea2 100644 (file)
@@ -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) {