]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sun, 5 Sep 2021 04:32:39 +0000 (21:32 -0700)
committeralex <[email protected]>
Sun, 5 Sep 2021 04:32:39 +0000 (21:32 -0700)
Makefile.am
inc/log.h
inc/main.h
inc/opt.h
src/default.c
src/main.c
src/opt/config.c [new file with mode: 0644]

index 563cb17cf4883370f6a5a3e124b80aec982cec7f..69bea3dc29057ed15e57407cce8fc80f03db484b 100644 (file)
@@ -2,12 +2,19 @@ AM_CPPFLAGS = \
        -Wall \
        -Werror
 
+if ENABLE_DEBUG
+else
+AM_CPPFLAGS += \
+       -DNDEBUG
+endif
+
 bin_PROGRAMS = seederd
 
 seederd_SOURCES = \
        src/default.c \
        src/log.c \
        src/main.c \
+       src/opt/config.c \
        src/opt/loglevel.c \
        src/setup.c \
        src/usage.c
index 3b075d7d0b7f00066445f59e5e3e825fdc55d80a..d705a8ccc34b9cd8fe1f857a3e0899ba20795577 100644 (file)
--- a/inc/log.h
+++ b/inc/log.h
@@ -17,9 +17,16 @@ enum log_level {
        LOG_LEVEL_VERBOSE = 3  /* logging and debugging info */
 };
 
+#ifndef NDEBUG
+#define LOG_WITH_THREAD_PREFIX(level,fd,...) log_message(level,fd,LOG_THREAD_PREFIX_MESSAGE,pthread_self());log_message(level,fd,__VA_ARGS__)
+#define log_err(...) LOG_WITH_THREAD_PREFIX(LOG_LEVEL_ERRORS,stderr,__VA_ARGS__)
+#define log_info(...) LOG_WITH_THREAD_PREFIX(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__)
+#define log_msg(...) LOG_WITH_THREAD_PREFIX(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__)
+#else
 #define log_err(...) log_message(LOG_LEVEL_ERRORS,stderr,__VA_ARGS__)
 #define log_info(...) log_message(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__)
 #define log_msg(...) log_message(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__)
+#endif
 
 #define LOG_FLUSH_MESSAGE "flushing log queue...\n"
 #define LOG_THREAD_START_MESSAGE "logging thread start\n"
index ea1db5b4d16f4c4598a2bc8394d94d9c12ccf3c3..b4c82cd87e23cc3bfc29f040a5e3b866b8b0ef66 100644 (file)
@@ -3,13 +3,14 @@
 
 #include<getopt.h>
 #include<stdlib.h>
-#include<unistd.h>
 
 #include<default.h>
 #include<log.h>
 #include<setup.h>
 #include<usage.h>
 
+#define MAIN_SHUTDOWN_MESSAGE "shutting down...\n"
+
 int main(int,char**);
 
 #endif
index 3384104ccb8f56b2547e4a6447037eb7ac6f7802..c03415febe104d824d1b099938ab4cdd2128d055 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -3,6 +3,9 @@
 
 #include<log.h>
 
+#define OPT_LOADING_CONFIG_FILE_MESSAGE "loading config file %s\n"
+
+int opt_load_config_file(char*);
 void opt_set_log_level(enum log_level);
 
 #endif
index 5a8248724c07879e9d94e350f840b70136897143..21896cb551a10891930066ece29189f93ec20a93 100644 (file)
@@ -3,7 +3,11 @@
 int defaults() {
        logging_thread = pthread_self();
 
+#ifndef NDEBUG
+       opt_set_log_level(LOG_LEVEL_VERBOSE);
+#else
        opt_set_log_level(LOG_LEVEL_DEFAULT);
+#endif
        
        return 1;
 }
index 8cabfb64f3efa0ca80a2fcce462a74633305d308..e114384e021535bb1eb515e7e1f86da89fdc5697 100644 (file)
@@ -1,6 +1,7 @@
 #include<main.h>
 
 static struct option long_options[] = {
+       {"config-file", required_argument, 0, 'c'},
        {"daemon", no_argument, 0, 'd'},
        {"help", no_argument, 0, 'h'},
        {"quiet", no_argument, &verbose_flag, LOG_LEVEL_SILENT},
@@ -16,9 +17,12 @@ int main(int argc, char **argv) {
        while(1) {
                int option_index = 0;
 
-               if((c = getopt_long(argc,argv,"dhqv",long_options,&option_index))==-1) { break; }
+               if((c = getopt_long(argc,argv,"c:dhqv",long_options,&option_index))==-1) { break; }
 
                switch(c) {
+                       case 'c':
+                               if(opt_load_config_file(optarg)<0) { return EXIT_FAILURE; }
+                               break;
                        case 'd':
                                log_err("not implemented\n");
                                return EXIT_FAILURE;
@@ -40,5 +44,8 @@ int main(int argc, char **argv) {
 
        if(setup()<0) { return EXIT_FAILURE; }
 
+       log_err("this is a test %d %s\n",10,"what?");
+       while(1) { }
+
        return EXIT_FAILURE;
 }
diff --git a/src/opt/config.c b/src/opt/config.c
new file mode 100644 (file)
index 0000000..3b1d8d4
--- /dev/null
@@ -0,0 +1,7 @@
+#include<opt.h>
+
+int opt_load_config_file(char *path) {
+       log_info(OPT_LOADING_CONFIG_FILE_MESSAGE,path);
+       log_err("not implemented\n");
+       return -1;
+}