Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #79774
| From | Michael Ströder <michael@stroeder.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: asyncio: setting file permissions of a Unix socket? |
| Date | 2014-10-27 11:19 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <m2l679$q72$1@dont-email.me> (permalink) |
| References | <mailman.15229.1414399500.18130.python-list@python.org> |
Martin wrote:
> I'm using the asyncio.Protocol interface to build a server which binds
> to a unix socket file. I want other system users to connect to the
> unix socket, so to communicate with the server.
>
> Where should I set the permissions of the file?
You should start the demon with a strict umask and set the permissions after
the socket is created.
Deriving from SocketServer.UnixStreamServer I'm overriding the server_bind()
method:
class MyServer(SocketServer.UnixStreamServer):
[..]
def server_bind(self):
"""Override server_bind to set socket options."""
self.socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
self.socket.settimeout(SOCKET_TIMEOUT)
try:
os.unlink(self.server_address)
except OSError:
if os.path.exists(self.server_address):
raise
SocketServer.UnixStreamServer.server_bind(self)
os.chmod(self.server_address,int(SOCKET_PERMISSIONS,8))
return # server_bind()
Ciao, Michael.
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
asyncio: setting file permissions of a Unix socket? Martin <martin@libtec.org> - 2014-10-25 15:42 +0300 Re: asyncio: setting file permissions of a Unix socket? Michael Ströder <michael@stroeder.com> - 2014-10-27 11:19 +0100
csiph-web