From 18f365945db33c4342abd30f73cf74da971c268a Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Wed, 14 Nov 2012 20:52:54 -0700 Subject: [PATCH] Make select work, and remove handled files --- bot.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/bot.c b/bot.c index ea67d9e..d07e37f 100644 --- a/bot.c +++ b/bot.c @@ -13,7 +13,8 @@ #include #include #include -#include "dispatch.h" + +#include "dump.h" #define MAX_ARGS 50 #define MAX_SUBPROCS 50 @@ -318,12 +319,13 @@ handle_file(FILE *f, void (*func) (const char *, size_t)) // Read a line. If we didn't have enough space, pretend it was a line // anyway. - fgets(line, sizeof line, f); - linelen = strlen(line); - if (line[linelen-1] != '\n') { - line[linelen++] = '\n'; + while (fgets(line, sizeof line, f)) { + linelen = strlen(line); + if (line[linelen-1] != '\n') { + line[linelen++] = '\n'; + } + func(line, linelen); } - func(line, linelen); } void @@ -384,12 +386,10 @@ loop() snprintf(fn, sizeof fn, "%s/%s", msgdir, ent->d_name); f = fopen(fn, "r"); if (f) { - while (! feof(f)) { - handle_file(f, output); - } + handle_file(f, output); fclose(f); + remove(fn); } - remove(fn); } } @@ -408,7 +408,9 @@ loop() } do { - ret = select(nfds + 1, &rfds, NULL, NULL, NULL); + struct timeval timeout = {1, 0}; + + ret = select(nfds + 1, &rfds, NULL, NULL, msgdir?(&timeout):NULL); } while ((-1 == ret) && (EINTR == errno)); if (-1 == ret) { perror("select");