summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRobin Hack <hack.robin@gmail.com>2015-01-23 15:15:04 +0100
committerAndreas Schneider <asn@cryptomilk.org>2015-01-28 17:17:07 +0100
commit0830d93eece7e0d132c1513c195d7735cf3421da (patch)
tree59402423dc0b87b5b22a95076f2844e028095b17 /lib
parentb21106a1a1c940151d2e56608aea35dab714b773 (diff)
downloadsamba-0830d93eece7e0d132c1513c195d7735cf3421da.tar.gz
samba-0830d93eece7e0d132c1513c195d7735cf3421da.tar.xz
samba-0830d93eece7e0d132c1513c195d7735cf3421da.zip
uwrap: Optimalization of uid_wrapper_enabled() function.
Check only bool variable inside uwrap structure instead of calling whole uid_init(). In the best case only one mutex lock is need when check. NOTES: * This patch uses __atomic_load gcc builtin function. * uid_init() were moved outside uid_wrapper_enabled() function. Signed-off-by: Robin Hack <hack.robin@gmail.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/uid_wrapper/uid_wrapper.c33
-rw-r--r--lib/uid_wrapper/wscript13
2 files changed, 42 insertions, 4 deletions
diff --git a/lib/uid_wrapper/uid_wrapper.c b/lib/uid_wrapper/uid_wrapper.c
index 578977dadc..aa3f30212a 100644
--- a/lib/uid_wrapper/uid_wrapper.c
+++ b/lib/uid_wrapper/uid_wrapper.c
@@ -639,10 +639,15 @@ static void uwrap_init(void)
bool uid_wrapper_enabled(void)
{
- uwrap_init();
-
- return uwrap.enabled ? true : false;
- UWRAP_UNLOCK(uwrap_id);
+ bool enabled = false;
+ #ifdef HAVE_GCC_ATOMIC_BUILTINS
+ __atomic_load(&uwrap.enabled, &enabled, __ATOMIC_RELAXED);
+ #else
+ UWRAP_LOCK(uwrap_id);
+ enabled = uwrap.enabled;
+ UWRAP_UNLOCK(uwrap_id);
+ #endif
+ return enabled;
}
static int uwrap_setresuid_thread(uid_t ruid, uid_t euid, uid_t suid)
@@ -712,6 +717,7 @@ int setuid(uid_t uid)
return libc_setuid(uid);
}
+ uwrap_init();
return uwrap_setresuid(uid, -1, -1);
}
@@ -727,6 +733,7 @@ int seteuid(uid_t euid)
return libc_seteuid(euid);
}
+ uwrap_init();
return uwrap_setresuid(-1, euid, -1);
}
#endif
@@ -743,6 +750,7 @@ int setreuid(uid_t ruid, uid_t euid)
return libc_setreuid(ruid, euid);
}
+ uwrap_init();
return uwrap_setresuid(ruid, euid, -1);
}
#endif
@@ -754,6 +762,7 @@ int setresuid(uid_t ruid, uid_t euid, uid_t suid)
return libc_setresuid(ruid, euid, suid);
}
+ uwrap_init();
return uwrap_setresuid(ruid, euid, suid);
}
#endif
@@ -779,6 +788,7 @@ uid_t getuid(void)
return libc_getuid();
}
+ uwrap_init();
return uwrap_getuid();
}
@@ -809,6 +819,7 @@ uid_t geteuid(void)
return libc_geteuid();
}
+ uwrap_init();
return uwrap_geteuid();
}
@@ -879,6 +890,7 @@ int setgid(gid_t gid)
return libc_setgid(gid);
}
+ uwrap_init();
return uwrap_setresgid(gid, -1, -1);
}
@@ -889,6 +901,7 @@ int setegid(gid_t egid)
return libc_setegid(egid);
}
+ uwrap_init();
return uwrap_setresgid(-1, egid, -1);
}
#endif
@@ -900,6 +913,7 @@ int setregid(gid_t rgid, gid_t egid)
return libc_setregid(rgid, egid);
}
+ uwrap_init();
return uwrap_setresgid(rgid, egid, -1);
}
#endif
@@ -911,6 +925,7 @@ int setresgid(gid_t rgid, gid_t egid, gid_t sgid)
return libc_setresgid(rgid, egid, sgid);
}
+ uwrap_init();
return uwrap_setresgid(rgid, egid, sgid);
}
#endif
@@ -936,6 +951,7 @@ gid_t getgid(void)
return libc_getgid();
}
+ uwrap_init();
return uwrap_getgid();
}
@@ -960,6 +976,7 @@ uid_t getegid(void)
return libc_getegid();
}
+ uwrap_init();
return uwrap_getegid();
}
@@ -1041,6 +1058,7 @@ int setgroups(size_t size, const gid_t *list)
return libc_setgroups(size, list);
}
+ uwrap_init();
return uwrap_setgroups(size, list);
}
@@ -1076,6 +1094,7 @@ int getgroups(int size, gid_t *list)
return libc_getgroups(size, list);
}
+ uwrap_init();
return uwrap_getgroups(size, list);
}
@@ -1242,6 +1261,7 @@ long int syscall (long int sysno, ...)
return rc;
}
+ uwrap_init();
rc = uwrap_syscall(sysno, va);
va_end(va);
@@ -1263,6 +1283,11 @@ void uwrap_constructor(void)
pthread_atfork(&uwrap_thread_prepare,
&uwrap_thread_parent,
&uwrap_thread_child);
+
+ /* Here is safe place to call uwrap_init() and initialize data
+ * for main process.
+ */
+ uwrap_init();
}
/****************************
diff --git a/lib/uid_wrapper/wscript b/lib/uid_wrapper/wscript
index bd797e5a72..49c23d2610 100644
--- a/lib/uid_wrapper/wscript
+++ b/lib/uid_wrapper/wscript
@@ -9,6 +9,19 @@ def configure(conf):
conf.DEFINE('USING_SYSTEM_UID_WRAPPER', 1)
libuid_wrapper_so_path = 'libuid_wrapper.so'
else:
+ # check HAVE_GCC_ATOMIC_BUILTINS
+ conf.CHECK_CODE('''
+ #include <stdbool.h>
+ int main(void) {
+ bool x;
+ bool *p_x = &x;
+ __atomic_load(p_x, &x, __ATOMIC_RELAXED);
+ return 0;
+ ''',
+ 'HAVE_GCC_ATOMIC_BUILTINS',
+ addmain=False,
+ msg='Checking for atomic builtins')
+
# check HAVE_GCC_THREAD_LOCAL_STORAGE
conf.CHECK_CODE('''
__thread int tls;