X-Git-Url: https://git.liburcu.org/?a=blobdiff_plain;f=src%2Fbin%2Flttng-consumerd%2Flttng-consumerd.c;h=293654053e87ad046d4cc2716de75e1934b513f8;hb=19154d2ab25daef13e23586d1c5201b6baaf8148;hp=7122d065e649aa41533d4319af9d88010d4b4890;hpb=25b397f9ccee70eb6f2968837702c50f22ad7bbf;p=lttng-tools.git diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index 7122d065e..293654053 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -16,7 +16,6 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -38,15 +37,15 @@ #include #include #include -#include #include #include #include #include -#include -#include +#include +#include #include +#include #include #include @@ -100,15 +99,9 @@ static void sighandler(int sig) return; } - /* - * Ignore SIGPIPE because it should not stop the consumer whenever a - * SIGPIPE is catched through a FD operation. - */ - if (sig == SIGPIPE) { - return; + if (ctx) { + lttng_consumer_should_exit(ctx); } - - lttng_consumer_should_exit(ctx); } /* @@ -126,9 +119,10 @@ static int set_signal_handler(void) return ret; } - sa.sa_handler = sighandler; sa.sa_mask = sigset; sa.sa_flags = 0; + + sa.sa_handler = sighandler; if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { PERROR("sigaction"); return ret; @@ -139,6 +133,7 @@ static int set_signal_handler(void) return ret; } + sa.sa_handler = SIG_IGN; if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) { PERROR("sigaction"); return ret; @@ -223,16 +218,31 @@ static int parse_args(int argc, char **argv) } break; case 'c': - snprintf(command_sock_path, PATH_MAX, "%s", optarg); + if (lttng_is_setuid_setgid()) { + WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", + "-c, --consumerd-cmd-sock"); + } else { + snprintf(command_sock_path, PATH_MAX, "%s", optarg); + } break; case 'e': - snprintf(error_sock_path, PATH_MAX, "%s", optarg); + if (lttng_is_setuid_setgid()) { + WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", + "-e, --consumerd-err-sock"); + } else { + snprintf(error_sock_path, PATH_MAX, "%s", optarg); + } break; case 'd': opt_daemon = 1; break; case 'g': - tracing_group_name = optarg; + if (lttng_is_setuid_setgid()) { + WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", + "-g, --group"); + } else { + tracing_group_name = optarg; + } break; case 'h': usage(stdout); @@ -296,6 +306,7 @@ int main(int argc, char **argv) { int ret = 0, retval = 0; void *status; + struct lttng_consumer_local_data *tmp_ctx; if (set_signal_handler()) { retval = -1; @@ -403,6 +414,10 @@ int main(int argc, char **argv) set_ulimit(); } + if (run_as_create_worker(argv[0]) < 0) { + goto exit_init_data; + } + /* create the consumer instance with and assign the callbacks */ ctx = lttng_consumer_create(opt_type, lttng_consumer_read_subbuffer, NULL, lttng_consumer_on_recv_stream, NULL); @@ -610,17 +625,30 @@ exit_health_thread: exit_health_pipe: exit_init_data: - lttng_consumer_destroy(ctx); + tmp_ctx = ctx; + ctx = NULL; + cmm_barrier(); /* Clear ctx for signal handler. */ + /* + * Wait for all pending call_rcu work to complete before tearing + * down data structures. call_rcu worker may be trying to + * perform lookups in those structures. + */ + rcu_barrier(); + lttng_consumer_destroy(tmp_ctx); lttng_consumer_cleanup(); if (health_consumerd) { health_app_destroy(health_consumerd); } -exit_health_consumerd_cleanup: + /* Ensure all prior call_rcu are done. */ + rcu_barrier(); -exit_options: + run_as_destroy_worker(); +exit_health_consumerd_cleanup: +exit_options: exit_set_signal_handler: + if (!retval) { exit(EXIT_SUCCESS); } else {