Bläddra i källkod

- Fix crash on start if AUTO logging is used with a max_bytes of
zero for a process.

Chris McDonough 18 år sedan
förälder
incheckning
e71c4ed94f

+ 3 - 0
CHANGES.txt

@@ -60,6 +60,9 @@ Next Release
   - Abandon the use of the Python stdlib 'logging' module for speed
     and cleanliness purposes.  We've rolled our own.
 
+  - Fix crash on start if AUTO logging is used with a max_bytes of
+    zero for a process.
+
 3.0a2
 
   - Fixed the README.txt example for defining the supervisor RPC

+ 5 - 2
src/supervisor/options.py

@@ -385,6 +385,7 @@ class ServerOptions(Options):
         self.add("environment", "supervisord.environment", "b:", "environment=",
                  dict_of_key_value_pairs)
         self.pidhistory = {}
+        self.parse_warnings = []
 
     def getLogger(self, filename, level, fmt, rotating=False, maxbytes=0,
                   backups=0, stdout=False):
@@ -651,7 +652,7 @@ class ServerOptions(Options):
             mb_key = '%s_maxbytes' % n
             maxbytes = byte_size(get(section, mb_key, '50MB'))
             if not maxbytes and lf_name is Automatic:
-                self.logger.warn(
+                self.parse_warnings.append(
                     'For [%s], AUTO logging used for %s without '
                     'rollover, set maxbytes > 0 to avoid filling up '
                     'filesystem unintentionally' % (section, n))
@@ -1044,7 +1045,7 @@ class ServerOptions(Options):
                     self.usage(msg % locals())
         return msgs
 
-    def make_logger(self, critical_messages, info_messages):
+    def make_logger(self, critical_messages, warn_messages, info_messages):
         # must be called after realize() and after supervisor does setuid()
         format =  '%(asctime)s %(levelname)s %(message)s\n'
         self.logger = loggers.getLogger(
@@ -1058,6 +1059,8 @@ class ServerOptions(Options):
             )
         for msg in critical_messages:
             self.logger.critical(msg)
+        for msg in warn_messages:
+            self.logger.warn(msg)
         for msg in info_messages:
             self.logger.info(msg)
 

+ 4 - 1
src/supervisor/supervisord.py

@@ -70,16 +70,19 @@ class Supervisor:
         self.options.cleanup_fds()
         info_messages = []
         critical_messages = []
+        warn_messages = []
         setuid_msg = self.options.set_uid()
         if setuid_msg:
             critical_messages.append(setuid_msg)
         if first:
             rlimit_messages = self.options.set_rlimits()
             info_messages.extend(rlimit_messages)
+            warn_messages.extend(self.options.parse_warnings)
 
         # this sets the options.logger object
         # delay logger instantiation until after setuid
-        self.options.make_logger(critical_messages, info_messages)
+        self.options.make_logger(critical_messages, warn_messages,
+                                 info_messages)
 
         if not self.options.nocleanup:
             # clean up old automatic logs

+ 3 - 2
src/supervisor/tests/base.py

@@ -62,6 +62,7 @@ class DummyOptions:
         self.existing = []
         self.openreturn = None
         self.readfd_result = ''
+        self.parse_warnings = []
 
     def getLogger(self, *args, **kw):
         logger = DummyLogger()
@@ -96,8 +97,8 @@ class DummyOptions:
     def get_socket_map(self):
         return self.socket_map
 
-    def make_logger(self, critical_msgs, info_msgs):
-        self.make_logger_messages = critical_msgs, info_msgs
+    def make_logger(self, critical_msgs, warn_msgs, info_msgs):
+        self.make_logger_messages = critical_msgs, warn_msgs, info_msgs
 
     def clear_autochildlogdir(self):
         self.autochildlogdir_cleared = True

+ 2 - 2
src/supervisor/tests/test_options.py

@@ -441,11 +441,11 @@ class ServerOptionsTests(unittest.TestCase):
         instance.logger = DummyLogger()
         config.read_string(text)
         processes = instance.processes_from_section(config, 'program:foo', None)
-        self.assertEqual(instance.logger.data[0],
+        self.assertEqual(instance.parse_warnings[0],
              'For [program:foo], AUTO logging used for stdout_logfile '
              'without rollover, set maxbytes > 0 to avoid filling up '
               'filesystem unintentionally')
-        self.assertEqual(instance.logger.data[1],
+        self.assertEqual(instance.parse_warnings[1],
              'For [program:foo], AUTO logging used for stderr_logfile '
              'without rollover, set maxbytes > 0 to avoid filling up '
               'filesystem unintentionally')

+ 1 - 1
src/supervisor/tests/test_supervisord.py

@@ -34,7 +34,7 @@ class SupervisordTests(unittest.TestCase):
         self.assertEqual(options.fds_cleaned_up, True)
         self.assertEqual(options.rlimits_set, True)
         self.assertEqual(options.make_logger_messages,
-                         (['setuid_called'], ['rlimits_set']))
+                         (['setuid_called'], [], ['rlimits_set']))
         self.assertEqual(options.autochildlogdir_cleared, True)
         self.assertEqual(len(supervisord.process_groups), 1)
         self.assertEqual(supervisord.process_groups['foo'].config.options,