From: Mathieu Desnoyers Date: Fri, 2 Mar 2012 17:10:32 +0000 (-0500) Subject: Fix: main.c client/apps sockets and kernel_trace_fd close(0) X-Git-Tag: v2.0.0-rc2~13 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=a4b35e07e4711a49f764c3783aae22d7f0a33d65;p=lttng-tools.git Fix: main.c client/apps sockets and kernel_trace_fd close(0) thread_registration_apps and thread_manage_clients threads are closing sock == 0 in error handling path, which is an error. They also may use kernel_tracer_fd at 0 value if no kernel tracer has been found. cleanup() can close this 0 socket too, which should never happen. Set all these sockets as "-1" when unset. Signed-off-by: Mathieu Desnoyers --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index 3cb970c06..efe2143dd 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -122,9 +122,9 @@ static char client_unix_sock_path[PATH_MAX]; static char wait_shm_path[PATH_MAX]; /* Sockets and FDs */ -static int client_sock; -static int apps_sock; -static int kernel_tracer_fd; +static int client_sock = -1; +static int apps_sock = -1; +static int kernel_tracer_fd = -1; static int kernel_poll_pipe[2]; /* @@ -419,7 +419,9 @@ static void cleanup(void) if (is_root && !opt_no_kernel) { DBG2("Closing kernel fd"); - close(kernel_tracer_fd); + if (kernel_tracer_fd >= 0) { + close(kernel_tracer_fd); + } DBG("Unloading kernel modules"); modprobe_remove_lttng_all(); } @@ -1281,7 +1283,7 @@ error: */ static void *thread_registration_apps(void *data) { - int sock = 0, i, ret, pollfd; + int sock = -1, i, ret, pollfd; uint32_t revents, nb_fd; struct lttng_poll_event events; /* @@ -1415,8 +1417,12 @@ error: /* Notify that the registration thread is gone */ notify_ust_apps(0); - close(apps_sock); - close(sock); + if (apps_sock >= 0) { + close(apps_sock); + } + if (clock >= 0) { + close(sock); + } unlink(apps_unix_sock_path); lttng_poll_clean(&events); @@ -1772,7 +1778,7 @@ error_open: error: WARN("No kernel tracer available"); - kernel_tracer_fd = 0; + kernel_tracer_fd = -1; return LTTCOMM_KERN_NA; } @@ -3249,7 +3255,7 @@ static int process_client_msg(struct command_ctx *cmd_ctx) } /* Kernel tracer check */ - if (kernel_tracer_fd == 0) { + if (kernel_tracer_fd == -1) { /* Basically, load kernel tracer modules */ ret = init_kernel_tracer(); if (ret != 0) { @@ -3589,7 +3595,7 @@ init_setup_error: */ static void *thread_manage_clients(void *data) { - int sock = 0, ret, i, pollfd; + int sock = -1, ret, i, pollfd; uint32_t revents, nb_fd; struct command_ctx *cmd_ctx = NULL; struct lttng_poll_event events; @@ -3747,8 +3753,12 @@ static void *thread_manage_clients(void *data) error: DBG("Client thread dying"); unlink(client_unix_sock_path); - close(client_sock); - close(sock); + if (sock >= 0) { + close(client_sock); + } + if (sock >= 0) { + close(sock); + } lttng_poll_clean(&events); clean_command_ctx(&cmd_ctx);