summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ebf73b6)
raw | patch | inline | side by side (parent: ebf73b6)
author | Nathaniel Wesley Filardo <nwf@cs.jhu.edu> | |
Wed, 6 Sep 2017 17:56:40 +0000 (13:56 -0400) | ||
committer | Nathaniel Wesley Filardo <nwf@cs.jhu.edu> | |
Thu, 21 Sep 2017 06:15:30 +0000 (02:15 -0400) |
One possible implementation of collectd/collectd#2421
src/daemon/collectd.c | patch | blob | history |
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index 2edfa3774ca763067d5eefcbfa7fde6791c99b60..dfd05ce254fed6e72c04173bed3ca3bbc611da24 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) {
+static int change_basedir(const char *orig_dir, int nocreate) {
char *dir;
size_t dirlen;
int status;
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;
+ 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 = chdir(dir);
#if COLLECT_DAEMON
" -f Don't fork to the background.\n"
#endif
+ " -B Don't create the BaseDir\n"
" -h Display help (this message)\n"
"\nBuiltin defaults:\n"
" Config file " CONFIGFILE "\n"
int test_config = 0;
int test_readall = 0;
const char *basedir;
+ int basedir_nocreate = 0;
#if COLLECT_DAEMON
pid_t pid;
int daemonize = 1;
while (1) {
int c;
- c = getopt(argc, argv, "htTC:"
+ c = getopt(argc, argv, "BhtTC:"
#if COLLECT_DAEMON
"fP:"
#endif
break;
switch (c) {
+ case 'B':
+ basedir_nocreate = 1;
+ break;
case 'C':
configfile = optarg;
break;
fprintf(stderr,
"Don't have a basedir to use. This should not happen. Ever.");
return 1;
- } else if (change_basedir(basedir)) {
+ } else if (change_basedir(basedir, basedir_nocreate)) {
fprintf(stderr, "Error: Unable to change to directory `%s'.\n", basedir);
return 1;
}