static struct pidns_init_store *pidns_hash_table[PIDNS_HASH_SIZE];
static pthread_mutex_t pidns_store_mutex = PTHREAD_MUTEX_INITIALIZER;
-static void lock_mutex(pthread_mutex_t *l)
+static void mutex_lock(pthread_mutex_t *l)
{
int ret;
struct cgroup_ops *cgroup_ops;
-static void unlock_mutex(pthread_mutex_t *l)
+static void mutex_unlock(pthread_mutex_t *l)
{
int ret;
log_exit("%s - returned %d\n", strerror(ret), ret);
}
-static inline void unlock_mutex_function(pthread_mutex_t **mutex)
+static inline void store_lock(void)
{
- if (*mutex)
- unlock_mutex(*mutex);
+ mutex_lock(&pidns_store_mutex);
}
-#define __do_unlock call_cleaner(unlock_mutex)
-static pthread_mutex_t* __attribute__((warn_unused_result)) store_lock(void)
+static inline void store_unlock(void)
{
- lock_mutex(&pidns_store_mutex);
- return &pidns_store_mutex;
+ mutex_unlock(&pidns_store_mutex);
}
/* /proc/ = 6
pid_t lookup_initpid_in_store(pid_t pid)
{
- __do_unlock pthread_mutex_t *store_mutex = NULL;
pid_t answer = 0;
char path[LXCFS_PROC_PID_NS_LEN];
struct stat st;
struct pidns_init_store *entry;
snprintf(path, sizeof(path), "/proc/%d/ns/pid", pid);
-
if (stat(path, &st))
- goto out;
+ return ret_errno(ESRCH);
- store_mutex = store_lock();
+ store_lock();
entry = lookup_verify_initpid(st.st_ino);
if (entry) {
}
/* release the mutex as the following call is expensive */
- unlock_mutex(move_ptr(store_mutex));
+ store_unlock();
+
answer = get_init_pid_for_task(pid);
- store_mutex = store_lock();
+
+ store_lock();
if (answer > 0)
save_initpid(st.st_ino, answer);
* return.
*/
prune_initpid_store();
+ store_unlock();
return answer;
}