Explorar o código

Change default mask

Conflicts:
	celery/platforms.py

Conflicts:
	celery/app/base.py
	celery/bin/celeryd_detach.py
Ask Solem %!s(int64=10) %!d(string=hai) anos
pai
achega
0d6c7c39d7

+ 3 - 2
celery/bin/base.py

@@ -56,7 +56,8 @@ in any command that also has a `--detach` option.
 
 .. cmdoption:: --umask
 
-    Effective umask of the process after detaching. Default is 0.
+    Effective umask (in octal) of the process after detaching.  Inherits
+    the umask of the parent process by default.
 
 .. cmdoption:: --workdir
 
@@ -388,5 +389,5 @@ def daemon_options(default_pidfile=None, default_logfile=None):
         Option('--pidfile', default=default_pidfile),
         Option('--uid', default=None),
         Option('--gid', default=None),
-        Option('--umask', default=0, type='int'),
+        Option('--umask', default=None),
     )

+ 1 - 1
celery/bin/celeryd_detach.py

@@ -36,7 +36,7 @@ OPTION_LIST = daemon_options(default_pidfile='celeryd.pid') + (
 
 
 def detach(path, argv, logfile=None, pidfile=None, uid=None,
-           gid=None, umask=0, working_directory=None, fake=False, ):
+           gid=None, umask=None, working_directory=None, fake=False):
     fake = 1 if C_FAKEFORK else fake
     with detached(logfile, pidfile, uid, gid, umask, working_directory, fake):
         try:

+ 5 - 3
celery/platforms.py

@@ -39,7 +39,6 @@ SYSTEM = _platform.system()
 IS_OSX = SYSTEM == 'Darwin'
 IS_WINDOWS = SYSTEM == 'Windows'
 
-DAEMON_UMASK = 0
 DAEMON_WORKDIR = '/'
 
 PIDFILE_FLAGS = os.O_CREAT | os.O_EXCL | os.O_WRONLY
@@ -285,8 +284,10 @@ class DaemonContext(object):
 
     def __init__(self, pidfile=None, workdir=None, umask=None,
                  fake=False, after_chdir=None, **kwargs):
+        if isinstance(umask, basestring):
+            umask = int(umask, 8)  # convert str -> octal
         self.workdir = workdir or DAEMON_WORKDIR
-        self.umask = DAEMON_UMASK if umask is None else umask
+        self.umask = umask
         self.fake = fake
         self.after_chdir = after_chdir
         self.stdfds = (sys.stdin, sys.stdout, sys.stderr)
@@ -302,7 +303,8 @@ class DaemonContext(object):
                 self._detach()
 
             os.chdir(self.workdir)
-            os.umask(self.umask)
+            if self.umask is not None:
+                os.umask(self.umask)
 
             if self.after_chdir:
                 self.after_chdir()

+ 1 - 1
celery/tests/bin/test_celery.py

@@ -151,7 +151,7 @@ class test_call(AppCase):
         iso = now.isoformat()
         a.run('tasks.add', expires=iso)
         self.assertEqual(send_task.call_args[1]['expires'], now)
-        with self.assertRaises(ValueError):
+        with self.assertRaises(TypeError):
             a.run('tasks.add', expires='foobaribazibar')
 
 

+ 3 - 3
celery/tests/bin/test_celeryd_detach.py

@@ -27,8 +27,8 @@ if not current_app.IS_WINDOWS:
 
             detach('/bin/boo', ['a', 'b', 'c'], logfile='/var/log',
                    pidfile='/var/pid')
-            detached.assert_called_with('/var/log', '/var/pid', None, None, 0,
-                                        None, False)
+            detached.assert_called_with('/var/log', '/var/pid', None, None,
+                                        None, None, False)
             execv.assert_called_with('/bin/boo', ['/bin/boo', 'a', 'b', 'c'])
 
             execv.side_effect = Exception('foo')
@@ -87,7 +87,7 @@ class test_Command(Case):
         self.assertTrue(exit.called)
         detach.assert_called_with(
             path=x.execv_path, uid=None, gid=None,
-            umask=0, fake=False, logfile='/var/log', pidfile='celeryd.pid',
+            umask=None, fake=False, logfile='/var/log', pidfile='celeryd.pid',
             argv=['-m', 'celery.bin.celeryd', '-c', '1', '-lDEBUG',
                   '--logfile=/var/log', '--pidfile=celeryd.pid',
                   '--', '.disable_rate_limits=1'],

+ 2 - 2
celery/tests/utilities/test_platforms.py

@@ -309,7 +309,7 @@ if not current_app.IS_WINDOWS:
         @patch('os.dup2')
         def test_open(self, dup2, open, close, umask,
                       chdir, _exit, setsid, fork):
-            x = DaemonContext(workdir='/opt/workdir')
+            x = DaemonContext(workdir='/opt/workdir', umask=022)
 
             fork.return_value = 0
             with x:
@@ -321,7 +321,7 @@ if not current_app.IS_WINDOWS:
             self.assertFalse(_exit.called)
 
             chdir.assert_called_with(x.workdir)
-            umask.assert_called_with(x.umask)
+            umask.assert_called_with(022)
             self.assertTrue(dup2.called)
 
             fork.reset_mock()