[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [ooni-probe/master] Better permissions handling for logfile and folder



commit 73b17d70ad8ac535ddebe36ca1b1d4c6277781d1
Author: Arturo Filastò <arturo@xxxxxxxxxxx>
Date:   Fri Sep 2 15:17:24 2016 +0200

    Better permissions handling for logfile and folder
---
 ooni/utils/log.py | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/ooni/utils/log.py b/ooni/utils/log.py
index 1aba8dd..67079e0 100644
--- a/ooni/utils/log.py
+++ b/ooni/utils/log.py
@@ -1,5 +1,6 @@
 import os
 import sys
+import errno
 import codecs
 import logging
 
@@ -132,6 +133,20 @@ class OONILogger(object):
             logfile = os.path.expanduser(config.basic.logfile)
 
         log_folder = os.path.dirname(logfile)
+        if not os.access(log_folder, os.W_OK):
+            # If we don't have permissions to write to the log_folder,
+            # write to running dir.
+            log_folder = config.running_path
+            logfile = os.path.join(log_folder, "ooniprobe.log")
+
+        try:
+            os.makedirs(log_folder)
+        except OSError as ose:
+            if ose.errno == errno.EEXIST and os.path.isdir(log_folder):
+                pass
+            else:
+                raise
+
         log_filename = os.path.basename(logfile)
         file_log_level = levels.get(config.basic.loglevel,
                                     levels['INFO'])



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits