Calling set_thread_credentials() with the same values,
skips syscalls the 2nd time.
We only do this if '__thread' is supported to provide
thread local storage.
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
Autobuild-User(master): Ralph Böhme <slow@samba.org>
Autobuild-Date(master): Tue Jul 24 20:35:17 CEST 2018 on sn-devel-144
* we know we have setresuid/setresgid
* available.
*/
+#ifdef HAVE___THREAD
+ static struct {
+ bool active;
+ uid_t uid;
+ gid_t gid;
+ size_t setlen;
+ uintptr_t gidset;
+ } __thread cache;
+
+ if (cache.active &&
+ cache.uid == uid &&
+ cache.gid == gid &&
+ cache.setlen == setlen &&
+ (const gid_t *)cache.gidset == gidset)
+ {
+ return 0;
+ }
+#endif /* HAVE___THREAD */
/* Become root. */
/* Set ru=0, eu=0 */
smb_panic("set_thread_credentials failed\n");
return -1;
}
+
+#ifdef HAVE___THREAD
+ cache.active = true;
+ cache.uid = uid;
+ cache.gid = gid;
+ cache.setlen = setlen;
+ cache.gidset = (uintptr_t)gidset;
+#endif /* HAVE___THREAD */
+
return 0;
#else
errno = ENOSYS;