]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Wed, 8 Sep 2021 06:18:01 +0000 (23:18 -0700)
committeralex <[email protected]>
Wed, 8 Sep 2021 06:18:01 +0000 (23:18 -0700)
Makefile.am
inc/default.h
src/default.c
src/setup.c

index 0d16745eb430917b245325d129408e609be9dea5..fbc11a293b7f801af49fee7758a66bd98f410fce 100644 (file)
@@ -1,4 +1,5 @@
 AM_CPPFLAGS = \
+       -DPREFIX=\"$(localstatedir)/seeder\" \
        -Wall \
        -Werror
 
index 3a91225ef976c676c913a9dbf0c1db70bb315aab..7f1a88a3b8ed503ba000f9ff547cd7ba42a68041 100644 (file)
@@ -1,12 +1,14 @@
 #ifndef __DEFAULT_H_
 #define __DEFAULT_H_
 
+#include<dirent.h>
 #include<unistd.h>
 
 #include<log.h>
 #include<opt.h>
 
 #define DEFAULT_MESSAGE_SETTING_DEFAULTS "setting default values\n"
+#define DEFAULT_MESSAGE_COULD_NOT_OPEN "could not open " PREFIX "\n"
 
 int defaults();
 
index c55fff931734634d67caac815425483a9d0163a4..b3521ea37f92b0cf69b08a6b0b826437519d4f7b 100644 (file)
@@ -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;
 }
index 166572a50493b5b80759d58828ebad22a5539962..53ce50b45ecee40f16b5cac2bc2658c97efc7895 100644 (file)
@@ -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;
 }