Tests: Fix rundir not created in ust-multi-test
authorChristian Babeux <christian.babeux@efficios.com>
Wed, 19 Dec 2012 19:22:27 +0000 (14:22 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 19 Dec 2012 19:22:27 +0000 (14:22 -0500)
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
tests/ust-multi-test/ust-multi-test.c

index 3f00f7edfcfd9ae3b5ffff9333c685c03f1178ef..015211c97357b97ce6dd349d84fb8457bcc62c9d 100644 (file)
@@ -693,6 +693,8 @@ static void set_ulimit(void)
 int main(int argc, char **argv)
 {
        const char *home_dir;
+       char home_rundir[PATH_MAX];
+       char *cmd = NULL;
        int ret, wait_shm_fd;
        struct sigaction act;
        mode_t old_umask = 0;
@@ -743,6 +745,21 @@ int main(int argc, char **argv)
                strcpy(apps_sock_path, DEFAULT_GLOBAL_APPS_UNIX_SOCK);
                old_umask = umask(0);
        } else {
+               home_dir = (const char *) getenv("HOME");
+               if (!home_dir) {
+                       perror("getenv error");
+                       return -ENOENT;
+               }
+
+               snprintf(home_rundir, PATH_MAX,
+                        LTTNG_HOME_RUNDIR, home_dir);
+
+               ret = mkdir(home_rundir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
+               if (ret && errno != EEXIST) {
+                       perror("mkdir");
+                       return -1;
+               }
+
                snprintf(local_apps_wait_shm_path, PATH_MAX,
                         DEFAULT_HOME_APPS_WAIT_SHM_PATH, getuid());
                wait_shm_fd = get_wait_shm(local_apps_wait_shm_path,
@@ -751,11 +768,6 @@ int main(int argc, char **argv)
                        perror("local wait shm error");
                        return -1;
                }
-               home_dir = (const char *) getenv("HOME");
-               if (!home_dir) {
-                       perror("getenv error");
-                       return -ENOENT;
-               }
                snprintf(apps_sock_path, PATH_MAX,
                         DEFAULT_HOME_APPS_UNIX_SOCK, home_dir);
        }
@@ -846,5 +858,20 @@ end:
                return -1;
        }
 
+       if (geteuid()) {
+               printf("Removing %s directory\n", home_rundir);
+               ret = asprintf(&cmd, "rm -rf %s", home_rundir);
+               if (ret < 0) {
+                       printf("asprintf failed. Something is really wrong!\n");
+                       return -1;
+               }
+
+               /* Remove lttng run directory */
+               ret = system(cmd);
+               if (ret < 0) {
+                       printf("Unable to clean %s\n", home_rundir);
+               }
+       }
+
        return 0;
 }
This page took 0.027831 seconds and 4 git commands to generate.