-/*
- * This thread manage application communication.
- */
-static void *thread_manage_apps(void *data)
-{
- int i, ret, count;
- unsigned int nb_fd = 2;
- int update_poll_flag = 1;
- struct pollfd *pollfd = NULL;
- struct ust_command ust_cmd;
-
- DBG("[thread] Manage application started");
-
- ust_cmd.sock = -1;
-
- while (1) {
- /* See if we have a valid socket to add to pollfd */
- if (ust_cmd.sock != -1) {
- nb_fd++;
- update_poll_flag = 1;
- }
-
- /* The pollfd struct must be updated */
- if (update_poll_flag) {
- ret = update_apps_cmd_pollfd(nb_fd, ARRAY_SIZE(pollfd), &pollfd);
- if (ret < 0) {
- /* malloc failed so we quit */
- goto error;
- }
-
- if (ust_cmd.sock != -1) {
- /* Update pollfd with the new UST socket */
- DBG("Adding sock %d to apps cmd pollfd", ust_cmd.sock);
- pollfd[nb_fd - 1].fd = ust_cmd.sock;
- pollfd[nb_fd - 1].events = POLLHUP | POLLNVAL | POLLERR;
- ust_cmd.sock = -1;
- }
- }
-
- DBG("Apps thread polling on %d fds", nb_fd);
-
- /* Inifinite blocking call, waiting for transmission */
- ret = poll(pollfd, nb_fd, -1);
- if (ret < 0) {
- perror("poll apps thread");
- goto error;
- }
-
- /* Thread quit pipe has been closed. Killing thread. */
- if (pollfd[0].revents == POLLNVAL) {
- goto error;
- } else {
- /* apps_cmd_pipe pipe events */
- switch (pollfd[1].revents) {
- case POLLERR:
- ERR("Apps command pipe poll error");
- goto error;
- case POLLIN:
- /* Empty pipe */
- ret = read(apps_cmd_pipe[0], &ust_cmd, sizeof(ust_cmd));
- if (ret < 0 || ret < sizeof(ust_cmd)) {
- perror("read apps cmd pipe");
- goto error;
- }
-
- /* Register applicaton to the session daemon */
- ret = register_traceable_app(&ust_cmd.reg_msg, ust_cmd.sock);
- if (ret < 0) {
- /* Only critical ENOMEM error can be returned here */
- goto error;
+ tracepoint(ust_register_done_start);
+ ret = ustctl_register_done(ust_cmd.sock);
+ if (ret < 0) {
+ /*
+ * If the registration is not possible, we simply
+ * unregister the apps and continue
+ */
+ unregister_traceable_app(ust_cmd.sock);
+ } else {
+ /*
+ * We just need here to monitor the close of the UST
+ * socket and poll set monitor those by default.
+ */
+ ret = lttng_poll_add(&events, ust_cmd.sock, 0);
+ if (ret < 0) {
+ goto error;
+ }
+
+ DBG("Apps with sock %d added to poll set",
+ ust_cmd.sock);
+ }
+ tracepoint(ust_register_done_stop);
+ break;