From: Florian Forster Date: Fri, 6 Apr 2012 14:18:18 +0000 (+0200) Subject: Create directories with permission 0777. X-Git-Tag: collectd-5.0.5~7^2~16 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=03fffc410e946598dbb6db2b9d9371b5f01048da;p=collectd.git Create directories with permission 0777. Let umask work its magic. Thanks to "Poil" for reporting this problem. Fixes GitHub issue #63. --- diff --git a/src/collectd.c b/src/collectd.c index 277d3b0d..b68aea5c 100644 --- a/src/collectd.c +++ b/src/collectd.c @@ -170,10 +170,11 @@ static int init_global_variables (void) static int change_basedir (const char *orig_dir) { - char *dir = strdup (orig_dir); - int dirlen; + char *dir; + size_t dirlen; int status; + dir = strdup (orig_dir); if (dir == NULL) { char errbuf[1024]; @@ -190,39 +191,41 @@ static int change_basedir (const char *orig_dir) return (-1); status = chdir (dir); - free (dir); + if (status == 0) + { + free (dir); + return (0); + } + else if (errno != ENOENT) + { + char errbuf[1024]; + ERROR ("change_basedir: chdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); + } + status = mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO); if (status != 0) { - if (errno == ENOENT) - { - if (mkdir (orig_dir, 0755) == -1) - { - char errbuf[1024]; - ERROR ("change_basedir: mkdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } - else if (chdir (orig_dir) == -1) - { - char errbuf[1024]; - ERROR ("chdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } - } - else - { - char errbuf[1024]; - ERROR ("chdir (%s): %s", orig_dir, - sstrerror (errno, errbuf, - sizeof (errbuf))); - return (-1); - } + char errbuf[1024]; + ERROR ("change_basedir: mkdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); + } + + status = chdir (dir); + if (status != 0) + { + char errbuf[1024]; + ERROR ("change_basedir: chdir (%s): %s", dir, + sstrerror (errno, errbuf, sizeof (errbuf))); + free (dir); + return (-1); } + free (dir); return (0); } /* static int change_basedir (char *dir) */ diff --git a/src/common.c b/src/common.c index c5bd6470..3bab7a59 100644 --- a/src/common.c +++ b/src/common.c @@ -547,7 +547,7 @@ int check_create_dir (const char *file_orig) { if (errno == ENOENT) { - if (mkdir (dir, 0755) == 0) + if (mkdir (dir, S_IRWXU | S_IRWXG | S_IRWXO) == 0) break; /* this might happen, if a different thread created