python - Using multiprocessing.Manager() with multiple users yields permission denied -
i have process running root needs spin threads off run various users. part working fine, need way communicate between kid processes , parent process.
when seek using multiprocessing.manager() lists, dictionary, lock, queue, etc, has permission denied errors on process has lowered permissions.
is there way grant access user or pid prepare this?
basic code represents i'm running (run root):
#!/usr/bin/env python import multiprocessing, os manager = multiprocessing.manager() problematic_list = manager.list() os.setuid(43121) # or whatever user problematic_list.append('anything')
result:
root@liberator:/home/bscable# python asd.py traceback (most recent phone call last): file "asd.py", line 8, in <module> problematic_list.append('anything') file "<string>", line 2, in append file "/usr/lib/python2.7/multiprocessing/managers.py", line 755, in _callmethod self._connect() file "/usr/lib/python2.7/multiprocessing/managers.py", line 742, in _connect conn = self._client(self._token.address, authkey=self._authkey) file "/usr/lib/python2.7/multiprocessing/connection.py", line 169, in client c = socketclient(address) file "/usr/lib/python2.7/multiprocessing/connection.py", line 293, in socketclient s.connect(address) file "/usr/lib/python2.7/socket.py", line 224, in meth homecoming getattr(self._sock,name)(*args) socket.error: [errno 13] permission denied traceback (most recent phone call last): file "/usr/lib/python2.7/multiprocessing/util.py", line 261, in _run_finalizers finalizer() file "/usr/lib/python2.7/multiprocessing/util.py", line 200, in __call__ res = self._callback(*self._args, **self._kwargs) file "/usr/lib/python2.7/multiprocessing/managers.py", line 625, in _finalize_manager process.terminate() file "/usr/lib/python2.7/multiprocessing/process.py", line 137, in terminate self._popen.terminate() file "/usr/lib/python2.7/multiprocessing/forking.py", line 165, in terminate os.kill(self.pid, signal.sigterm) oserror: [errno 1] operation not permitted
the first exception appears 1 of import here.
python (at to the lowest degree 2.6) uses unix socket communicate appears so:
/tmp/pymp-egnu6a/listener-bthj0e
we can grab path , alter permissions on so:
#!/usr/bin/env python import multiprocessing, os, grp, pwd manager = multiprocessing.manager() problematic_list = manager.list() fullname = manager._address dirname = os.path.dirname(fullname) gid = grp.getgrnam('some_group').gr_gid uid = pwd.getpwnam('root').pw_uid # should 0, never know os.chown(dirname, uid, gid) os.chmod(dirname, 0770) os.chown(fullname, uid, gid) os.chmod(fullname, 0770) os.setgid(gid) os.setuid(43121) # or whatever user problematic_list.append('anything')
python multithreading unix multiprocessing
No comments:
Post a Comment