summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 005b303)
raw | patch | inline | side by side (parent: 005b303)
author | Florian Forster <octo@collectd.org> | |
Fri, 6 Apr 2012 14:18:18 +0000 (16:18 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Fri, 6 Apr 2012 14:19:32 +0000 (16:19 +0200) |
Let umask work its magic. Thanks to "Poil" for reporting this problem.
Fixes GitHub issue #63.
Fixes GitHub issue #63.
src/collectd.c | patch | blob | history | |
src/common.c | patch | blob | history |
diff --git a/src/collectd.c b/src/collectd.c
index 277d3b0dc9432917db2f0483ec812742148852e3..b68aea5ca9ce894b5b7d7c13289726e3bc11a4d9 100644 (file)
--- a/src/collectd.c
+++ b/src/collectd.c
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];
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 c5bd6470aa47e80564e5145312bfc9dec89b1500..3bab7a59421466d33fbc072cc563e08c2f8248a7 100644 (file)
--- a/src/common.c
+++ b/src/common.c
{
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