*.tests
# binaries
+seederd
+AM_CPPFLAGS = \
+ -Wall \
+ -Werror
+
bin_PROGRAMS = seederd
seederd_SOURCES = \
AC_CONFIG_SRCDIR([src/main.c])
AC_CONFIG_HEADERS([inc/config.h])
+AC_ARG_ENABLE([debug],
+ [AS_HELP_STRING([--enable-debug],
+ [enable debugging])],
+ [enable_debug=$enableval],
+ [enable_debug=no])
+
+AC_ARG_ENABLE([tests],
+ [AS_HELP_STRING([--disable-tests],
+ [disable tests (enabled by default)])],
+ [enable_tests=$enableval],
+ [enable_tests=yes])
+
+AC_ARG_ENABLE([memcheck],
+ [AS_HELP_STRING([--disable-memcheck],
+ [disable memcheck with valgrind (enabled by default)])],
+ [enable_memcheck=$enableval],
+ [enable_memcheck=yes])
+
+AC_PATH_PROG([VALGRIND], [valgrind])
+AM_CONDITIONAL([HAVE_VALGRIND], [test -n "$VALGRIND"])
+
+AC_MSG_CHECKING([if debugging])
+if test x$enable_debug != xno; then
+ AC_MSG_RESULT(yes)
+ CFLAGS="-ggdb -O0"
+else
+ AC_MSG_RESULT(no)
+fi
+
+AM_CONDITIONAL([ENABLE_DEBUG],[test x$enable_debug != xno])
+
+dnl disable memcheck if valgrind not found
+if test "x$enable_memcheck" != "xno"; then
+ if test -z "$VALGRIND"; then
+ enable_memcheck=no
+ fi
+fi
+
+AC_MSG_CHECKING([if memcheck should be enabled])
+if test x$enable_memcheck != xno; then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+fi
+
+AM_CONDITIONAL([ENABLE_MEMCHECK],[test x$enable_memcheck = xyes])
+
# Checks for programs.
AC_PROG_CC
#ifndef __DEFAULT_H_
#define __DEFAULT_H_
+#include<log.h>
#include<opt.h>
int defaults();
#define log_msg(...) log_message(LOG_LEVEL_DEFAULT,stdout,__VA_ARGS__)
#define LOG_FLUSH_MESSAGE "flushing log queue...\n"
+#define LOG_THREAD_START_MESSAGE "logging thread start\n"
+#define LOG_THREAD_PREFIX_MESSAGE "[thread=%ld] "
#define LOG_ENTRY_MAX_LENGTH 100
#define LOG_QUEUE_SIZE 100
int log_entries_init();
void log_entries_clean();
void log_flush();
-void log_print(struct log_entry*);
+void log_print();
void log_message(enum log_level,FILE*,const char*,...);
void *log_poll(void*);
#include<getopt.h>
#include<stdlib.h>
+#include<unistd.h>
#include<default.h>
#include<log.h>
+#include<setup.h>
#include<usage.h>
int main(int,char**);
#include<log.h>
int setup();
+int setup_logging();
#endif
#include<default.h>
int defaults() {
+ logging_thread = pthread_self();
+
opt_set_log_level(LOG_LEVEL_DEFAULT);
return 1;
}
void log_flush() {
- log_err(LOG_FLUSH_MESSAGE);
-
pthread_mutex_lock(&logging_mutex);
+ if(helper.start!=NULL) {
+ fputs(LOG_FLUSH_MESSAGE,stderr);
+ }
+
while(helper.start!=NULL) {
log_print(helper.start);
- helper.start = helper.start->next;
}
helper.start = NULL;
pthread_mutex_unlock(&logging_mutex);
}
-void log_print(struct log_entry *p) {
- fputs(p->out_stream,p->buf);
+void log_print() {
+ struct log_entry *p = helper.start;
+ if(NULL!=p) {
+ fputs(p->buf,p->out_stream);
+ helper.start = p->next;
+ }
}
void log_message(enum log_level level, FILE *out_stream, const char *format,...) {
}
}
- p = &(helper.p[offset*sizeof(struct log_entry)]);
+ p = helper.p + offset*sizeof(struct log_entry);
p->level = level;
p->out_stream = out_stream;
}
void *log_poll(void *p) {
+ log_info(LOG_THREAD_START_MESSAGE);
while(1) {
+ pthread_mutex_lock(&logging_mutex);
+ log_print();
+ pthread_mutex_unlock(&logging_mutex);
}
return NULL;
}
}
- log_msg("here?\n");
-
if(setup()<0) { return EXIT_FAILURE; }
- log_msg("here!\n");
return EXIT_FAILURE;
}
#include<setup.h>
+
+int setup() {
+ if(setup_logging()<0) { return -1; }
+ return 1;
+}
+
pthread_t logging_thread;
pthread_mutex_t logging_mutex = PTHREAD_MUTEX_INITIALIZER;
-int setup() {
+int setup_logging() {
+ if(0!=atexit(&log_entries_clean)) {
+ perror("atexit");
+ return -1;
+ }
+
+ if(0!=atexit(&log_flush)) {
+ perror("atexit");
+ return -1;
+ }
+
if(log_entries_init()<0) { return -1; }
if(pthread_create(&logging_thread,NULL,&log_poll,NULL)!=0) {
perror("pthread_create");
return -1;
}
+
+ return 1;
}