]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: fixup usage of the '-l' switch with IP/INET6 sockets
authorEric Wong <e@80x24.org>
Fri, 11 Mar 2016 21:59:42 +0000 (21:59 +0000)
committerEric Wong <e@80x24.org>
Fri, 11 Mar 2016 22:03:21 +0000 (22:03 +0000)
We need to ensure $sock_pkg is preserved outside of the loop.
The variable passed to "for" or "foreach" is implicitly local
and restores the previous value when the loop exits.  This is
documented in the perlsyn manpage in the "Foreach Loops"
section.

Fixes: ea1b6cbd422b ("daemon: allow using IO::Socket::IP over INET6")
lib/PublicInbox/Daemon.pm

index fcb1a3d358fc444d4653c082d1bceac3895b00fa..c6fb62bf4d46292f4545b4f1c3de98dce4c14f53 100644 (file)
@@ -69,7 +69,8 @@ sub daemon_prepare ($) {
                        $o{Local} = delete $o{Peer};
                } else {
                        # both work for IPv4, too
-                       for $sock_pkg (qw(IO::Socket::IP IO::Socket::INET6)) {
+                       for (qw(IO::Socket::IP IO::Socket::INET6)) {
+                               $sock_pkg = $_;
                                eval "use $sock_pkg";
                                $@ or last;
                        }
@@ -79,7 +80,7 @@ sub daemon_prepare ($) {
                $o{Listen} = 1024;
                my $prev = umask 0000;
                my $s = eval { $sock_pkg->new(%o) };
-               warn "error binding $l: $!\n" unless $s;
+               warn "error binding $l: $! ($@)\n" unless $s;
                umask $prev;
 
                if ($s) {