=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
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;
}