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
63 63
 * nesting into this lock.
64 64
 */
65 65
static pthread_mutex_t ust_safe_guard_fd_mutex = PTHREAD_MUTEX_INITIALIZER;
66

  
67
/*
68
 * Cancel state when grabbing the ust_safe_guard_fd_mutex. Saved when
69
 * locking, restored on unlock. Protected by ust_safe_guard_fd_mutex.
70
 */
71
static int ust_safe_guard_saved_cancelstate;
72

  
66 73
/*
67 74
 * Track whether we are within lttng-ust or application, for close
68 75
 * system call override by LD_PRELOAD library.
......
124 131

  
125 132
void lttng_ust_lock_fd_tracker(void)
126 133
{
134
	int ret, oldstate;
135

  
136
	ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &oldstate);
137
	if (ret) {
138
		ERR("pthread_setcancelstate: %s", strerror(ret));
139
	}
127 140
	URCU_TLS(thread_fd_tracking) = 1;
128 141
	/*
129 142
	 * Ensure the compiler don't move the store after the close()
......
131 144
	 */
132 145
	cmm_barrier();
133 146
	pthread_mutex_lock(&ust_safe_guard_fd_mutex);
147
	ust_safe_guard_saved_cancelstate = oldstate;
134 148
}
135 149

  
136 150
void lttng_ust_unlock_fd_tracker(void)
137 151
{
152
	int ret, newstate, oldstate;
153

  
154
	newstate = ust_safe_guard_saved_cancelstate;
138 155
	pthread_mutex_unlock(&ust_safe_guard_fd_mutex);
139 156
	/*
140 157
	 * Ensure the compiler don't move the store before the close()
......
142 159
	 */
143 160
	cmm_barrier();
144 161
	URCU_TLS(thread_fd_tracking) = 0;
162
	ret = pthread_setcancelstate(newstate, &oldstate);
163
	if (ret) {
164
		ERR("pthread_setcancelstate: %s", strerror(ret));
165
	}
145 166
}
146 167

  
147 168
static int dup_std_fd(int fd)
(2-2/2)