From: alex Date: Wed, 8 Sep 2021 06:18:01 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=3736e9c2e65b8949ba73fc02cbdac70e74adfa7b;p=seeder ... --- diff --git a/Makefile.am b/Makefile.am index 0d16745..fbc11a2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,5 @@ AM_CPPFLAGS = \ + -DPREFIX=\"$(localstatedir)/seeder\" \ -Wall \ -Werror diff --git a/inc/default.h b/inc/default.h index 3a91225..7f1a88a 100644 --- a/inc/default.h +++ b/inc/default.h @@ -1,12 +1,14 @@ #ifndef __DEFAULT_H_ #define __DEFAULT_H_ +#include #include #include #include #define DEFAULT_MESSAGE_SETTING_DEFAULTS "setting default values\n" +#define DEFAULT_MESSAGE_COULD_NOT_OPEN "could not open " PREFIX "\n" int defaults(); diff --git a/src/default.c b/src/default.c index c55fff9..b3521ea 100644 --- a/src/default.c +++ b/src/default.c @@ -2,6 +2,8 @@ struct options global_options; +static int default_add_all_directories(); + int defaults() { // logging needs to be setup first logging_thread = pthread_self(); @@ -22,6 +24,42 @@ int defaults() { snprintf(buf,10,"%lu",sysconf(_SC_NPROCESSORS_ONLN)); if(opt_set_worker_threads(buf)<0) { return -1; } } - + + if(default_add_all_directories()<0) { return -1; } + + return 1; +} + +static int default_add_all_directories() { + // add all directories in PREFIX + DIR *dir; + struct dirent *ent; + char *p; + if((dir = opendir(PREFIX))==NULL) { + log_err(DEFAULT_MESSAGE_COULD_NOT_OPEN); + return -1; + } + + while((ent = readdir(dir))!=NULL) { + if(strcmp(ent->d_name,".")==0) { continue; } + if(strcmp(ent->d_name,"..")==0) { continue; } + + p = malloc(sizeof(char)*(strlen(PREFIX)+strlen(ent->d_name)+1)); + if(NULL==p) { + perror("malloc"); + return -1; + } + + sprintf(p,PREFIX "/%s",ent->d_name); + if(opt_add_watch(p)<0) { + free(p); + return -1; + } + + free(p); + } + + closedir(dir); + return 1; } diff --git a/src/setup.c b/src/setup.c index 166572a..53ce50b 100644 --- a/src/setup.c +++ b/src/setup.c @@ -6,8 +6,6 @@ int setup() { // logging must be setup first if(setup_logging()<0) { return -1; } - if(setup_session()<0) { return -1; } - return 1; }