Repository: benoitc/gunicorn

Issue:
Gunicorn 19.4.2 not working, downgraded to 19.4.1
On a Fedora 22 environment with virtualenvs, after upgrading Gunicorn, nginx would not serve the requested web page. 

The solution was to downgrade.

My project is called 'air' and the gunicorn logs reported that:

`ImportError: No module named 'air'`

Then, I tried to manually start gunicorn which resulted in the following error:

`AttributeError: 'os.stat_result' object has no attribute 'S_IWUSR'`

More specifically:

```
$ /home/carmen/.virtualenvs/airp/bin/gunicorn air.wsgi:application -c /home/carmen/00_server/settings/gunicorn_air.conf.py
Traceback (most recent call last):
  File "/home/carmen/.virtualenvs/airp/bin/gunicorn", line 11, in <module>
    sys.exit(run())
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/app/wsgiapp.py", line 74, in run
    WSGIApplication("%(prog)s [OPTIONS] [APP_MODULE]").run()
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/app/base.py", line 192, in run
    super(Application, self).run()
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/app/base.py", line 72, in run
    Arbiter(self).run()
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 61, in __init__
    self.setup(app)
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/arbiter.py", line 94, in setup
    self.log = self.cfg.logger_class(app.cfg)
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/glogging.py", line 178, in __init__
    self.setup(cfg)
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/glogging.py", line 187, in setup
    logging.Formatter(self.error_fmt, self.datefmt))
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/glogging.py", line 342, in _set_handler
    self.cfg.group):
  File "/home/carmen/.virtualenvs/airp/lib/python3.4/site-packages/gunicorn/util.py", line 170, in is_writable
    return st.st_mode & st.S_IWUSR != 0
AttributeError: 'os.stat_result' object has no attribute 'S_IWUSR'
```



Discussion:
can you provides more details? Is SELINUX enabled? What is your command line?

also python version

Yes Selinux is enabled. Up to now, I have arranged it so the system is working correctly. I did not have any alert while this issue was present.

The python version I am using is 3.4.

The command line is the following:

`$ /home/carmen/.virtualenvs/airp/bin/gunicorn air.wsgi:application -c /home/carmen/00_server/settings/gunicorn_air.conf.py`

I also tested it one more time:

Upgrading to 19.4.2 the issue appears. Donwgrading to 19.4.1 everything works great.


Resolving patch:
diff --git a/gunicorn/glogging.py b/gunicorn/glogging.py
--- 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
--- 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):


Test patch: