X-Git-Url: http://git.lttng.org/?p=ust.git;a=blobdiff_plain;f=libustcomm%2Fustcomm.c;fp=libustcomm%2Fustcomm.c;h=e401c4256e6666292a3ea6b9f5dddd948d811b64;hp=dce1e521c5b5c83714d439a00edf07ccb73253dc;hb=304f67a5f2d2eaaa7407c09b2ac7d6e049bccf1f;hpb=dbd75de7b2c05c98d6171bc531a1ecb23fb7e80d diff --git a/libustcomm/ustcomm.c b/libustcomm/ustcomm.c index dce1e52..e401c42 100644 --- a/libustcomm/ustcomm.c +++ b/libustcomm/ustcomm.c @@ -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;