Project

General

Profile

Bug #1201 » fix-1201-1.diff

Mathieu Desnoyers, 10/04/2019 10:16 AM

View differences:

liblttng-ust-comm/lttng-ust-fd-tracker.c
* nesting into this lock.
*/
static pthread_mutex_t ust_safe_guard_fd_mutex = PTHREAD_MUTEX_INITIALIZER;
/*
* Cancel state when grabbing the ust_safe_guard_fd_mutex. Saved when
* locking, restored on unlock. Protected by ust_safe_guard_fd_mutex.
*/
static int ust_safe_guard_saved_cancelstate;
/*
* Track whether we are within lttng-ust or application, for close
* system call override by LD_PRELOAD library.
......
void lttng_ust_lock_fd_tracker(void)
{
int ret, oldstate;
ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
if (ret) {
ERR("pthread_setcancelstate: %s", strerror(ret));
}
URCU_TLS(thread_fd_tracking) = 1;
/*
* Ensure the compiler don't move the store after the close()
......
*/
cmm_barrier();
pthread_mutex_lock(&ust_safe_guard_fd_mutex);
ust_safe_guard_saved_cancelstate = oldstate;
}
void lttng_ust_unlock_fd_tracker(void)
{
int ret, newstate, oldstate;
newstate = ust_safe_guard_saved_cancelstate;
pthread_mutex_unlock(&ust_safe_guard_fd_mutex);
/*
* Ensure the compiler don't move the store before the close()
......
*/
cmm_barrier();
URCU_TLS(thread_fd_tracking) = 0;
ret = pthread_setcancelstate(newstate, &oldstate);
if (ret) {
ERR("pthread_setcancelstate: %s", strerror(ret));
}
}
static int dup_std_fd(int fd)
(2-2/2)