summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 07a640a)
raw | patch | inline | side by side (parent: 07a640a)
author | Florian Forster <octo@collectd.org> | |
Thu, 21 Sep 2017 15:18:05 +0000 (17:18 +0200) | ||
committer | Florian Forster <octo@collectd.org> | |
Thu, 21 Sep 2017 15:19:49 +0000 (17:19 +0200) |
Also add a manual page entry.
Issue: #2421
Pull-Request: #2422
Issue: #2421
Pull-Request: #2422
src/collectd.pod | patch | blob | history | |
src/daemon/collectd.c | patch | blob | history |
diff --git a/src/collectd.pod b/src/collectd.pod
index 8e68fc016ac2fea5faa2bfe7d58f0d7c30c51e05..1dd899b808515d588ccc2de5e7c0544408368243 100644 (file)
--- a/src/collectd.pod
+++ b/src/collectd.pod
=item B<-P> I<E<lt>pid-fileE<gt>>
-Specify an alternative pid file. This overwrites any settings in the config
+Specify an alternative pid file. This overwrites any settings in the config
file. This is thought for init-scripts that require the PID-file in a certain
directory to work correctly. For everyday-usage use the B<PIDFile>
config-option.
+=item B<-B>
+
+If set, collectd will I<not> try to create its base directory. If the base
+directory does not exist, it will exit rather than trying to create the
+directory.
+
=item B<-f>
Don't fork to the background. I<collectd> will also B<not> close standard file
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index dfd05ce254fed6e72c04173bed3ca3bbc611da24..af8fb568bb21db3254c38bb76d1911a1cafc8a30 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
return 0;
} /* int init_global_variables */
-static int change_basedir(const char *orig_dir, int nocreate) {
+static int change_basedir(const char *orig_dir, _Bool create) {
char *dir;
size_t dirlen;
int status;
if (status == 0) {
free(dir);
return 0;
- } else if (errno != ENOENT) {
+ } else if (!create || (errno != ENOENT)) {
char errbuf[1024];
ERROR("change_basedir: chdir (%s): %s", dir,
sstrerror(errno, errbuf, sizeof(errbuf)));
return -1;
}
- if (nocreate == 0) {
- status = mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
- if (status != 0) {
- char errbuf[1024];
- ERROR("change_basedir: mkdir (%s): %s", dir,
- sstrerror(errno, errbuf, sizeof(errbuf)));
- free(dir);
- return -1;
- }
+ status = mkdir(dir, S_IRWXU | S_IRWXG | S_IRWXO);
+ if (status != 0) {
+ char errbuf[1024];
+ ERROR("change_basedir: mkdir (%s): %s", dir,
+ sstrerror(errno, errbuf, sizeof(errbuf)));
+ free(dir);
+ return -1;
}
status = chdir(dir);
int test_config = 0;
int test_readall = 0;
const char *basedir;
- int basedir_nocreate = 0;
+ _Bool opt_create_basedir = 1;
#if COLLECT_DAEMON
pid_t pid;
int daemonize = 1;
switch (c) {
case 'B':
- basedir_nocreate = 1;
+ opt_create_basedir = 0;
break;
case 'C':
configfile = optarg;
fprintf(stderr,
"Don't have a basedir to use. This should not happen. Ever.");
return 1;
- } else if (change_basedir(basedir, basedir_nocreate)) {
+ } else if (change_basedir(basedir, opt_create_basedir)) {
fprintf(stderr, "Error: Unable to change to directory `%s'.\n", basedir);
return 1;
}