X-Git-Url: http://git.lttng.org/?a=blobdiff_plain;f=liblttng-ust-comm%2Flttng-ust-fd-tracker.c;h=1118163a201af456ac6ed28d490e09f458af08ef;hb=283f4bec47781f7a39dde82d02e53add02155f9c;hp=1bc186bf08453f870001446ebf17dbb0e2ab2054;hpb=5a4d96d170a38f29bf147b84e248a47d45ee7d8e;p=lttng-ust.git diff --git a/liblttng-ust-comm/lttng-ust-fd-tracker.c b/liblttng-ust-comm/lttng-ust-fd-tracker.c index 1bc186bf..1118163a 100644 --- a/liblttng-ust-comm/lttng-ust-fd-tracker.c +++ b/liblttng-ust-comm/lttng-ust-fd-tracker.c @@ -61,8 +61,18 @@ * Protect the lttng_fd_set. Nests within the ust_lock, and therefore * within the libc dl lock. Therefore, we need to fixup the TLS before * nesting into this lock. + * + * The ust_safe_guard_fd_mutex nests within the ust_mutex. This mutex + * is also held across fork. */ 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. @@ -124,6 +134,12 @@ void lttng_ust_init_fd_tracker(void) 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() @@ -131,10 +147,14 @@ void lttng_ust_lock_fd_tracker(void) */ 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() @@ -142,6 +162,10 @@ void lttng_ust_unlock_fd_tracker(void) */ 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)