common BUGFIX directory creation and umask
Fixes cesnet/netopeer2#602
@@ -2461,17 +2461,21 @@ sr_error_info_t *
sr_mkpath(char *path, mode_t mode)
{
sr_error_info_t *err_info = NULL;
+ mode_t um;
char *p;
assert(path[0] == '/');
+ /* set umask so that the correct permissions are really set */
+ um = umask(00000);
+
for (p = strchr(path + 1, '/'); p; p = strchr(p + 1, '/')) {
*p = '\0';
if (mkdir(path, mode) == -1) {
if (errno != EEXIST) {
sr_errinfo_new(&err_info, SR_ERR_SYS, NULL, "Creating directory \"%s\" failed (%s).", path, strerror(errno));
*p = '/';
- return err_info;
+ goto cleanup;
}
}
*p = '/';
@@ -2480,11 +2484,13 @@ sr_mkpath(char *path, mode_t mode)
if (mkdir(path, mode) == -1) {
if (errno != EEXIST) {
sr_errinfo_new(&err_info, SR_ERR_SYS, NULL, "Creating directory \"%s\" failed (%s).", path, strerror(errno));
- return err_info;
+ goto cleanup;
}
}
- return NULL;
+cleanup:
+ umask(um);
+ return err_info;
}
char *
