- goto next;
- }
-
- if (ua_sess->metadata == NULL) {
- /* Allocate UST metadata */
- ua_sess->metadata = trace_ust_create_metadata(usess->pathname);
- if (ua_sess->metadata == NULL) {
- ERR("UST app session %d creating metadata failed",
- ua_sess->handle);
- goto next;
- }
-
- uattr.overwrite = ua_sess->metadata->attr.overwrite;
- uattr.subbuf_size = ua_sess->metadata->attr.subbuf_size;
- uattr.num_subbuf = ua_sess->metadata->attr.num_subbuf;
- uattr.switch_timer_interval =
- ua_sess->metadata->attr.switch_timer_interval;
- uattr.read_timer_interval =
- ua_sess->metadata->attr.read_timer_interval;
- uattr.output = ua_sess->metadata->attr.output;
-
- /* UST tracer metadata creation */
- ret = ustctl_open_metadata(app->key.sock, ua_sess->handle, &uattr,
- &ua_sess->metadata->obj);
- if (ret < 0) {
- ERR("UST app open metadata failed for app pid:%d",
- app->key.pid);
- goto next;
- }
-
- DBG2("UST metadata opened for app pid %d", app->key.pid);
- }
-
- /* Open UST metadata stream */
- if (ua_sess->metadata->stream_obj == NULL) {
- ret = ustctl_create_stream(app->key.sock, ua_sess->metadata->obj,
- &ua_sess->metadata->stream_obj);
- if (ret < 0) {
- ERR("UST create metadata stream failed");
- goto next;
- }
-
- ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, "%s/%s-%d",
- usess->pathname, app->name, app->key.pid);
- if (ret < 0) {
- PERROR("asprintf UST create stream");
- goto next;
- }
-
- ret = mkdir(ua_sess->metadata->pathname, S_IRWXU | S_IRWXG);
- if (ret < 0) {
- goto next;
- }
-
- ret = snprintf(ua_sess->metadata->pathname, PATH_MAX, "%s/%s-%d/metadata",
- usess->pathname, app->name, app->key.pid);
- if (ret < 0) {
- PERROR("asprintf UST create stream");
- goto next;
- }
-
- DBG2("UST metadata stream object created for app pid %d",
- app->key.pid);
- }
-
- /* For each channel */
- hashtable_get_first(usess->domain_global.channels, &iter);
- while ((node = hashtable_iter_get_node(&iter)) != NULL) {
- uchan = caa_container_of(node, struct ltt_ust_channel, node);
-
- /* Lookup channel in the ust app session */
- ua_chan_node = hashtable_lookup(ua_sess->channels,
- (void *) uchan->name, strlen(uchan->name), &iter);
- if (ua_chan_node == NULL) {
- ERR("Channel suppose to be present with the above shallow "
- "session copy. Continuing...");
- goto next;
- }
-
- ua_chan = caa_container_of(ua_chan_node,
- struct ust_app_channel, node);
-
- for (;;) {
- struct lttng_ust_object_data *obj;
- struct ltt_ust_stream *ustream;
-
- ret = ustctl_create_stream(app->key.sock, ua_chan->obj,
- &obj);
- if (ret < 0) {
- /* Got all streams */
- goto next_chan;
- }
-
- ustream = malloc(sizeof(*ustream));
- if (ustream == NULL) {
- goto next_chan;
- }
- memset(ustream, 0, sizeof(struct ltt_ust_stream));
- ustream->obj = obj;
- ustream->handle = ustream->obj->handle;
- /* Order is important */
- cds_list_add_tail(&ustream->list, &ua_chan->streams.head);
- ret = snprintf(ustream->pathname, PATH_MAX, "%s/%s-%d/%s_%u",
- usess->pathname, app->name, app->key.pid,
- uchan->name, ua_chan->streams.count++);
- if (ret < 0) {
- PERROR("asprintf UST create stream");
- goto next_chan;
- }
- }
-
-next_chan:
- /* Next applications */
- hashtable_get_next(ua_sess->channels, &iter);
- }
-
- /* Setup UST consumer socket and send fds to it */
- ret = ust_consumer_send_session(usess->consumer_fd, ua_sess);
- if (ret < 0) {
- goto next;