changeset 525:8559078a82ff

Fix race setting umask
author Matt Johnston <matt@ucc.asn.au>
date Sat, 28 Feb 2015 00:14:02 +0800
parents 0833f0aaf159
children 1f25c9d97111
files web/secure.py
diffstat 1 files changed, 1 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/web/secure.py	Thu Jan 29 22:55:24 2015 +0800
+++ b/web/secure.py	Sat Feb 28 00:14:02 2015 +0800
@@ -56,11 +56,10 @@
 def setup_csrf():
     NONCE_SIZE=16
     global _csrf_fd, _csrf_key
-    _csrf_fd = open('%s/csrf.dat' % config.DATA_PATH, 'r+')
+    _csrf_fd = os.fdopen(os.open('%s/csrf.dat' % config.DATA_PATH, os.O_RDWR | os.O_CREAT, 0600), 'r+')
 
     try:
         fcntl.lockf(_csrf_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
-        os.fchmod(_csrf_fd.fileno(), 0600)
         _csrf_fd.write("%d-%s" % (os.getpid(), binascii.hexlify(os.urandom(NONCE_SIZE))))
         _csrf_fd.flush()
         _csrf_fd.seek(0)