Module: check_mk
Branch: master
Commit: 2f3f9446930c2fa4bad1a811142fc0b37c46f99a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=2f3f9446930c2f…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 11 14:11:41 2013 +0200
Again, trying to prevent race conditions in auth.php generating hook
---
web/plugins/userdb/hook_auth.py | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/web/plugins/userdb/hook_auth.py b/web/plugins/userdb/hook_auth.py
index a1c36ec..15392c6 100644
--- a/web/plugins/userdb/hook_auth.py
+++ b/web/plugins/userdb/hook_auth.py
@@ -90,9 +90,17 @@ def create_php_file(callee, users, role_permissions,
folder_permissions):
for username in users:
users[username].setdefault('language', config.default_language)
+ # need an extra lock file, since we move the auth.php.tmp file later
+ # to auth.php. This move is needed for not having loaded incomplete
+ # files into php.
+ tempfile = g_auth_base_dir + '/auth.php.tmp'
+ lockfile = g_auth_base_dir + '/auth.php.state'
+ file(lockfile, "a")
+ aquire_lock(lockfile)
+
# First write a temp file and then do a move to prevent syntax errors
# when reading half written files during creating that new file
- file(g_auth_base_dir + '/auth.php.tmp',
'w').write('''<?php
+ file(tempfile, 'w').write('''<?php
// Created by Multisite UserDB Hook (%s)
global $mk_users, $mk_roles, $mk_folders;
$mk_users = %s;
@@ -186,7 +194,9 @@ function may($username, $need_permission) {
?>
''' % (callee, format_php(users), format_php(role_permissions),
format_php(folder_permissions)))
# Now really replace the file
- os.rename(g_auth_base_dir + '/auth.php.tmp', g_auth_base_dir +
'/auth.php');
+ os.rename(tempfile, g_auth_base_dir + '/auth.php')
+
+ release_lock(lockfile)
def create_auth_file(callee, users):
make_nagios_directory(g_auth_base_dir)