ustd: be more intelligent and verbose when opening traces for output
authorPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 30 Jul 2009 19:34:41 +0000 (15:34 -0400)
committerPierre-Marc Fournier <pierre-marc.fournier@polymtl.ca>
Thu, 30 Jul 2009 19:34:41 +0000 (15:34 -0400)
- report errors
- create dirs if not present

ustd/ustd.c
ustd/ustd.h

index b3af3c47efd3700fcb026247577ce8741782e3eb..5b45b6c812b94263d92ce81b8f4a8a06a81b70f3 100644 (file)
@@ -245,6 +245,20 @@ void *consumer_thread(void *arg)
        return NULL;
 }
 
+int create_dir_if_needed(char *dir)
+{
+       int result;
+       result = mkdir(dir, 0777);
+       if(result == -1) {
+               if(errno != EEXIST) {
+                       perror("mkdir");
+                       return -1;
+               }
+       }
+
+       return 0;
+}
+
 int add_buffer(pid_t pid, char *bufname)
 {
        struct buffer_info *buf;
@@ -343,7 +357,22 @@ int add_buffer(pid_t pid, char *bufname)
        buf->memlen = shmds.shm_segsz;
 
        /* open file for output */
-       asprintf(&tmp, "/tmp/trace/%s_0", buf->name);
+       result = create_dir_if_needed(USTD_DEFAULT_TRACE_PATH);
+       if(result == -1) {
+               ERR("could not create directory %s", USTD_DEFAULT_TRACE_PATH);
+               return -1;
+       }
+
+       asprintf(&tmp, "%s/%u", USTD_DEFAULT_TRACE_PATH, buf->pid);
+       result = create_dir_if_needed(tmp);
+       if(result == -1) {
+               ERR("could not create directory %s", tmp);
+               free(tmp);
+               return -1;
+       }
+       free(tmp);
+
+       asprintf(&tmp, "%s/%u/%s_0", USTD_DEFAULT_TRACE_PATH, buf->pid, buf->name);
        result = fd = open(tmp, O_WRONLY | O_CREAT | O_TRUNC, 00600);
        if(result == -1) {
                PERROR("open");
index 0eb33570e7e4c88b6fcd4d4a98fc160853146d0f..0b2db775e1c766fae68dd7c8f37c958bc619d6e7 100644 (file)
@@ -3,6 +3,8 @@
 
 #include "ustcomm.h"
 
+#define USTD_DEFAULT_TRACE_PATH "/tmp/usttrace"
+
 struct buffer_info {
        char *name;
        pid_t pid;
This page took 0.0342 seconds and 4 git commands to generate.