Fix: sessiond: use system LTTng-UST headers when available
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index 0e97b944ca094722f4bb36f468455633e1333608..1731c368328b31fcf8712a6e02309418dc686bda 100644 (file)
@@ -27,7 +27,6 @@
 #include <sys/types.h>
 #include <unistd.h>
 #include <urcu/compiler.h>
-#include <lttng/ust-error.h>
 #include <signal.h>
 
 #include <common/common.h>
@@ -38,7 +37,8 @@
 #include "health-sessiond.h"
 #include "ust-app.h"
 #include "ust-consumer.h"
-#include "ust-ctl.h"
+#include "lttng-ust-ctl.h"
+#include "lttng-ust-error.h"
 #include "utils.h"
 #include "session.h"
 #include "lttng-sessiond.h"
@@ -1100,7 +1100,7 @@ struct ust_app_event *alloc_ust_app_event(char *name,
        /* Init most of the default value by allocating and zeroing */
        ua_event = zmalloc(sizeof(struct ust_app_event));
        if (ua_event == NULL) {
-               PERROR("malloc");
+               PERROR("Failed to allocate ust_app_event structure");
                goto error;
        }
 
@@ -3133,7 +3133,7 @@ int create_ust_app_event(struct ust_app_session *ua_sess,
 
        ua_event = alloc_ust_app_event(uevent->attr.name, &uevent->attr);
        if (ua_event == NULL) {
-               /* Only malloc can failed so something is really wrong */
+               /* Only failure mode of alloc_ust_app_event(). */
                ret = -ENOMEM;
                goto end;
        }
@@ -3142,8 +3142,19 @@ int create_ust_app_event(struct ust_app_session *ua_sess,
        /* Create it on the tracer side */
        ret = create_ust_event(app, ua_sess, ua_chan, ua_event);
        if (ret < 0) {
-               /* Not found previously means that it does not exist on the tracer */
-               assert(ret != -LTTNG_UST_ERR_EXIST);
+               /*
+                * Not found previously means that it does not exist on the
+                * tracer. If the application reports that the event existed,
+                * it means there is a bug in the sessiond or lttng-ust
+                * (or corruption, etc.)
+                */
+               if (ret == -LTTNG_UST_ERR_EXIST) {
+                       ERR("Tracer for application reported that an event being created already existed: "
+                                       "event_name = \"%s\", pid = %d, ppid = %d, uid = %d, gid = %d",
+                                       uevent->attr.name,
+                                       app->pid, app->ppid, app->uid,
+                                       app->gid);
+               }
                goto error;
        }
 
@@ -4201,7 +4212,7 @@ int ust_app_create_channel_glb(struct ltt_ust_session *usess,
                        if (session_was_created) {
                                destroy_app_session(app, ua_sess);
                        }
-                       goto error_rcu_unlock;
+                       /* Continue to the next application. */
                }
        }
 
@@ -4413,7 +4424,7 @@ int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
        health_code_update();
 
 skip_setup:
-       /* This start the UST tracing */
+       /* This starts the UST tracing */
        pthread_mutex_lock(&app->sock_lock);
        ret = ustctl_start_session(app->sock, ua_sess->handle);
        pthread_mutex_unlock(&app->sock_lock);
@@ -5885,6 +5896,7 @@ enum lttng_error_code ust_app_snapshot_record(
        enum lttng_error_code status = LTTNG_OK;
        struct lttng_ht_iter iter;
        struct ust_app *app;
+       char *trace_path = NULL;
 
        assert(usess);
        assert(output);
@@ -5899,7 +5911,6 @@ enum lttng_error_code ust_app_snapshot_record(
                cds_list_for_each_entry(reg, &usess->buffer_reg_uid_list, lnode) {
                        struct buffer_reg_channel *reg_chan;
                        struct consumer_socket *socket;
-                       char *trace_path = NULL;
                        char pathname[PATH_MAX];
 
                        if (!reg->registry->reg.ust->metadata_key) {
@@ -5928,6 +5939,8 @@ enum lttng_error_code ust_app_snapshot_record(
                                status = LTTNG_ERR_INVALID;
                                goto error;
                        }
+                       /* Free path allowed on previous iteration. */
+                       free(trace_path);
                        trace_path = setup_channel_trace_path(usess->consumer, pathname);
                        if (!trace_path) {
                                status = LTTNG_ERR_INVALID;
@@ -5942,14 +5955,12 @@ enum lttng_error_code ust_app_snapshot_record(
                                                usess->gid, trace_path, wait,
                                                nb_packets_per_stream);
                                if (status != LTTNG_OK) {
-                                       free(trace_path);
                                        goto error;
                                }
                        }
                        status = consumer_snapshot_channel(socket,
                                        reg->registry->reg.ust->metadata_key, output, 1,
                                        usess->uid, usess->gid, trace_path, wait, 0);
-                       free(trace_path);
                        if (status != LTTNG_OK) {
                                goto error;
                        }
@@ -5964,7 +5975,6 @@ enum lttng_error_code ust_app_snapshot_record(
                        struct ust_app_channel *ua_chan;
                        struct ust_app_session *ua_sess;
                        struct ust_registry_session *registry;
-                       char *trace_path = NULL;
                        char pathname[PATH_MAX];
 
                        ua_sess = lookup_session_by_app(usess, app);
@@ -5990,6 +6000,8 @@ enum lttng_error_code ust_app_snapshot_record(
                                PERROR("snprintf snapshot path");
                                goto error;
                        }
+                       /* Free path allowed on previous iteration. */
+                       free(trace_path);
                        trace_path = setup_channel_trace_path(usess->consumer, pathname);
                        if (!trace_path) {
                                status = LTTNG_ERR_INVALID;
@@ -6009,10 +6021,8 @@ enum lttng_error_code ust_app_snapshot_record(
                                case LTTNG_OK:
                                        break;
                                case LTTNG_ERR_CHAN_NOT_FOUND:
-                                       free(trace_path);
                                        continue;
                                default:
-                                       free(trace_path);
                                        goto error;
                                }
                        }
@@ -6027,7 +6037,6 @@ enum lttng_error_code ust_app_snapshot_record(
                                        ua_sess->effective_credentials.uid,
                                        ua_sess->effective_credentials.gid,
                                        trace_path, wait, 0);
-                       free(trace_path);
                        switch (status) {
                        case LTTNG_OK:
                                break;
@@ -6045,6 +6054,7 @@ enum lttng_error_code ust_app_snapshot_record(
        }
 
 error:
+       free(trace_path);
        rcu_read_unlock();
        return status;
 }
This page took 0.026114 seconds and 4 git commands to generate.