From 9ccb05a709bd203a384db0584597d5aaf64b41df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krist=C3=B3f=20T=C3=B3th?= Date: Sat, 4 May 2019 21:06:00 +0200 Subject: [PATCH] Add support for initializing pipes with specific permissions --- pipe_io_server/pipe.py | 10 ++++------ pipe_io_server/pipe_io_server.py | 10 +++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/pipe_io_server/pipe.py b/pipe_io_server/pipe.py index 82af022..f47ba34 100644 --- a/pipe_io_server/pipe.py +++ b/pipe_io_server/pipe.py @@ -1,4 +1,4 @@ -from os import mkfifo, remove +from os import mkfifo, remove, chmod from os.path import exists @@ -6,13 +6,11 @@ class Pipe: def __init__(self, path): self.path = path - def recreate(self): + def recreate(self, permissions): self.remove() - self.create() + mkfifo(self.path) + chmod(self.path, permissions) def remove(self): if exists(self.path): remove(self.path) - - def create(self): - mkfifo(self.path) diff --git a/pipe_io_server/pipe_io_server.py b/pipe_io_server/pipe_io_server.py index 632d92a..6037261 100644 --- a/pipe_io_server/pipe_io_server.py +++ b/pipe_io_server/pipe_io_server.py @@ -8,17 +8,17 @@ from .terminate_process_on_failure import terminate_process_on_failure class PipeIOServer(ABC, Thread): - def __init__(self, in_pipe=None, out_pipe=None): + def __init__(self, in_pipe=None, out_pipe=None, permissions=0o700): super().__init__() self._in_pipe, self._out_pipe = in_pipe, out_pipe - self._create_pipes() + self._create_pipes(permissions) self._stop_event = Event() self._reader_thread, self._writer_thread = self._create_io_threads() self._io_threads = (self._reader_thread, self._writer_thread) - def _create_pipes(self): - Pipe(self.in_pipe).recreate() - Pipe(self.out_pipe).recreate() + def _create_pipes(self, permissions): + Pipe(self.in_pipe).recreate(permissions) + Pipe(self.out_pipe).recreate(permissions) @property def in_pipe(self):