From: alex Date: Fri, 3 Sep 2021 21:19:44 +0000 (-0700) Subject: ... X-Git-Url: http://git.infiniteadaptability.org/?a=commitdiff_plain;h=5dcc5c2e9a77867f6c87ec3d9c4e0aae3787346c;p=seeder ... --- diff --git a/.gitignore b/.gitignore index 92947ef..eedf05a 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,3 @@ stamp-h1 *.tests # binaries -rss/rss-create -rss/*_tests -seederd/seederd diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..e247a38 --- /dev/null +++ b/Makefile.am @@ -0,0 +1,19 @@ +AM_CPPFLAGS = \ + -I$(top_builddir)/inc/ \ + -I$(top_srcdir)/inc/ + +bin_PROGRAMS = seederd + +seederd_SOURCES = \ + src/default.c \ + src/log.c \ + src/main.c \ + src/opt/loglevel.c \ + src/usage.c + +seederd_SOURCES += \ + inc/default.h \ + inc/log.h \ + inc/main.h \ + inc/opt.h \ + inc/usage.h diff --git a/configure.ac b/configure.ac index 87f1522..ddbe493 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,11 @@ AC_PREREQ([2.69]) AC_INIT([seeder], [0.0.0]) + +# Store build files not in main directory +AC_CONFIG_AUX_DIR([build-aux]) + +AM_INIT_AUTOMAKE([foreign subdir-objects nostdinc -Wall -Werror]) + AC_CONFIG_SRCDIR([src/main.c]) AC_CONFIG_HEADERS([config.h]) @@ -15,4 +21,5 @@ AC_CHECK_HEADERS([stdlib.h]) # Checks for library functions. +AC_CONFIG_FILES([Makefile]) AC_OUTPUT diff --git a/inc/default.h b/inc/default.h index bfe63a1..c043bf8 100644 --- a/inc/default.h +++ b/inc/default.h @@ -1,6 +1,8 @@ #ifndef __DEFAULT_H_ #define __DEFAULT_H_ +#include + int defaults(); #endif diff --git a/inc/log.h b/inc/log.h index 43006ce..3ecca33 100644 --- a/inc/log.h +++ b/inc/log.h @@ -3,6 +3,7 @@ #include #include +#include extern int verbose_flag; @@ -13,10 +14,13 @@ enum log_level { LOG_LEVEL_VERBOSE = 3 /* logging and debugging info */ }; -#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__) +extern thrd_t logging_thread; +#define log_err(...) log_enqueue(LOG_LEVEL_ERRORS,stderr,__VA_ARGS__) +#define log_info(...) log_enqueue(LOG_LEVEL_VERBOSE,stdout,__VA_ARGS__) +#define log_msg(...) log_enqueue(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__) + +void log_enqueue(enum log_level,FILE*,const char*,...); void log_message(enum log_level,FILE*,const char*,...); #endif diff --git a/inc/main.h b/inc/main.h index b00db75..99e116d 100644 --- a/inc/main.h +++ b/inc/main.h @@ -1,6 +1,7 @@ #ifndef __MAIN_H_ #define __MAIN_H_ +#include #include #include diff --git a/seederd b/seederd new file mode 100755 index 0000000..c2136b1 Binary files /dev/null and b/seederd differ diff --git a/src/default.c b/src/default.c index b891dc4..262fd21 100644 --- a/src/default.c +++ b/src/default.c @@ -1,6 +1,10 @@ #include +thrd_t logging_thread; + int defaults() { + logging_thread = thrd_current(); + opt_set_log_level(LOG_LEVEL_DEFAULT); return 1; diff --git a/src/log.c b/src/log.c index c10d250..5c73ef5 100644 --- a/src/log.c +++ b/src/log.c @@ -2,11 +2,22 @@ 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); + va_end(args); +} + void log_message(enum log_level level, FILE *out_stream, const char *format,...) { - if(level<=verbose_flag) { + if(level>verbose_flag) { return; } + + if(thrd_equal(logging_thread,thrd_current)) { va_list args; va_start(args,format); - vfprintf(out_stream,format,args); + vfprintf(out_stream,message); va_end(args); + } else { + log_enqueue(level,out_stream,format,...); } } diff --git a/src/usage.c b/src/usage.c new file mode 100644 index 0000000..de83968 --- /dev/null +++ b/src/usage.c @@ -0,0 +1,4 @@ +#include + +void usage() { +}