Add jul-app ABI/API and handle registration
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 028f5f9d233a0933ddd9199e9171bf620065fbba..05646279a63a48b3f81bbf64d67454b9aaf53a1c 100644 (file)
@@ -63,6 +63,7 @@
 #include "health-sessiond.h"
 #include "testpoint.h"
 #include "ust-thread.h"
+#include "jul-thread.h"
 
 #define CONSUMERD_FILE "lttng-consumerd"
 
@@ -156,6 +157,7 @@ static pthread_t kernel_thread;
 static pthread_t dispatch_thread;
 static pthread_t health_thread;
 static pthread_t ht_cleanup_thread;
+static pthread_t jul_reg_thread;
 
 /*
  * UST registration command queue. This queue is tied with a futex and uses a N
@@ -233,6 +235,9 @@ long page_size;
 /* Application health monitoring */
 struct health_app *health_sessiond;
 
+/* JUL TCP port for registration. Used by the JUL thread. */
+unsigned int jul_tcp_port = DEFAULT_JUL_TCP_PORT;
+
 static
 void setup_consumerd_path(void)
 {
@@ -2410,6 +2415,7 @@ static int copy_session_consumer(int domain, struct ltt_session *session)
                consumer = session->kernel_session->consumer;
                dir_name = DEFAULT_KERNEL_TRACE_DIR;
                break;
+       case LTTNG_DOMAIN_JUL:
        case LTTNG_DOMAIN_UST:
                DBG3("Copying tracing session consumer output in UST session");
                if (session->ust_session->consumer) {
@@ -2453,6 +2459,7 @@ static int create_ust_session(struct ltt_session *session,
        assert(session->consumer);
 
        switch (domain->type) {
+       case LTTNG_DOMAIN_JUL:
        case LTTNG_DOMAIN_UST:
                break;
        default:
@@ -2745,10 +2752,6 @@ static int process_client_msg(struct command_ctx *cmd_ctx, int sock,
 
                break;
        case LTTNG_DOMAIN_JUL:
-       {
-               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
-               goto error;
-       }
        case LTTNG_DOMAIN_UST:
        {
                if (!ust_app_supported()) {
@@ -3917,6 +3920,7 @@ static void usage(void)
        fprintf(stderr, "  -p, --pidfile FILE                 Write a pid to FILE name overriding the default value.\n");
        fprintf(stderr, "      --verbose-consumer             Verbose mode for consumer. Activate DBG() macro.\n");
        fprintf(stderr, "      --no-kernel                    Disable kernel tracer\n");
+       fprintf(stderr, "      --jul-tcp-port                 JUL application registration TCP port\n");
 }
 
 /*
@@ -3949,12 +3953,13 @@ static int parse_args(int argc, char **argv)
                { "verbose-consumer", 0, 0, 'Z' },
                { "no-kernel", 0, 0, 'N' },
                { "pidfile", 1, 0, 'p' },
+               { "jul-tcp-port", 1, 0, 'J' },
                { NULL, 0, 0, 0 }
        };
 
        while (1) {
                int option_index = 0;
-               c = getopt_long(argc, argv, "dhqvVSN" "a:c:g:s:C:E:D:F:Z:u:t:p:",
+               c = getopt_long(argc, argv, "dhqvVSN" "a:c:g:s:C:E:D:F:Z:u:t:p:J:",
                                long_options, &option_index);
                if (c == -1) {
                        break;
@@ -4034,6 +4039,24 @@ static int parse_args(int argc, char **argv)
                case 'p':
                        opt_pidfile = optarg;
                        break;
+               case 'J': /* JUL TCP port. */
+               {
+                       unsigned long v;
+
+                       errno = 0;
+                       v = strtoul(optarg, NULL, 0);
+                       if (errno != 0 || !isdigit(optarg[0])) {
+                               ERR("Wrong value in --jul-tcp-port parameter: %s", optarg);
+                               return -1;
+                       }
+                       if (v == 0 || v >= 65535) {
+                               ERR("Port overflow in --jul-tcp-port parameter: %s", optarg);
+                               return -1;
+                       }
+                       jul_tcp_port = (uint32_t) v;
+                       DBG3("JUL TCP port set to non default: %u", jul_tcp_port);
+                       break;
+               }
                default:
                        /* Unknown option or other error.
                         * Error is printed by getopt, just return */
@@ -4603,6 +4626,12 @@ int main(int argc, char **argv)
         */
        ust_app_ht_alloc();
 
+       /* Initialize JUL domain subsystem. */
+       if ((ret = jul_init()) < 0) {
+               /* ENOMEM at this point. */
+               goto error;
+       }
+
        /* After this point, we can safely call cleanup() with "goto exit" */
 
        /*
@@ -4778,6 +4807,14 @@ int main(int argc, char **argv)
                goto exit_apps_notify;
        }
 
+       /* Create JUL registration thread. */
+       ret = pthread_create(&jul_reg_thread, NULL,
+                       jul_thread_manage_registration, (void *) NULL);
+       if (ret != 0) {
+               PERROR("pthread_create apps");
+               goto exit_jul_reg;
+       }
+
        /* Don't start this thread if kernel tracing is not requested nor root */
        if (is_root && !opt_no_kernel) {
                /* Create kernel thread to manage kernel event */
@@ -4796,6 +4833,13 @@ int main(int argc, char **argv)
        }
 
 exit_kernel:
+       ret = pthread_join(jul_reg_thread, &status);
+       if (ret != 0) {
+               PERROR("pthread_join JUL");
+               goto error;     /* join error, exit without cleanup */
+       }
+
+exit_jul_reg:
        ret = pthread_join(apps_notify_thread, &status);
        if (ret != 0) {
                PERROR("pthread_join apps notify");
This page took 0.025051 seconds and 4 git commands to generate.