From 20f5c4bf1eb7297a6358c044d98bcd078a2c4c8b Mon Sep 17 00:00:00 2001 From: Eric Atkin Date: Sat, 10 Mar 2018 14:07:16 -0700 Subject: [PATCH 1/2] chmod temp files using umask from ServerOptions --- supervisor/options.py | 1 + supervisor/tests/test_options.py | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/supervisor/options.py b/supervisor/options.py index aa0c8a5c4..4f226c1fd 100644 --- a/supervisor/options.py +++ b/supervisor/options.py @@ -1495,6 +1495,7 @@ def mktempfile(self, suffix, prefix, dir): os._urandomfd = None fd, filename = tempfile.mkstemp(suffix, prefix, dir) os.close(fd) + os.chmod(filename, 0o666 ^ self.configroot.supervisord.umask) return filename def remove(self, path): diff --git a/supervisor/tests/test_options.py b/supervisor/tests/test_options.py index c9f3192a1..1462f38ab 100644 --- a/supervisor/tests/test_options.py +++ b/supervisor/tests/test_options.py @@ -429,6 +429,22 @@ def test_version(self): self.assertRaises(SystemExit, options.version, None) self.assertEqual(options.stdout.getvalue(), VERSION + '\n') + def test_mktempfile(self): + text = lstrip(""" + [supervisord] + identifier=foo ;comment should not be in identifier + """) + instance = self._makeOne() + instance.configfile = StringIO(text) + instance.realize(args=[]) + options = instance.configroot.supervisord + filename = instance.mktempfile(None, None, None) + try: + mode = os.stat(filename).st_mode & 0o777 + self.assertEqual(oct(mode), oct(0o666 ^ options.umask)) + finally: + os.remove(filename) + def test_options(self): s = lstrip("""[inet_http_server] port=127.0.0.1:8999 @@ -2908,10 +2924,11 @@ def test_clear_autochildlogdir(self): dn = tempfile.mkdtemp() try: instance = self._makeOne() + instance.configroot.supervisord.umask = 0o022 instance.childlogdir = dn sid = 'supervisor' instance.identifier = sid - logfn = instance.get_autochildlog_name('foo', sid,'stdout') + logfn = instance.get_autochildlog_name('foo', sid, 'stdout') first = logfn + '.1' second = logfn + '.2' f1 = open(first, 'w') From 7ba85cfe7272e0c88a24a83741fca34d4dc212c6 Mon Sep 17 00:00:00 2001 From: Eric Atkin Date: Sat, 10 Mar 2018 14:15:53 -0700 Subject: [PATCH 2/2] Make test work with python<3.5 --- supervisor/tests/test_options.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/supervisor/tests/test_options.py b/supervisor/tests/test_options.py index 1462f38ab..84813da37 100644 --- a/supervisor/tests/test_options.py +++ b/supervisor/tests/test_options.py @@ -438,7 +438,7 @@ def test_mktempfile(self): instance.configfile = StringIO(text) instance.realize(args=[]) options = instance.configroot.supervisord - filename = instance.mktempfile(None, None, None) + filename = instance.mktempfile('', 'tmp', None) try: mode = os.stat(filename).st_mode & 0o777 self.assertEqual(oct(mode), oct(0o666 ^ options.umask))