summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAllan Saddi <allan@saddi.com>2006-05-18 16:31:01 +0000
committerAllan Saddi <allan@saddi.com>2006-05-18 16:31:01 +0000
commit1f9ebbb444efc6972d9224461ce40189c56cf876 (patch)
tree1b0cc77f39d012ecf91577aea98c60faeb731215
parent9a65a0bb23ee5835eb84165163eed05c958cb8e7 (diff)
downloadflup-1f9ebbb444efc6972d9224461ce40189c56cf876.tar.gz
Added umask keyword parameter to fcgi and fcgi_fork,
for use when binding to a UNIX socket.
-rw-r--r--ChangeLog5
-rw-r--r--flup/server/fcgi.py3
-rw-r--r--flup/server/fcgi_base.py16
-rw-r--r--flup/server/fcgi_fork.py3
4 files changed, 23 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a56849..fd76797 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-05-18 Allan Saddi <asaddi@kalahari.flup.org>
+
+ * Added umask keyword parameter to fcgi and fcgi_fork,
+ for use when binding to a UNIX socket.
+
2006-05-03 Allan Saddi <asaddi@kalahari.flup.org>
* Fix illusive problem with AJP implementation. Thanks to
diff --git a/flup/server/fcgi.py b/flup/server/fcgi.py
index 2b02126..1b23ddc 100644
--- a/flup/server/fcgi.py
+++ b/flup/server/fcgi.py
@@ -63,7 +63,7 @@ class WSGIServer(BaseFCGIServer, ThreadedServer):
"""
def __init__(self, application, environ=None,
multithreaded=True, multiprocess=False,
- bindAddress=None, multiplexed=False,
+ bindAddress=None, umask=None, multiplexed=False,
debug=True, **kw):
"""
environ, if present, must be a dictionary-like object. Its
@@ -84,6 +84,7 @@ class WSGIServer(BaseFCGIServer, ThreadedServer):
multithreaded=multithreaded,
multiprocess=multiprocess,
bindAddress=bindAddress,
+ umask=umask,
multiplexed=multiplexed,
debug=debug)
for key in ('jobClass', 'jobArgs'):
diff --git a/flup/server/fcgi_base.py b/flup/server/fcgi_base.py
index 52c95dc..bce5155 100644
--- a/flup/server/fcgi_base.py
+++ b/flup/server/fcgi_base.py
@@ -899,7 +899,7 @@ class BaseFCGIServer(object):
def __init__(self, application, environ=None,
multithreaded=True, multiprocess=False,
- bindAddress=None, multiplexed=False,
+ bindAddress=None, umask=None, multiplexed=False,
debug=True):
"""
bindAddress, if present, must either be a string or a 2-tuple. If
@@ -911,6 +911,11 @@ class BaseFCGIServer(object):
is the interface name/IP to bind to, and the second element (an int)
is the port number.
+ If binding to a UNIX socket, umask may be set to specify what
+ the umask is to be changed to before the socket is created in the
+ filesystem. After the socket is created, the previous umask is
+ restored.
+
Set multiplexed to True if you want to handle multiple requests
per connection. Some FastCGI backends (namely mod_fastcgi) don't
multiplex requests at all, so by default this is off (which saves
@@ -928,7 +933,8 @@ class BaseFCGIServer(object):
self.debug = debug
self._bindAddress = bindAddress
-
+ self._umask = umask
+
# Used to force single-threadedness
self._appLock = thread.allocate_lock()
@@ -987,6 +993,7 @@ class BaseFCGIServer(object):
sys.exit(0)
else:
# Run as a server
+ oldUmask = None
if type(self._bindAddress) is str:
# Unix socket
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
@@ -994,6 +1001,8 @@ class BaseFCGIServer(object):
os.unlink(self._bindAddress)
except OSError:
pass
+ if self._umask is not None:
+ oldUmask = os.umask(self._umask)
else:
# INET socket
assert type(self._bindAddress) is tuple
@@ -1004,6 +1013,9 @@ class BaseFCGIServer(object):
sock.bind(self._bindAddress)
sock.listen(socket.SOMAXCONN)
+ if oldUmask is not None:
+ os.umask(oldUmask)
+
return sock
def _cleanupSocket(self, sock):
diff --git a/flup/server/fcgi_fork.py b/flup/server/fcgi_fork.py
index 352f3a8..d8de255 100644
--- a/flup/server/fcgi_fork.py
+++ b/flup/server/fcgi_fork.py
@@ -63,7 +63,7 @@ class WSGIServer(BaseFCGIServer, PreforkServer):
<http://www.python.org/peps/pep-0333.html>.
"""
def __init__(self, application, environ=None,
- bindAddress=None, multiplexed=False,
+ bindAddress=None, umask=None, multiplexed=False,
debug=True, **kw):
"""
environ, if present, must be a dictionary-like object. Its
@@ -84,6 +84,7 @@ class WSGIServer(BaseFCGIServer, PreforkServer):
multithreaded=False,
multiprocess=True,
bindAddress=bindAddress,
+ umask=umask,
multiplexed=multiplexed,
debug=debug)
for key in ('multithreaded', 'multiprocess', 'jobClass', 'jobArgs'):