summaryrefslogtreecommitdiff
path: root/blabouncer.c
diff options
context:
space:
mode:
authorLuke Bratch <luke@bratch.co.uk>2019-06-01 19:11:00 +0100
committerLuke Bratch <luke@bratch.co.uk>2019-06-01 19:11:00 +0100
commitc3f421e4046faf8b5f39cd1ad36bc4869405fcc9 (patch)
tree5d2c8575076a82b6ebe518c91fb14a339e92fe7c /blabouncer.c
parent0c153207be8a31fc66b7f6e9d0b849357017e34a (diff)
Put debug logs in subdirectory and have max number to keep be configurable. Also fix possible crash in debugprint() if debug directory doesn't exist yet.
Diffstat (limited to 'blabouncer.c')
-rw-r--r--blabouncer.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/blabouncer.c b/blabouncer.c
index 02c62ad..2410625 100644
--- a/blabouncer.c
+++ b/blabouncer.c
@@ -60,7 +60,6 @@
#define MAXPORTLEN 6 // Up to 65535, so 5 characters + 1 for null
#define MAXAUTOCHANLEN 1024 // Randomly picked maximum length of the auto channel list
#define SERVERTIMEOUT 300 // How many seconds to wait without hearing from the server before assuming a timeout
-#define DEBUGFILESKEEP 5 // How many debug files to keep around
// Global debug control
int debug = 0; // Debug verbosity ("0" for critical only, "1" for some extra info, "2" for full debug mode)
@@ -121,6 +120,7 @@ struct settings {
char basedir[PATH_MAX];
int logging;
int replaylogging;
+ int debugkeep;
int background; // Whether or not we're running in the background (detached from the terminal as a daemon)
};
@@ -2794,27 +2794,45 @@ int main(int argc, char *argv[]) {
// Is replay logging enabled?
settings.replaylogging = getconfint("replaylogging", settings.conffile);
+ // How many debug logs should we keep?
+ settings.debugkeep = getconfint("debugkeep", settings.conffile);
+
// Is debugging enabled?
debug = getconfint("debug", settings.conffile);
- if (!snprintf(debugpath, PATH_MAX, "%s/debug.txt", settings.basedir)) {
+ if (!snprintf(debugpath, PATH_MAX, "%s/debug/debug.txt", settings.basedir)) {
+ fprintf(stderr, "Error while preparing debug path location!\n");
+ exit(1);
+ }
+ // debugfile goes in its own directory
+ char debugdir[PATH_MAX];
+ if (!snprintf(debugdir, PATH_MAX, "%s/debug/", settings.basedir)) {
fprintf(stderr, "Error while preparing debug path location!\n");
exit(1);
}
+ // Make sure the debug directory exists
+ if (stat(debugdir, &st) == -1) {
+ if (mkdir(debugdir, 0700)) {
+ printf("Error creating debug directory '%s'.\n", debugdir);
+ exit(1);
+ } else {
+ printf("Created debug directory '%s'.\n", debugdir);
+ }
+ }
// Prepare the debug file
- // (Keep DEBUGFILESKEEP number of debug files around for past debugging)
- if (DEBUGFILESKEEP > 0) {
+ // (Keep settings.debugkeep number of debug files around for past debugging)
+ if (settings.debugkeep > 0) {
// Check each possible debug file and rename it to one higher
char tmppath[PATH_MAX];
char tmppathnew[PATH_MAX];
// Delete or rename numbered debug files first
- for (int i = DEBUGFILESKEEP; i > 0; i--) {
+ for (int i = settings.debugkeep; i > 0; i--) {
if (!snprintf(tmppath, PATH_MAX - 1, "%s.%d", debugpath, i)) {
fprintf(stderr, "Error while preparing to check old debug files!\n");
exit(1);
}
if (!access(tmppath, F_OK)) {
- if (i == DEBUGFILESKEEP) {
+ if (i == settings.debugkeep) {
if (remove(tmppath)) {
printf("error deleting old debug file '%s'.\n", tmppath);
exit(1);