+ kchan = trace_kernel_get_channel_by_name(attr->name,
+ session->kernel_session);
+ if (kchan == NULL) {
+ ret = channel_kernel_create(session->kernel_session,
+ attr, kernel_poll_pipe[1]);
+ } else {
+ ret = channel_kernel_enable(session->kernel_session, kchan);
+ }
+
+ if (ret != LTTCOMM_OK) {
+ goto error;
+ }
+
+ kernel_wait_quiescent(kernel_tracer_fd);
+ break;
+ }
+ case LTTNG_DOMAIN_UST_PID:
+ {
+ struct ltt_ust_event *uevent, *new_uevent;
+ struct ltt_ust_session *usess;
+ struct ltt_ust_channel *uchan, *app_chan;
+ struct ltt_traceable_app *app;
+
+ usess = trace_ust_get_session_by_pid(&session->ust_session_list,
+ domain->attr.pid);
+ if (usess == NULL) {
+ ret = LTTCOMM_UST_CHAN_NOT_FOUND;
+ goto error;
+ }
+
+ app = traceable_app_get_by_pid(domain->attr.pid);
+ if (app == NULL) {
+ ret = LTTCOMM_APP_NOT_FOUND;
+ goto error;
+ }
+
+ uchan = trace_ust_get_channel_by_name(attr->name, usess);
+ if (uchan == NULL) {
+ ret = channel_ust_create(usess, attr, app->sock);
+ } else {
+ ret = channel_ust_enable(usess, uchan, app->sock);
+ }
+
+ if (ret != LTTCOMM_OK) {
+ goto error;
+ }
+
+ /*TODO: This should be put in an external function */
+
+ /* Copy UST channel to add to the traceable app */
+ uchan = trace_ust_get_channel_by_name(attr->name, usess);
+ if (uchan == NULL) {
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ app_chan = trace_ust_create_channel(attr, session->path);
+ if (app_chan == NULL) {
+ PERROR("malloc ltt_ust_channel");
+ ret = LTTCOMM_FATAL;
+ goto error;
+ }
+
+ memcpy(app_chan, uchan, sizeof(struct ltt_ust_channel));
+ CDS_INIT_LIST_HEAD(&app_chan->events.head);
+
+ cds_list_for_each_entry(uevent, &uchan->events.head, list) {
+ new_uevent = malloc(sizeof(struct ltt_ust_event));
+ if (new_uevent == NULL) {
+ PERROR("malloc ltt_ust_event");
+ ret = LTTCOMM_FATAL;