X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcollectd.c;h=af8fb568bb21db3254c38bb76d1911a1cafc8a30;hb=7a8cd12cc66a349106a34a7655944cfeac71d7c5;hp=2edfa3774ca763067d5eefcbfa7fde6791c99b60;hpb=b165cd13cd30a30ac830df1f6f6fbd52474a6f64;p=collectd.git diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 2edfa377..af8fb568 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -158,7 +158,7 @@ static int init_global_variables(void) { return 0; } /* int init_global_variables */ -static int change_basedir(const char *orig_dir) { +static int change_basedir(const char *orig_dir, _Bool create) { char *dir; size_t dirlen; int status; @@ -183,7 +183,7 @@ static int change_basedir(const char *orig_dir) { 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))); @@ -250,6 +250,7 @@ __attribute__((noreturn)) static void exit_usage(int status) { #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" @@ -459,6 +460,7 @@ int main(int argc, char **argv) { int test_config = 0; int test_readall = 0; const char *basedir; + _Bool opt_create_basedir = 1; #if COLLECT_DAEMON pid_t pid; int daemonize = 1; @@ -469,7 +471,7 @@ int main(int argc, char **argv) { while (1) { int c; - c = getopt(argc, argv, "htTC:" + c = getopt(argc, argv, "BhtTC:" #if COLLECT_DAEMON "fP:" #endif @@ -479,6 +481,9 @@ int main(int argc, char **argv) { break; switch (c) { + case 'B': + opt_create_basedir = 0; + break; case 'C': configfile = optarg; break; @@ -533,7 +538,7 @@ int main(int argc, char **argv) { 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, opt_create_basedir)) { fprintf(stderr, "Error: Unable to change to directory `%s'.\n", basedir); return 1; }