From 1d127ce0b2edcc8b03e4cb1031ff341ff91770fe Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 31 Mar 2009 00:19:47 -0700 Subject: Better canonicalization of listener paths + tests * Expand addresses like "1:8080" to "127.0.0.1:8080" beforehand so sock_name() in SocketHelper will always return consistent results. * Add support for "unix:/path/to/foo" paths for easier synchronization with nginx config files. --- lib/unicorn/configurator.rb | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'lib/unicorn') diff --git a/lib/unicorn/configurator.rb b/lib/unicorn/configurator.rb index a69e971..79bbf4b 100644 --- a/lib/unicorn/configurator.rb +++ b/lib/unicorn/configurator.rb @@ -286,16 +286,26 @@ module Unicorn @set[var] = my_proc end + # expands "unix:path/to/foo" to a socket relative to the current path # expands pathnames of sockets if relative to "~" or "~username" # expands "*:port and ":port" to "0.0.0.0:port" def expand_addr(address) #:nodoc return address unless String === address - if address[0..0] == '~' - return File.expand_path(address) - elsif address =~ %r{\A\*?:(\d+)\z} - return "0.0.0.0:#$1" + + case address + when %r{\Aunix:(.*)\z} + File.expand_path($1) + when %r{\A~} + File.expand_path(address) + when %r{\A\*:(\d+)\z} + "0.0.0.0:#$1" + when %r{\A(.*):(\d+)\z} + # canonicalize the name + packed = Socket.pack_sockaddr_in($2.to_i, $1) + Socket.unpack_sockaddr_in(packed).reverse!.join(':') + else + address end - address end end -- cgit v1.2.3-24-ge0c7