@@ -184,11 +184,11 @@ } /* Log a message */ //#define FILED_DONT_LOG #ifdef FILED_DONT_LOG -# define filed_logging_thread_init() 0 +# define filed_logging_thread_init(x) 0 # define filed_log_msg_debug(x, ...) /**/ # define filed_log_msg(x) /**/ #else #ifdef FILED_DEBUG # define filed_log_msg_debug(x, ...) { fprintf(stderr, x, __VA_ARGS__); fprintf(stderr, "\n"); fflush(stderr); } @@ -223,10 +223,11 @@ } curr = prev; while (curr) { fprintf(fp, "%s THREAD=%llu\n", curr->buffer, (unsigned long long) curr->thread); + fflush(fp); prev = curr; curr = curr->_prev; free(prev); @@ -234,23 +235,13 @@ } return(NULL); } -static int filed_logging_thread_init(const char *logfile) { +static int filed_logging_thread_init(FILE *logfp) { struct filed_logging_thread_args *args; pthread_t thread_id; - FILE *logfp; - - if (strcmp(logfile, "-") == 0) { - logfp = stdout; - } else { - logfp = fopen(logfile, "a+"); - if (logfp == NULL) { - return(1); - } - } args = malloc(sizeof(*args)); args->fp = logfp; filed_log_msg_list = NULL; @@ -1004,10 +995,11 @@ /* Run process */ int main(int argc, char **argv) { struct option options[10]; const char *bind_addr = BIND_ADDR, *newroot = NULL, *log_file = LOG_FILE; + FILE *log_fp; uid_t user = 0; int port = PORT, thread_count = THREAD_COUNT; int cache_size = CACHE_SIZE; int init_ret, chroot_ret, setuid_ret, lookup_ret, chdir_ret; int setuid_enabled = 0, daemon_enabled = 0; @@ -1066,10 +1058,22 @@ filed_print_help(stdout, 1, NULL); return(0); } } + + /* Open log file */ + if (strcmp(log_file, "-") == 0) { + log_fp = stdout; + } else { + log_fp = fopen(log_file, "a+"); + if (log_fp == NULL) { + perror("fopen"); + + return(4); + } + } /* Create listening socket */ fd = filed_listen(bind_addr, port); if (fd < 0) { perror("filed_listen"); @@ -1116,11 +1120,11 @@ return(3); } /* Create logging thread */ - init_ret = filed_logging_thread_init(log_file); + init_ret = filed_logging_thread_init(log_fp); if (init_ret != 0) { perror("filed_logging_thread_init"); return(4); }