From: alex Date: Sun, 5 Sep 2021 04:32:39 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=23e15e39d2caf2691ba48c9e402c2d37c76d6c78;p=seeder ... --- diff --git a/Makefile.am b/Makefile.am index 563cb17..69bea3d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 diff --git a/inc/log.h b/inc/log.h index 3b075d7..d705a8c 100644 --- 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" diff --git a/inc/main.h b/inc/main.h index ea1db5b..b4c82cd 100644 --- a/inc/main.h +++ b/inc/main.h @@ -3,13 +3,14 @@ #include #include -#include #include #include #include #include +#define MAIN_SHUTDOWN_MESSAGE "shutting down...\n" + int main(int,char**); #endif diff --git a/inc/opt.h b/inc/opt.h index 3384104..c03415f 100644 --- a/inc/opt.h +++ b/inc/opt.h @@ -3,6 +3,9 @@ #include +#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 diff --git a/src/default.c b/src/default.c index 5a82487..21896cb 100644 --- a/src/default.c +++ b/src/default.c @@ -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; } diff --git a/src/main.c b/src/main.c index 8cabfb6..e114384 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include 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 index 0000000..3b1d8d4 --- /dev/null +++ b/src/opt/config.c @@ -0,0 +1,7 @@ +#include + +int opt_load_config_file(char *path) { + log_info(OPT_LOADING_CONFIG_FILE_MESSAGE,path); + log_err("not implemented\n"); + return -1; +}