libust: cleanup usage of have_listener
[ust.git] / ustd / ustd.c
index fdf8d13f8d2f1fe418b1604a1b6baad3a1114fd1..a054554db07bc465a8d86cf90b1fdde366602287 100644 (file)
@@ -65,12 +65,12 @@ int test_sigpipe(void)
 
        result = sigemptyset(&sigset);
        if(result == -1) {
-               perror("sigemptyset");
+               PERROR("sigemptyset");
                return -1;
        }
        result = sigaddset(&sigset, SIGPIPE);
        if(result == -1) {
-               perror("sigaddset");
+               PERROR("sigaddset");
                return -1;
        }
 
@@ -80,7 +80,7 @@ int test_sigpipe(void)
                return 0;
        }
        else if(result == -1) {
-               perror("sigtimedwait");
+               PERROR("sigtimedwait");
                return -1;
        }
        else if(result == SIGPIPE) {
@@ -273,7 +273,7 @@ int create_dir_if_needed(char *dir)
        result = mkdir(dir, 0777);
        if(result == -1) {
                if(errno != EEXIST) {
-                       perror("mkdir");
+                       PERROR("mkdir");
                        return -1;
                }
        }
@@ -326,6 +326,23 @@ int add_buffer(pid_t pid, char *bufname)
                return -1;
        }
 
+       /* get pidunique */
+       asprintf(&send_msg, "get_pidunique");
+       result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
+       free(send_msg);
+       if(result == -1) {
+               ERR("problem in ustcomm_send_request(get_pidunique)");
+               return -1;
+       }
+
+       result = sscanf(received_msg, "%lld", &buf->pidunique);
+       if(result != 1) {
+               ERR("unable to parse response to get_pidunique");
+               return -1;
+       }
+       free(received_msg);
+       DBG("got pidunique %lld", buf->pidunique);
+
        /* get shmid */
        asprintf(&send_msg, "get_shmid %s", buf->name);
        result = ustcomm_send_request(&buf->conn, send_msg, &received_msg);
@@ -376,14 +393,14 @@ int add_buffer(pid_t pid, char *bufname)
        /* attach memory */
        buf->mem = shmat(buf->shmid, NULL, 0);
        if(buf->mem == (void *) 0) {
-               perror("shmat");
+               PERROR("shmat");
                return -1;
        }
        DBG("successfully attached buffer memory");
 
        buf->bufstruct_mem = shmat(buf->bufstruct_shmid, NULL, 0);
        if(buf->bufstruct_mem == (void *) 0) {
-               perror("shmat");
+               PERROR("shmat");
                return -1;
        }
        DBG("successfully attached buffer bufstruct memory");
@@ -391,7 +408,7 @@ int add_buffer(pid_t pid, char *bufname)
        /* obtain info on the memory segment */
        result = shmctl(buf->shmid, IPC_STAT, &shmds);
        if(result == -1) {
-               perror("shmctl");
+               PERROR("shmctl");
                return -1;
        }
        buf->memlen = shmds.shm_segsz;
@@ -411,7 +428,7 @@ int add_buffer(pid_t pid, char *bufname)
                trace_path = USTD_DEFAULT_TRACE_PATH;
        }
 
-       asprintf(&tmp, "%s/%u", trace_path, buf->pid);
+       asprintf(&tmp, "%s/%u_%lld", trace_path, buf->pid, buf->pidunique);
        result = create_dir_if_needed(tmp);
        if(result == -1) {
                ERR("could not create directory %s", tmp);
@@ -420,8 +437,8 @@ int add_buffer(pid_t pid, char *bufname)
        }
        free(tmp);
 
-       asprintf(&tmp, "%s/%u/%s_0", trace_path, buf->pid, buf->name);
-       result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600);
+       asprintf(&tmp, "%s/%u_%lld/%s_0", trace_path, buf->pid, buf->pidunique, buf->name);
+       result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 00600);
        if(result == -1) {
                PERROR("open");
                ERR("failed opening trace file %s", tmp);
@@ -511,7 +528,7 @@ int main(int argc, char **argv)
 
        result = sigemptyset(&sigset);
        if(result == -1) {
-               perror("sigemptyset");
+               PERROR("sigemptyset");
                return 1;
        }
        sa.sa_handler = sigterm_handler;
@@ -537,17 +554,17 @@ int main(int argc, char **argv)
        /* setup handler for SIGPIPE */
        result = sigemptyset(&sigset);
        if(result == -1) {
-               perror("sigemptyset");
+               PERROR("sigemptyset");
                return 1;
        }
        result = sigaddset(&sigset, SIGPIPE);
        if(result == -1) {
-               perror("sigaddset");
+               PERROR("sigaddset");
                return 1;
        }
        result = sigprocmask(SIG_BLOCK, &sigset, NULL);
        if(result == -1) {
-               perror("sigprocmask");
+               PERROR("sigprocmask");
                return 1;
        }
 
This page took 0.024451 seconds and 4 git commands to generate.