sessiond: clarify the role of notification credentials
[lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index ba63922cb36c9041edf55814c211a6a90ec34089..c332f5c75b1df8bb698520b2d14bc67b7f7fe618 100644 (file)
@@ -1143,7 +1143,7 @@ struct ust_app_ctx *alloc_ust_app_ctx(struct lttng_ust_context_attr *uctx)
        if (uctx) {
                memcpy(&ua_ctx->ctx, uctx, sizeof(ua_ctx->ctx));
                if (uctx->ctx == LTTNG_UST_CONTEXT_APP_CONTEXT) {
-                       char *provider_name = NULL, *ctx_name = NULL;
+                       char *provider_name = NULL, *ctx_name = NULL;
 
                        provider_name = strdup(uctx->u.app_ctx.provider_name);
                        ctx_name = strdup(uctx->u.app_ctx.ctx_name);
@@ -2296,7 +2296,7 @@ end:
  */
 static
 int create_ust_app_channel_context(struct ust_app_channel *ua_chan,
-               struct lttng_ust_context_attr *uctx,
+               struct lttng_ust_context_attr *uctx,
                struct ust_app *app)
 {
        int ret = 0;
@@ -4112,11 +4112,14 @@ int ust_app_channel_create(struct ltt_ust_session *usess,
                ret = ust_app_channel_allocate(ua_sess, uchan,
                        LTTNG_UST_CHAN_PER_CPU, usess,
                        &ua_chan);
-               if (ret == 0) {
-                       ret = ust_app_channel_send(app, usess,
-                               ua_sess, ua_chan);
-               } else {
-                       goto end;
+               if (ret < 0) {
+                       goto error;
+               }
+
+               ret = ust_app_channel_send(app, usess,
+                       ua_sess, ua_chan);
+               if (ret) {
+                       goto error;
                }
 
                /* Add contexts. */
@@ -4124,10 +4127,12 @@ int ust_app_channel_create(struct ltt_ust_session *usess,
                        ret = create_ust_app_channel_context(ua_chan,
                                &uctx->ctx, app);
                        if (ret) {
-                               goto end;
+                               goto error;
                        }
                }
        }
+
+error:
        if (ret < 0) {
                switch (ret) {
                case -ENOTCONN:
@@ -4143,7 +4148,7 @@ int ust_app_channel_create(struct ltt_ust_session *usess,
                        break;
                }
        }
-end:
+
        if (ret == 0 && _ua_chan) {
                /*
                 * Only return the application's channel on success. Note
@@ -4996,7 +5001,7 @@ end:
 
 /*
  * The caller must ensure that the application is compatible and is tracked
- * by the PID tracker.
+ * by the process attribute trackers.
  */
 static
 void ust_app_synchronize(struct ltt_ust_session *usess,
@@ -5040,7 +5045,7 @@ void ust_app_synchronize(struct ltt_ust_session *usess,
                 * allocated (if necessary) and sent to the application, and
                 * all enabled contexts will be added to the channel.
                 */
-               ret = find_or_create_ust_app_channel(usess, ua_sess,
+               ret = find_or_create_ust_app_channel(usess, ua_sess,
                        app, uchan, &ua_chan);
                if (ret) {
                        /* Tracer is probably gone or ENOMEM. */
@@ -5116,11 +5121,14 @@ void ust_app_global_update(struct ltt_ust_session *usess, struct ust_app *app)
        if (!app->compatible) {
                return;
        }
-       if (trace_ust_id_tracker_lookup(LTTNG_TRACKER_VPID, usess, app->pid) &&
+       if (trace_ust_id_tracker_lookup(LTTNG_PROCESS_ATTR_VIRTUAL_PROCESS_ID,
+                           usess, app->pid) &&
                        trace_ust_id_tracker_lookup(
-                                       LTTNG_TRACKER_VUID, usess, app->uid) &&
+                                       LTTNG_PROCESS_ATTR_VIRTUAL_USER_ID,
+                                       usess, app->uid) &&
                        trace_ust_id_tracker_lookup(
-                                       LTTNG_TRACKER_VGID, usess, app->gid)) {
+                                       LTTNG_PROCESS_ATTR_VIRTUAL_GROUP_ID,
+                                       usess, app->gid)) {
                /*
                 * Synchronize the application's internal tracing configuration
                 * and start tracing.
@@ -5889,7 +5897,7 @@ enum lttng_error_code ust_app_snapshot_record(
                                status = LTTNG_ERR_INVALID;
                                goto error;
                        }
-                        /* Add the UST default trace dir to path. */
+                       /* Add the UST default trace dir to path. */
                        cds_lfht_for_each_entry(reg->registry->channels->ht, &iter.iter,
                                        reg_chan, node.node) {
                                status = consumer_snapshot_channel(socket,
@@ -5953,7 +5961,7 @@ enum lttng_error_code ust_app_snapshot_record(
                                status = LTTNG_ERR_INVALID;
                                goto error;
                        }
-                        cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter,
+                       cds_lfht_for_each_entry(ua_sess->channels->ht, &chan_iter.iter,
                                        ua_chan, node.node) {
                                status = consumer_snapshot_channel(socket,
                                                ua_chan->key, output, 0,
@@ -6636,3 +6644,126 @@ end:
        rcu_read_unlock();
        return cmd_ret;
 }
+
+/*
+ * This function skips the metadata channel as the begin/end timestamps of a
+ * metadata packet are useless.
+ *
+ * Moreover, opening a packet after a "clear" will cause problems for live
+ * sessions as it will introduce padding that was not part of the first trace
+ * chunk. The relay daemon expects the content of the metadata stream of
+ * successive metadata trace chunks to be strict supersets of one another.
+ *
+ * For example, flushing a packet at the beginning of the metadata stream of
+ * a trace chunk resulting from a "clear" session command will cause the
+ * size of the metadata stream of the new trace chunk to not match the size of
+ * the metadata stream of the original chunk. This will confuse the relay
+ * daemon as the same "offset" in a metadata stream will no longer point
+ * to the same content.
+ */
+enum lttng_error_code ust_app_open_packets(struct ltt_session *session)
+{
+       enum lttng_error_code ret = LTTNG_OK;
+       struct lttng_ht_iter iter;
+       struct ltt_ust_session *usess = session->ust_session;
+
+       assert(usess);
+
+       rcu_read_lock();
+
+       switch (usess->buffer_type) {
+       case LTTNG_BUFFER_PER_UID:
+       {
+               struct buffer_reg_uid *reg;
+
+               cds_list_for_each_entry (
+                               reg, &usess->buffer_reg_uid_list, lnode) {
+                       struct buffer_reg_channel *reg_chan;
+                       struct consumer_socket *socket;
+
+                       socket = consumer_find_socket_by_bitness(
+                                       reg->bits_per_long, usess->consumer);
+                       if (!socket) {
+                               ret = LTTNG_ERR_FATAL;
+                               goto error;
+                       }
+
+                       cds_lfht_for_each_entry(reg->registry->channels->ht,
+                                       &iter.iter, reg_chan, node.node) {
+                               const int open_ret =
+                                               consumer_open_channel_packets(
+                                                       socket,
+                                                       reg_chan->consumer_key);
+
+                               if (open_ret < 0) {
+                                       ret = LTTNG_ERR_UNK;
+                                       goto error;
+                               }
+                       }
+               }
+               break;
+       }
+       case LTTNG_BUFFER_PER_PID:
+       {
+               struct ust_app *app;
+
+               cds_lfht_for_each_entry (
+                               ust_app_ht->ht, &iter.iter, app, pid_n.node) {
+                       struct consumer_socket *socket;
+                       struct lttng_ht_iter chan_iter;
+                       struct ust_app_channel *ua_chan;
+                       struct ust_app_session *ua_sess;
+                       struct ust_registry_session *registry;
+
+                       ua_sess = lookup_session_by_app(usess, app);
+                       if (!ua_sess) {
+                               /* Session not associated with this app. */
+                               continue;
+                       }
+
+                       /* Get the right consumer socket for the application. */
+                       socket = consumer_find_socket_by_bitness(
+                                       app->bits_per_long, usess->consumer);
+                       if (!socket) {
+                               ret = LTTNG_ERR_FATAL;
+                               goto error;
+                       }
+
+                       registry = get_session_registry(ua_sess);
+                       if (!registry) {
+                               DBG("Application session is being torn down. Skip application.");
+                               continue;
+                       }
+
+                       cds_lfht_for_each_entry(ua_sess->channels->ht,
+                                       &chan_iter.iter, ua_chan, node.node) {
+                               const int open_ret =
+                                               consumer_open_channel_packets(
+                                                       socket,
+                                                       ua_chan->key);
+
+                               if (open_ret < 0) {
+                                       /*
+                                        * Per-PID buffer and application going
+                                        * away.
+                                        */
+                                       if (open_ret == -LTTNG_ERR_CHAN_NOT_FOUND) {
+                                               continue;
+                                       }
+
+                                       ret = LTTNG_ERR_UNK;
+                                       goto error;
+                               }
+                       }
+               }
+               break;
+       }
+       default:
+               abort();
+               break;
+       }
+
+error:
+       rcu_read_unlock();
+       return ret;
+}
This page took 0.026256 seconds and 4 git commands to generate.