From: Mathieu Desnoyers Date: Thu, 14 Jul 2011 22:02:13 +0000 (-0400) Subject: kconsumerd: signals should only set flag and write into pipe (part 1) X-Git-Tag: v2.0-pre1~40 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=3dcd27214e19ba1175a7ac4057d3ce2c7b99c599 kconsumerd: signals should only set flag and write into pipe (part 1) Simplify signal reception. Left todo. Signed-off-by: Mathieu Desnoyers --- diff --git a/liblttkconsumerd/liblttkconsumerd.c b/liblttkconsumerd/liblttkconsumerd.c index c1bad734d..de942a198 100644 --- a/liblttkconsumerd/liblttkconsumerd.c +++ b/liblttkconsumerd/liblttkconsumerd.c @@ -69,6 +69,12 @@ static int kconsumerd_thread_pipe[2]; /* pipe to wake the poll thread when necessary */ static int kconsumerd_poll_pipe[2]; +/* + * TODO: create a should_quit pipe to let the signal handler wake up the + * fd receiver thread. It should be initialized before any signal can be + * received by the library. + */ + /* timeout parameter, to control the polling thread grace period */ static int kconsumerd_poll_timeout = -1; @@ -78,8 +84,13 @@ static int kconsumerd_error_socket; /* socket to exchange commands with sessiond */ static char *kconsumerd_command_sock_path; -/* flag to inform the polling thread to kconsumerd_quit when all fd hung up */ -static int kconsumerd_quit = 0; +/* + * flag to inform the polling thread to quit when all fd hung up. + * Updated by the kconsumerd_thread_receive_fds when it notices that all + * fds has hung up. Also updated by the signal handler + * (kconsumerd_should_exit()). Read by the polling threads. + */ +static volatile int kconsumerd_quit = 0; /* * kconsumerd_set_error_socket @@ -790,7 +801,6 @@ end: free(local_kconsumerd_fd); local_kconsumerd_fd = NULL; } - kconsumerd_cleanup(); return NULL; } @@ -835,6 +845,8 @@ void *kconsumerd_thread_receive_fds(void *data) goto end; } + /* TODO: poll on socket and "should_quit" fd pipe */ + /* TODO: change blocking call into non-blocking call */ /* Blocking call, waiting for transmission */ sock = lttcomm_accept_unix_sock(client_socket); if (sock <= 0) { @@ -843,6 +855,8 @@ void *kconsumerd_thread_receive_fds(void *data) } while (1) { /* We first get the number of fd we are about to receive */ + /* TODO: poll on sock and "should_quit" fd pipe */ + /* TODO: change recv into a non-blocking call */ ret = lttcomm_recv_unix_sock(sock, &tmp, sizeof(struct lttcomm_kconsumerd_header)); if (ret <= 0) { @@ -853,6 +867,10 @@ void *kconsumerd_thread_receive_fds(void *data) DBG("Received STOP command"); goto end; } + if (kconsumerd_quit) { + DBG("kconsumerd_thread_receive_fds received quit from signal"); + goto end; + } /* we received a command to add or update fds */ ret = kconsumerd_consumerd_recv_fd(sock, tmp.payload_size, tmp.cmd_type); if (ret <= 0) { @@ -890,19 +908,35 @@ end: * * Cleanup the daemon's socket on exit */ -void kconsumerd_cleanup() +void kconsumerd_cleanup(void) { struct kconsumerd_fd *iter; /* remove the socket file */ unlink(kconsumerd_command_sock_path); - /* close all outfd */ + /* + * close all outfd. Called when there are no more threads + * running (after joining on the threads), no need to protect + * list iteration with mutex. + */ cds_list_for_each_entry(iter, &kconsumerd_data.fd_list.head, list) { kconsumerd_del_fd(iter); } } +/* + * Called from signal handler. + */ +void kconsumerd_should_exit(void) +{ + kconsumerd_quit = 1; + /* + * TODO: write into a should_quit pipe to wake up the fd + * receiver thread. + */ +} + /* * kconsumerd_send_error * diff --git a/liblttkconsumerd/liblttkconsumerd.h b/liblttkconsumerd/liblttkconsumerd.h index 8dc6b6270..83c769acf 100644 --- a/liblttkconsumerd/liblttkconsumerd.h +++ b/liblttkconsumerd/liblttkconsumerd.h @@ -61,7 +61,8 @@ int kconsumerd_create_poll_pipe(); int kconsumerd_send_error(enum lttcomm_return_code cmd); void *kconsumerd_thread_poll_fds(void *data); void *kconsumerd_thread_receive_fds(void *data); -void kconsumerd_cleanup(); +void kconsumerd_should_exit(void); +void kconsumerd_cleanup(void); void kconsumerd_set_error_socket(int sock); void kconsumerd_set_command_socket_path(char *sock); diff --git a/ltt-kconsumerd/ltt-kconsumerd.c b/ltt-kconsumerd/ltt-kconsumerd.c index 60134e831..b5e854179 100644 --- a/ltt-kconsumerd/ltt-kconsumerd.c +++ b/ltt-kconsumerd/ltt-kconsumerd.c @@ -67,7 +67,7 @@ static void sighandler(int sig) return; } - kconsumerd_cleanup(); + kconsumerd_should_exit(); } /*