+/*
+ * Send the application sockets (cmd and notify) to the respective threads.
+ * This is called from the dispatch UST registration thread once all sockets
+ * are set for the application.
+ *
+ * On success, return 0 else a negative value being the errno message of the
+ * write().
+ */
+static int send_app_sockets_to_threads(struct ust_app *app)
+{
+ int ret;
+
+ assert(app);
+ /* Sockets MUST be set or else this should not have been called. */
+ assert(app->sock >= 0);
+ assert(app->notify_sock >= 0);
+ assert(apps_cmd_pipe[1] >= 0);
+ assert(apps_cmd_notify_pipe[1] >= 0);
+
+ do {
+ ret = write(apps_cmd_pipe[1], &app->sock, sizeof(app->sock));
+ } while (ret < 0 && errno == EINTR);
+ if (ret < 0 || ret != sizeof(app->sock)) {
+ PERROR("write apps cmd pipe %d", apps_cmd_pipe[1]);
+ if (ret < 0) {
+ ret = -errno;
+ }
+ goto error;
+ }
+
+ do {
+ ret = write(apps_cmd_notify_pipe[1], &app->notify_sock,
+ sizeof(app->notify_sock));
+ } while (ret < 0 && errno == EINTR);
+ if (ret < 0 || ret != sizeof(app->notify_sock)) {
+ PERROR("write apps notify cmd pipe %d", apps_cmd_notify_pipe[1]);
+ if (ret < 0) {
+ ret = -errno;
+ }
+ goto error;
+ }
+
+ /* All good. Don't send back the write positive ret value. */
+ ret = 0;
+error:
+ return ret;
+}
+