Permalink
Browse files

Fix and configure the perms of UNIXServer. Fixes #44

  • Loading branch information...
evanphx committed Mar 30, 2012
1 parent a94e026 commit 3dd7049f4922f4f13375c76bdd29fee46a7eb29e
Showing with 30 additions and 3 deletions.
  1. +8 −0 README.md
  2. +11 −1 lib/puma/cli.rb
  3. +11 −2 lib/puma/server.rb
View
@@ -77,6 +77,14 @@ Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance b
$ puma -b unix:///var/run/puma.sock
+If you need to change the permissions of the UNIX socket, just add a umask parameter:
+
+ $ puma -b 'unix:///var/run/puma.sock?umask=0777'
+
+Need a bit of security? Use SSL sockets!
+
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
+
## License
Puma is copyright 2011 Evan Phoenix and contributors. It is licensed under the BSD license. See the include LICENSE file for details.
View
@@ -243,7 +243,17 @@ def run
log "* Listening on #{str}"
path = "#{uri.host}#{uri.path}"
- server.add_unix_listener path
+ umask = nil
+
+ if uri.query
+ params = Rack::Utils.parse_query uri.query
+ if u = params['umask']
+ # Use Integer() to respect the 0 prefix as octal
+ umask = Integer(u)
+ end
+ end
+
+ server.add_unix_listener path, umask
when "ssl"
log "* Listening on #{str}"
params = Rack::Utils.parse_query uri.query
View
@@ -123,9 +123,18 @@ def add_ssl_listener(host, port, ctx, optimize_for_latency=true, backlog=1024)
# Tell the server to listen on +path+ as a UNIX domain socket.
#
- def add_unix_listener(path)
+ def add_unix_listener(path, umask=nil)
@unix_paths << path
- @ios << UNIXServer.new(path)
+
+ # Let anyone connect by default
+ umask ||= 0
+
+ begin
+ old_mask = File.umask(umask)
+ @ios << UNIXServer.new(path)
+ ensure
+ File.umask old_mask
+ end
end
def backlog

0 comments on commit 3dd7049

Please sign in to comment.