uti: Make tracer exit when not used

Change-Id: I3d3b2f92fa2b160ffce633c46d1b60e9079e7f1b
This commit is contained in:
Masamichi Takagi
2017-12-23 15:28:23 +09:00
parent 9102b176c4
commit 77f5cac2bf

View File

@ -1959,6 +1959,7 @@ struct uti_desc {
int pid, tid; /* Used as the id of tracee when issuing MCEXEC_UP_TERMINATE_THREAD */
unsigned long uti_clv;
sem_t arg, attach;
int exit; /* Used to tell the tracer to exit */
};
static int create_tracer();
@ -2155,6 +2156,7 @@ int main(int argc, char **argv)
if (uti_desc == (void *)-1) {
exit(1);
}
memset(uti_desc, 0, sizeof(struct uti_desc));
sem_init(&uti_desc->arg, 1, 0);
sem_init(&uti_desc->attach, 1, 0);
#if 1
@ -2689,7 +2691,6 @@ int main(int argc, char **argv)
}
join_all_threads();
fn_fail:
return ret;
}
@ -2966,6 +2967,11 @@ create_tracer()
#endif
sem_wait(&uti_desc->arg);
if (uti_desc->exit) { /* When uti is not used */
fprintf(stderr, "%s: exiting tid=%d\n", __FUNCTION__, gettid());
exit(0);
}
//close(uti_pfd[0]);
if (ptrace(PTRACE_ATTACH, uti_desc->tid, 0, 0) == -1) {
@ -3461,6 +3467,7 @@ int main_loop(struct thread_data_s *my_thread)
char pathbuf[PATH_MAX];
char tmpbuf[PATH_MAX];
int cpu = my_thread->cpu;
int sem_val;
memset(&w, '\0', sizeof w);
w.cpu = cpu;
@ -3605,6 +3612,16 @@ int main_loop(struct thread_data_s *my_thread)
kill(getpid(), sig);
pause();
}
/* Make tracer exit when it is not used */
if (sem_getvalue(&uti_desc->arg, &sem_val)) {
fprintf(stderr, "%s: ERROR: sem_getvalue returned %d\n", __FUNCTION__, errno);
}
if (sem_val == 0) {
uti_desc->exit = 1;
sem_post(&uti_desc->arg);
}
exit(term);
//pthread_mutex_unlock(lock);