Add mode setting to socket directory creation
authorNils Carlson <nils.carlson@ericsson.com>
Tue, 29 Mar 2011 09:27:55 +0000 (11:27 +0200)
committerNils Carlson <nils.carlson@ericsson.com>
Wed, 30 Mar 2011 15:01:09 +0000 (17:01 +0200)
Set the mode when creating the personal socket directory,
this way all app sockets are private.

Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
libust/tracectl.c
libustcomm/ustcomm.c
libustcomm/ustcomm.h
libustconsumer/libustconsumer.c

index ae92b7e17577f279d30456622842037d371455ca..58b567f14265d57cea8405b9652cf49dfa66ba69 100644 (file)
@@ -1236,7 +1236,7 @@ static struct ustcomm_sock * init_app_socket(int epoll_fd)
                goto free_dir_name;
        }
 
-       result = ensure_dir_exists(dir_name);
+       result = ensure_dir_exists(dir_name, S_IRWXU);
        if (result == -1) {
                ERR("Unable to create socket directory %s, UST thread bailing",
                    dir_name);
index dce1e521c5b5c83714d439a00edf07ccb73253dc..e401c4256e6666292a3ea6b9f5dddd948d811b64 100644 (file)
@@ -588,28 +588,34 @@ free_dir_name:
        return retval;
 }
 
-int ensure_dir_exists(const char *dir)
+int ensure_dir_exists(const char *dir, mode_t mode)
 {
        struct stat st;
        int result;
 
-       if(!strcmp(dir, ""))
+       if (!strcmp(dir, ""))
                return -1;
 
        result = stat(dir, &st);
-       if(result == -1 && errno != ENOENT) {
+       if (result < 0 && errno != ENOENT) {
                return -1;
-       }
-       else if(result == -1) {
+       } else if (result < 0) {
                /* ENOENT */
                int result;
 
-               /* mkdir mode to 0777 */
-               result = mkdir_p(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+               result = mkdir_p(dir, mode);
                if(result != 0) {
                        ERR("executing in recursive creation of directory %s", dir);
                        return -1;
                }
+       } else {
+               if (st.st_mode != mode) {
+                       result = chmod(dir, mode);
+                       if (result < 0) {
+                               ERR("couldn't set directory mode on %s", dir);
+                               return -1;
+                       }
+               }
        }
 
        return 0;
index db3811961b2b8481aeed2704cb1333fd95dab0fd..d16aec79fc9aa4b79cba8f2f72383665e58bd5c3 100644 (file)
@@ -119,7 +119,7 @@ struct ustcomm_notify_buf_mapped {
 };
 
 /* Ensure directory existence, usefull for unix sockets */
-extern int ensure_dir_exists(const char *dir);
+extern int ensure_dir_exists(const char *dir, mode_t mode);
 
 /* Create and delete sockets */
 extern struct ustcomm_sock * ustcomm_init_sock(int fd, int epoll_fd,
index 8eb4424be81099d4113fe00a8d780b1e2f5edfce..eaee1fa61f358b6ec3145818ae5347994fcb6249 100644 (file)
@@ -846,7 +846,7 @@ static int init_ustconsumer_socket(struct ustconsumer_instance *instance)
                int result;
 
                /* Only check if socket dir exists if we are using the default directory */
-               result = ensure_dir_exists(SOCK_DIR);
+               result = ensure_dir_exists(SOCK_DIR, S_IRWXU | S_IRWXG | S_IRWXO);
                if (result == -1) {
                        ERR("Unable to create socket directory %s", SOCK_DIR);
                        return -1;
This page took 0.026534 seconds and 4 git commands to generate.