From 63e6c50030c2cb0278497117a1cf4dd61d300501 Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 3 Sep 2021 17:44:18 -0700 Subject: [PATCH] ... --- Makefile.am | 2 ++ inc/log.h | 8 ++++++++ inc/setup.h | 2 +- src/log.c | 20 ++++++++++---------- src/setup.c | 4 +++- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/Makefile.am b/Makefile.am index e247a38..3371098 100644 --- a/Makefile.am +++ b/Makefile.am @@ -9,6 +9,7 @@ seederd_SOURCES = \ src/log.c \ src/main.c \ src/opt/loglevel.c \ + src/setup.c \ src/usage.c seederd_SOURCES += \ @@ -16,4 +17,5 @@ seederd_SOURCES += \ inc/log.h \ inc/main.h \ inc/opt.h \ + inc/setup.h \ inc/usage.h diff --git a/inc/log.h b/inc/log.h index 08dcf18..912681a 100644 --- a/inc/log.h +++ b/inc/log.h @@ -1,10 +1,12 @@ #ifndef __LOG_H_ #define __LOG_H_ +#include #include #include extern int verbose_flag; +extern pthread_t logging_thread; enum log_level { LOG_LEVEL_SILENT = 0, /* suppresses all output */ @@ -17,6 +19,12 @@ enum log_level { #define log_info(...) log_enqueue(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__) #define log_msg(...) log_enqueue(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__) +struct log_entry { + enum log_level level; + char buf[LOG_ENTRY_MAX_LENGTH]; + FILE *out_stream; +}; + void log_enqueue(enum log_level,FILE*,const char*,...); void log_message(enum log_level,FILE*,const char*,...); void log_poll(); diff --git a/inc/setup.h b/inc/setup.h index 9077be8..c3e6a24 100644 --- a/inc/setup.h +++ b/inc/setup.h @@ -1,7 +1,7 @@ #ifndef __SETUP_H_ #define __SETUP_H_ -#include +#include int setup(); diff --git a/src/log.c b/src/log.c index 38691a2..74b2bdb 100644 --- a/src/log.c +++ b/src/log.c @@ -5,26 +5,26 @@ int verbose_flag = LOG_LEVEL_DEFAULT; void log_enqueue(enum log_level level, FILE *out_stream, const char *format,...) { va_list args; va_start(args,format); - vsnprintf(buf,format,args); +// vsnprintf(buf,format,args); va_end(args); } void log_message(enum log_level level, FILE *out_stream, const char *format,...) { if(level>verbose_flag) { return; } - if(thrd_equal(logging_thread,thrd_current())) { - va_list args; - va_start(args,format); - vfprintf(out_stream,message); - va_end(args); - } else { + va_list args; + + if(0==pthread_equal(pthread_self(),logging_thread)) { log_enqueue(level,out_stream,format,...); + } else { + va_start(args,format); + vfprintf(out_stream,format,args); } + + va_end(args); } -int log_poll(void *arg) { +void log_poll() { while(1) { } - - return 1; } diff --git a/src/setup.c b/src/setup.c index b71171c..41ae3fb 100644 --- a/src/setup.c +++ b/src/setup.c @@ -1,7 +1,9 @@ #include +pthread_t logging_thread; + int setup() { - if(pthread_create(&logging_thread,&log_poll)!=0) { + if(pthread_create(&logging_thread,NULL,&log_poll)!=0) { perror("pthread_create"); return -1; } -- 2.39.5