From: Julien Desfossez Date: Wed, 18 May 2011 17:58:11 +0000 (-0400) Subject: Fatal error causes kconsumerd to exit X-Git-Tag: v2.0-pre1~130 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bcd8d9db8fccd691c1e919bfa7c0d49a2fda35f9;p=lttng-tools.git Fatal error causes kconsumerd to exit In each thread, if a fatal error occurs, all threads are killed and kconsumerd exits thus preventing half working daemon. The session daemon gets notified because kconsumerd disconnects from the error socket. Signed-off-by: Julien Desfossez --- diff --git a/kconsumerd/kconsumerd.c b/kconsumerd/kconsumerd.c index a00f07932..315095ee3 100644 --- a/kconsumerd/kconsumerd.c +++ b/kconsumerd/kconsumerd.c @@ -72,6 +72,28 @@ static const char *progname; static char command_sock_path[PATH_MAX]; /* Global command socket path */ static char error_sock_path[PATH_MAX]; /* Global error path */ +/* + * del_fd + * + * Remove a fd from the global list protected by a mutex + */ +static void del_fd(struct ltt_kconsumerd_fd *lcf) +{ + pthread_mutex_lock(&kconsumerd_lock_fds); + cds_list_del(&lcf->list); + if (fds_count > 0) { + fds_count--; + DBG("Removed ltt_kconsumerd_fd"); + if (lcf != NULL) { + close(lcf->out_fd); + close(lcf->consumerd_fd); + free(lcf); + lcf = NULL; + } + } + pthread_mutex_unlock(&kconsumerd_lock_fds); +} + /* * cleanup * @@ -79,7 +101,21 @@ static char error_sock_path[PATH_MAX]; /* Global error path */ */ static void cleanup() { + struct ltt_kconsumerd_fd *iter; + + + /* remove the socket file */ unlink(command_sock_path); + + /* unblock the threads */ + WARN("Terminating the threads before exiting"); + pthread_cancel(threads[0]); + pthread_cancel(threads[1]); + + /* close all outfd */ + cds_list_for_each_entry(iter, &kconsumerd_fd_list.head, list) { + del_fd(iter); + } } /* send_error @@ -96,21 +132,6 @@ static int send_error(enum lttcomm_return_code cmd) } } -/* - * cleanup_kconsumerd_fd - * - * Close the FDs and frees a ltt_kconsumerd_fd struct - */ -static void cleanup_kconsumerd_fd(struct ltt_kconsumerd_fd *lcf) -{ - if (lcf != NULL) { - close(lcf->out_fd); - close(lcf->consumerd_fd); - free(lcf); - lcf = NULL; - } -} - /* * add_fd * @@ -152,36 +173,6 @@ end: return ret; } -/* - * del_fd - * - * Remove a fd from the global list protected by a mutex - */ -static void del_fd(struct ltt_kconsumerd_fd *lcf) -{ - pthread_mutex_lock(&kconsumerd_lock_fds); - cds_list_del(&lcf->list); - if (fds_count > 0) { - fds_count--; - DBG("Removed ltt_kconsumerd_fd"); - cleanup_kconsumerd_fd(lcf); - } - pthread_mutex_unlock(&kconsumerd_lock_fds); -} - -/* - * close_outfds - * - * Close all fds in the previous fd_list - * Must be used with kconsumerd_lock_fds lock held - */ -static void close_outfds() -{ - struct ltt_kconsumerd_fd *iter; - cds_list_for_each_entry(iter, &kconsumerd_fd_list.head, list) { - del_fd(iter); - } -} /* * sighandler @@ -190,11 +181,6 @@ static void close_outfds() */ static void sighandler(int sig) { - /* unblock the threads */ - pthread_cancel(threads[0]); - pthread_cancel(threads[1]); - - close_outfds(); cleanup(); return; @@ -529,6 +515,7 @@ static void *thread_receive_fds(void *data) /* Blocking call, waiting for transmission */ sock = lttcomm_accept_unix_sock(client_socket); if (sock <= 0) { + WARN("On accept, retrying"); continue; } @@ -536,16 +523,18 @@ static void *thread_receive_fds(void *data) ret = lttcomm_recv_unix_sock(sock, &tmp, sizeof(struct lttcomm_kconsumerd_header)); if (ret < 0) { - ERR("Receiving the lttcomm_kconsumerd_header"); - continue; + ERR("Receiving the lttcomm_kconsumerd_header, exiting"); + goto error; } ret = consumerd_recv_fd(sock, tmp.payload_size, tmp.cmd_type); if (ret < 0) { - continue; + ERR("Receiving the FD, exiting"); + goto error; } } error: + cleanup(); return NULL; } @@ -718,6 +707,7 @@ end: free(local_kconsumerd_fd); local_kconsumerd_fd = NULL; } + cleanup(); return NULL; }