struct parm {
int id;
int ready;
+ pthread_cond_t cond;
};
+pthread_mutex_t cond_mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_t msg_mutex = PTHREAD_MUTEX_INITIALIZER;
static void *syscall_setreuid(void *arg)
syscall_setreuid(arg);
+ pthread_mutex_lock(&cond_mutex);
p->ready = 1;
+ pthread_cond_signal(&p->cond);
+ pthread_mutex_unlock(&cond_mutex);
pthread_mutex_lock(&msg_mutex);
struct parm *p;
int rc;
int i;
+ struct timespec ts;
(void) state; /* unused */
for (i = 0; i < NUM_THREADS; i++) {
p[i].id = i;
p[i].ready = 0;
+ p[i].cond = (pthread_cond_t)PTHREAD_COND_INITIALIZER;
pthread_create(&threads[i],
&pthread_custom_attr,
}
/* wait for the threads to set euid to 0 */
+
+ pthread_mutex_lock(&cond_mutex);
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += NUM_THREADS;
for (i = 0; i < NUM_THREADS; i++) {
while (p[i].ready != 1) {
- sleep(1);
+ rc = pthread_cond_timedwait(&p[i].cond, &cond_mutex, &ts);
+ assert_int_equal(rc, 0);
}
}
+ pthread_mutex_unlock(&cond_mutex);
rc = setreuid(-1, 42);
assert_int_equal(rc, 0);