mirror of https://github.com/nealey/irc-bot
Make select work, and remove handled files
This commit is contained in:
parent
919432ff6b
commit
18f365945d
14
bot.c
14
bot.c
|
@ -13,7 +13,8 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include "dispatch.h"
|
|
||||||
|
#include "dump.h"
|
||||||
|
|
||||||
#define MAX_ARGS 50
|
#define MAX_ARGS 50
|
||||||
#define MAX_SUBPROCS 50
|
#define MAX_SUBPROCS 50
|
||||||
|
@ -318,13 +319,14 @@ 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
|
// Read a line. If we didn't have enough space, pretend it was a line
|
||||||
// anyway.
|
// anyway.
|
||||||
fgets(line, sizeof line, f);
|
while (fgets(line, sizeof line, f)) {
|
||||||
linelen = strlen(line);
|
linelen = strlen(line);
|
||||||
if (line[linelen-1] != '\n') {
|
if (line[linelen-1] != '\n') {
|
||||||
line[linelen++] = '\n';
|
line[linelen++] = '\n';
|
||||||
}
|
}
|
||||||
func(line, linelen);
|
func(line, linelen);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
handle_subproc(struct subproc *s)
|
handle_subproc(struct subproc *s)
|
||||||
|
@ -384,14 +386,12 @@ loop()
|
||||||
snprintf(fn, sizeof fn, "%s/%s", msgdir, ent->d_name);
|
snprintf(fn, sizeof fn, "%s/%s", msgdir, ent->d_name);
|
||||||
f = fopen(fn, "r");
|
f = fopen(fn, "r");
|
||||||
if (f) {
|
if (f) {
|
||||||
while (! feof(f)) {
|
|
||||||
handle_file(f, output);
|
handle_file(f, output);
|
||||||
}
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
}
|
|
||||||
remove(fn);
|
remove(fn);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (d) {
|
if (d) {
|
||||||
closedir(d);
|
closedir(d);
|
||||||
|
@ -408,7 +408,9 @@ loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
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));
|
} while ((-1 == ret) && (EINTR == errno));
|
||||||
if (-1 == ret) {
|
if (-1 == ret) {
|
||||||
perror("select");
|
perror("select");
|
||||||
|
|
Loading…
Reference in New Issue