summaryrefslogtreecommitdiff
path: root/logging.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-05-30 22:02:07 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-05-30 22:02:07 +0100
commitfd33289346881b96841a598a1f8980212b0bab62 (patch)
tree2de9e0c65af5c2d138e3141c88fb826c0ea133dc /logging.c
parent6d183c02a50a42743c3031532f458ab5cea0685d (diff)
Remove most (all?) exit()s with error handling without exiting where possible. Convert most remaining printing to stdout/stderr to debugprint() instead.
Diffstat (limited to 'logging.c')
-rw-r--r--logging.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/logging.c b/logging.c
index 973d03c..e3edb02 100644
--- a/logging.c
+++ b/logging.c
@@ -52,8 +52,8 @@ int logline(char *str, char *ournick, char *basedir, int type) {
for (int i = 0; i < 3; i++) {
// Try to split
if ((token = strsep(&str, " ")) == NULL) {
- printf("Error splitting string for logging, exiting!\n");
- exit(1);
+ debugprint(DEBUG_CRIT, "Error splitting string for logging, returning!\n");
+ return 0;
}
// Copy into the token array (strlen + 1 to get the NULL terminator)
strncpy(tokens[i], token, strlen(token) + 1);
@@ -156,7 +156,7 @@ int logline(char *str, char *ournick, char *basedir, int type) {
if (mkdir(logdir, 0700)) {
debugprint(DEBUG_CRIT, "Error creating log directory '%s.\n", logdir);
printf("Error creating log directory '%s'.\n", logdir);
- exit(1);
+ return 0;
} else {
debugprint(DEBUG_FULL, "logline(): log directory '%s'.\n", logdir);
}
@@ -171,7 +171,8 @@ int logline(char *str, char *ournick, char *basedir, int type) {
if (fp == NULL) {
debugprint(DEBUG_CRIT, "error: could not open log file '%s' for writing.\n", filename);
printf("error: could not open log file '%s' for writing.\n", filename);
- exit(1);
+ fclose(fp);
+ return 0;
}
// Get a current time string to prepend - TODO - Make this customisable.
@@ -188,14 +189,18 @@ int logline(char *str, char *ournick, char *basedir, int type) {
// Prepend the time string and "from" nick
if (!snprintf(line, MAXCHAR, "%s <%s> %s", timestr, tokens[0], str)) {
fprintf(stderr, "Error while preparing log string to write!\n");
- exit(1);
+ debugprint(DEBUG_CRIT, "Error while preparing log string to write!\n");
+ fclose(fp);
+ return 0;
}
} else if (type == LOG_JOINPART || type == LOG_TOPIC) {
// Prepend the time string
char line2[MAXCHAR];
if (!snprintf(line2, MAXCHAR, "%s %s", timestr, line)) {
fprintf(stderr, "Error while preparing log string to write!\n");
- exit(1);
+ debugprint(DEBUG_CRIT, "Error while preparing log string to write!\n");
+ fclose(fp);
+ return 0;
}
// Copy back to line to write
snprintf(line, MAXCHAR, "%s", line2);
@@ -208,9 +213,10 @@ int logline(char *str, char *ournick, char *basedir, int type) {
// Write complete line to file
if ((bytes = fprintf(fp, "%s", line)) < 0) {
- debugprint(DEBUG_CRIT, "error: could not write to log file.\n");
printf("error: could not write to log file.\n");
- exit(1);
+ debugprint(DEBUG_CRIT, "error: could not write to log file.\n");
+ fclose(fp);
+ return 0;
}
fclose(fp);