+/* pid: the pid of the trace process that must receive the msg
+ msg: pointer to a null-terminated message to send
+ reply: location where to put the null-terminated string of the reply;
+ it must be free'd after usage
+ */
+
+int send_message(pid_t pid, const char *msg, char **reply)
+{
+ int result;
+ char path[UNIX_PATH_MAX];
+
+ result = snprintf(path, UNIX_PATH_MAX, "%s/%d", SOCK_DIR, pid);
+ if(result >= UNIX_PATH_MAX) {
+ fprintf(stderr, "string overflow allocating socket name");
+ return -1;
+ }
+
+ send_message_path(path, msg, reply, pid);
+
+ return 0;
+}
+
+/* Called by an app to ask the consumer daemon to connect to it. */
+
+int ustcomm_request_consumer(pid_t pid, const char *channel)
+{
+ char path[UNIX_PATH_MAX];
+ int result;
+ char *msg;
+
+ result = snprintf(path, UNIX_PATH_MAX, "%s/ustd", SOCK_DIR);
+ if(result >= UNIX_PATH_MAX) {
+ fprintf(stderr, "string overflow allocating socket name");
+ return -1;
+ }
+
+ asprintf(&msg, "collect %d %s", pid, channel);
+
+ send_message_path(path, msg, NULL, pid);
+ free(msg);
+
+ return 0;
+}
+
+static int recv_message_fd(int fd, char **msg)