Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: =?ISO-8859-1?Q?Michael_Str=F6der?= Newsgroups: comp.lang.python Subject: Re: asyncio: setting file permissions of a Unix socket? Date: Mon, 27 Oct 2014 11:19:26 +0100 Organization: A noiseless patient Spider Lines: 30 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 27 Oct 2014 10:19:21 +0000 (UTC) Injection-Info: mx02.eternal-september.org; posting-host="60ae14806c91d704026e36baba1f1756"; logging-data="26850"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/WBRzJq3kTRLbi47PT/394zRsSM2KEeDE=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26.1 In-Reply-To: Cancel-Lock: sha1:siC2C9rJ3K13p2lFDQ7RALnygTo= Xref: csiph.com comp.lang.python:79774 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.