summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-29 21:13:16 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-29 21:13:16 +0100
commit50f345b10e489c3099497c10f493663fee631683 (patch)
tree86dc7d816d74acb4ce2365124d84b12d0bd69974
parentc5a9bc507e9724090a63cdfb3b6df13a0ff74582 (diff)
Don't exit if there's a failure to read/write from/to the replay log file.
-rw-r--r--TODO2
-rw-r--r--blabouncer.c12
-rw-r--r--replay.c21
3 files changed, 19 insertions, 16 deletions
diff --git a/TODO b/TODO
index 20dff69..e416113 100644
--- a/TODO
+++ b/TODO
@@ -14,5 +14,3 @@ Implement daemon (background) mode.
Implement BLABOUNCER EXIT command.
Some text gets written to previous debug.txt upon startup (getconfstr() output).
-
-Don't exit if there's a failure to read the replay log file/line.
diff --git a/blabouncer.c b/blabouncer.c
index fe8cd1e..b6dc015 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -502,8 +502,8 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
debugprint("Replay log lines: '%d'.\n", numlines);
if (numlines < 0) {
- printf("Error getting number of replay lines.\n");
- exit(1);
+ debugprint("Error getting number of replay lines.\n");
+ return 0;
} else if (numlines == 0) {
snprintf(outgoingmsg, MAXDATASIZE, "NOTICE %s :0 replay log lines found in the time requested, nothing to send.", ircdstrings->ircnick);
sendtoclient(sourcefd, outgoingmsg, clients, settings, 0);
@@ -517,8 +517,8 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
// Replay those lines!
for (int i = 0; i < numlines; i++) {
if (!readreplayline(replayseconds, i, outgoingmsg, settings->basedir)) {
- printf("Error requesting replay line.\n");
- exit(1);
+ debugprint("Error requesting replay line.\n");
+ return 0;
}
// Check if the replay line is a TOPIC, a JOIN, or a PART so we don't
@@ -538,8 +538,8 @@ int doreplay(int sourcefd, int replayseconds, struct client *clients, struct set
for (int j = 0; j < 3; j++) {
// Try to split
if ((token = strsep(&strcopy, " ")) == NULL) {
- printf("doreplay(): error splitting string on iteration %d, exiting!\n", j);
- exit(1);
+ debugprint("doreplay(): error splitting string on iteration %d, exiting!\n", j);
+ return 0;
}
// Copy into the token array (strlen + 1 to get the NULL terminator)
strncpy(tokens[j], token, strlen(token) + 1);
diff --git a/replay.c b/replay.c
index 410463b..7201082 100644
--- a/replay.c
+++ b/replay.c
@@ -154,6 +154,7 @@ int replaylines(int seconds, char *basedir) {
if (fp == NULL) {
printf("error: could not open replay log '%s'.\n", filename);
// Assume the file just doesn't exist yet - TODO - Interpret error codes to see what happened.
+ fclose(fp);
return 0;
}
@@ -198,8 +199,9 @@ int readreplayline(int seconds, int linenum, char *str, char *basedir) {
fp = fopen(filename, "r");
if (fp == NULL) {
- printf("error: could not open replay log '%s'.\n", filename);
- exit(1);
+ debugprint("error: could not open replay log '%s'.\n", filename);
+ fclose(fp);
+ return 0;
}
// Get the current time for comparison later
@@ -209,8 +211,9 @@ int readreplayline(int seconds, int linenum, char *str, char *basedir) {
// Read the timestamp from each line
int timestamp = gettimestamp(line);
if (timestamp < 1) {
- printf("Error reading timestamp from replay log file.\n");
- exit(1);
+ debugprint("Error reading timestamp from replay log file.\n");
+ fclose(fp);
+ return 0;
}
// If the line is within range of the requested time...
@@ -254,8 +257,9 @@ int writereplayline(char *str, char *basedir) {
fp = fopen(filename, "a");
if (fp == NULL) {
- printf("error: could not open replay log '%s' for writing.\n", filename);
- exit(1);
+ debugprint("error: could not open replay log '%s' for writing.\n", filename);
+ fclose(fp);
+ return 0;
}
// Get the current time and manipulate it into a C string
@@ -274,8 +278,9 @@ int writereplayline(char *str, char *basedir) {
// Write complete line to file
if ((bytes = fprintf(fp, "%s", line)) < 0) {
- printf("error: could not write to replay log file.\n");
- exit(1);
+ debugprint("error: could not write to replay log file.\n");
+ fclose(fp);
+ return 0;
}
fclose(fp);