X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbin%2Flttng-consumerd%2Flttng-consumerd.c;h=d0d83988c7beceb6d3196d523260b55feb0a30a9;hb=5acdb082c9b7d75df2e4bfa18f4e9dd3f119ee39;hp=2b5528d64cc4385866761e8df7cdef5f3a5dba8d;hpb=e98ec5475c67dd270e7a703011d720ff14ec4ed2;p=lttng-tools.git diff --git a/src/bin/lttng-consumerd/lttng-consumerd.c b/src/bin/lttng-consumerd/lttng-consumerd.c index 2b5528d64..d0d83988c 100644 --- a/src/bin/lttng-consumerd/lttng-consumerd.c +++ b/src/bin/lttng-consumerd/lttng-consumerd.c @@ -17,6 +17,7 @@ */ #define _GNU_SOURCE +#define _LGPL_SOURCE #include #include #include @@ -52,8 +53,6 @@ #include "lttng-consumerd.h" #include "health-consumerd.h" -/* TODO : support UST (all direct kernel-ctl accesses). */ - /* threads (channel handling, poll, metadata, sessiond) */ static pthread_t channel_thread, data_thread, metadata_thread, @@ -65,6 +64,8 @@ static int sigintcount = 0; /* Argument variables */ int lttng_opt_quiet; /* not static in error.h */ int lttng_opt_verbose; /* not static in error.h */ +int lttng_opt_mi; /* not static in error.h */ + static int opt_daemon; static const char *progname; static char command_sock_path[PATH_MAX]; /* Global command socket path */ @@ -79,6 +80,8 @@ struct health_app *health_consumerd; const char *tracing_group_name = DEFAULT_TRACING_GROUP; +int lttng_consumer_ready = NR_LTTNG_CONSUMER_READY; + enum lttng_consumer_type lttng_consumer_get_type(void) { if (!ctx) { @@ -119,7 +122,7 @@ static int set_signal_handler(void) sigset_t sigset; if ((ret = sigemptyset(&sigset)) < 0) { - perror("sigemptyset"); + PERROR("sigemptyset"); return ret; } @@ -127,17 +130,17 @@ static int set_signal_handler(void) sa.sa_mask = sigset; sa.sa_flags = 0; if ((ret = sigaction(SIGTERM, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } if ((ret = sigaction(SIGINT, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } if ((ret = sigaction(SIGPIPE, &sa, NULL)) < 0) { - perror("sigaction"); + PERROR("sigaction"); return ret; } @@ -181,9 +184,9 @@ static void usage(FILE *fp) /* * daemon argument parsing */ -static void parse_args(int argc, char **argv) +static int parse_args(int argc, char **argv) { - int c; + int c, ret = 0; static struct option long_options[] = { { "consumerd-cmd-sock", 1, 0, 'c' }, @@ -203,16 +206,20 @@ static void parse_args(int argc, char **argv) while (1) { int option_index = 0; - c = getopt_long(argc, argv, "dhqvVku" "c:e:g:", long_options, &option_index); + c = getopt_long(argc, argv, "dhqvVku" "c:e:g:", + long_options, &option_index); if (c == -1) { break; } switch (c) { case 0: - fprintf(stderr, "option %s", long_options[option_index].name); + fprintf(stderr, "option %s", + long_options[option_index].name); if (optarg) { fprintf(stderr, " with arg %s\n", optarg); + ret = -1; + goto end; } break; case 'c': @@ -255,9 +262,12 @@ static void parse_args(int argc, char **argv) #endif default: usage(stderr); - exit(EXIT_FAILURE); + ret = -1; + goto end; } } +end: + return ret; } /* @@ -339,7 +349,10 @@ int main(int argc, char **argv) } /* Init */ - lttng_consumer_init(); + if (lttng_consumer_init() < 0) { + goto error; + } + /* Init socket timeouts */ lttcomm_init(); lttcomm_inet_init(); @@ -403,9 +416,6 @@ int main(int argc, char **argv) ctx->type = opt_type; - /* Initialize communication library */ - lttcomm_init(); - ret = utils_create_pipe(health_quit_pipe); if (ret < 0) { goto error_health_pipe; @@ -419,6 +429,15 @@ int main(int argc, char **argv) goto health_error; } + /* + * Wait for health thread to be initialized before letting the + * sessiond thread reply to the sessiond that we are ready. + */ + while (uatomic_read(<tng_consumer_ready)) { + usleep(100000); + } + cmm_smp_mb(); /* Read ready before following operations */ + /* Create thread to manage channels */ ret = pthread_create(&channel_thread, NULL, consumer_thread_channel_poll, (void *) ctx); @@ -509,15 +528,11 @@ health_error: error_health_pipe: if (!ret) { ret = EXIT_SUCCESS; - lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_EXIT_SUCCESS); goto end; } error: ret = EXIT_FAILURE; - if (ctx) { - lttng_consumer_send_error(ctx, LTTCOMM_CONSUMERD_EXIT_FAILURE); - } end: lttng_consumer_destroy(ctx);