+ struct dirent *dirent;
+ char sock_path_base[MAX_SOCK_PATH_BASE_LEN];
+ int len;
+ DIR *dir = opendir(dir_name);
+
+ snprintf(sock_path_base, MAX_SOCK_PATH_BASE_LEN - 1,
+ "%ld.", (long) pid);
+ len = strlen(sock_path_base);
+
+ while ((dirent = readdir(dir))) {
+ if (!strcmp(dirent->d_name, ".") ||
+ !strcmp(dirent->d_name, "..") ||
+ !strcmp(dirent->d_name, "ust-consumer") ||
+ dirent->d_type == DT_DIR ||
+ strncmp(dirent->d_name, sock_path_base, len)) {
+ continue;
+ }
+
+ if (ustcomm_is_socket_live(dirent->d_name, NULL)) {
+ if (snprintf(sock_name, PATH_MAX - 1, "%s/%s",
+ dir_name, dirent->d_name) < 0) {
+ PERROR("path longer than PATH_MAX?");
+ goto out_err;
+ }
+ closedir(dir);
+ return 0;
+ }
+ }
+
+out_err:
+ closedir(dir);
+ return -1;