]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sat, 4 Sep 2021 00:44:18 +0000 (17:44 -0700)
committeralex <[email protected]>
Sat, 4 Sep 2021 00:44:18 +0000 (17:44 -0700)
Makefile.am
inc/log.h
inc/setup.h
src/log.c
src/setup.c

index e247a384361034ea09b71379c4108819ea4527dd..3371098a1f0c9f989e03b21a1351b0085ddbee92 100644 (file)
@@ -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
index 08dcf18aa7dfba4176cbe59e419fc1882b5d5911..912681a840b940c94416ef9ad92695066585b822 100644 (file)
--- a/inc/log.h
+++ b/inc/log.h
@@ -1,10 +1,12 @@
 #ifndef __LOG_H_
 #define __LOG_H_
 
+#include<pthread.h>
 #include<stdarg.h>
 #include<stdio.h>
 
 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();
index 9077be861bc57934c33fdd91fca9a51c899ef700..c3e6a24879b2380f4f4e50912f6e7d949ee83b08 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __SETUP_H_
 #define __SETUP_H_
 
-#include<pthread.h>
+#include<log.h>
 
 int setup();
 
index 38691a2f75add3092a54283cc9d3e596e92b958a..74b2bdbe13362f9a18c85a40ca731eccb52b9450 100644 (file)
--- 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;
 }
index b71171c9262f77dcf44426290b20f98603468d43..41ae3fb89d94a33e7ab7bbd9a02d21e127b89c93 100644 (file)
@@ -1,7 +1,9 @@
 #include<setup.h>
 
+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;
        }