+ return retval;
+}
+
+/*
+ * To be used on setups where gdb has issues debugging programs using
+ * clone/rfork. Note that this is for debuging ONLY, and should not be
+ * considered secure.
+ */
+static
+int run_as_noclone(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
+{
+ int ret;
+ mode_t old_mask;
+
+ old_mask = umask(0);
+ ret = cmd(data);
+ umask(old_mask);
+
+ return ret;
+}
+
+static
+int run_as(int (*cmd)(void *data), void *data, uid_t uid, gid_t gid)
+{
+ if (!getenv("LTTNG_DEBUG_NOCLONE")) {
+ int ret;
+
+ DBG("Using run_as_clone");
+ pthread_mutex_lock(<tng_libc_state_lock);
+ ret = run_as_clone(cmd, data, uid, gid);
+ pthread_mutex_unlock(<tng_libc_state_lock);
+ return ret;
+ } else {
+ DBG("Using run_as_noclone");
+ return run_as_noclone(cmd, data, uid, gid);
+ }