From 6439c3ba7a3d83086ba8fb63e806ecc819c6a7c9 Mon Sep 17 00:00:00 2001 From: Benoit Chesneau Date: Tue, 29 Dec 2015 15:01:23 +0100 Subject: [PATCH] don't check if a file is writable using os.stat Some systems edisable like SELINUX disable some flags so ignore the possible error while chowning a log file. The error will be raised later anyway. fix #1171 --- gunicorn/glogging.py | 8 ++++++-- gunicorn/util.py | 15 --------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py index d368b497e..2e3fd527c 100644 --- a/gunicorn/glogging.py +++ b/gunicorn/glogging.py @@ -338,9 +338,13 @@ def _set_handler(self, log, output, fmt): util.check_is_writeable(output) h = logging.FileHandler(output) # make sure the user can reopen the file - if not util.is_writable(h.baseFilename, self.cfg.user, - self.cfg.group): + try: os.chown(h.baseFilename, self.cfg.user, self.cfg.group) + except OSError: + # it's probably OK there, we assume the user has given + # /dev/null as a parameter. + pass + h.setFormatter(fmt) h._gunicorn = True log.addHandler(h) diff --git a/gunicorn/util.py b/gunicorn/util.py index 029afbfae..ac2ca769e 100644 --- a/gunicorn/util.py +++ b/gunicorn/util.py @@ -162,21 +162,6 @@ def chown(path, uid, gid): gid = abs(gid) & 0x7FFFFFFF # see note above. os.chown(path, uid, gid) -def is_writable(path, uid, gid): - gid = abs(gid) & 0x7FFFFFFF - st = os.stat(path) - - if st.st_uid == uid: - return st.st_mode & st.S_IWUSR != 0 - - user = pwd.getpwuid(uid)[0] - groups = [g.gr_gid for g in grp.getgrall() if user in g.gr_mem] - groups.append(gid) - - if st.st_gid in groups: - return st.st_mode & stat.S_IWGRP != 0 - - return st.st_mode & stat.S_IWOTH != 0 if sys.platform.startswith("win"): def _waitfor(func, pathname, waitall=False):