diff options
author | Luke Bratch <luke@bratch.co.uk> | 2019-06-01 19:22:13 +0100 |
---|---|---|
committer | Luke Bratch <luke@bratch.co.uk> | 2019-06-01 19:22:13 +0100 |
commit | d38794635a763174d62790cf350ee5665737c6ef (patch) | |
tree | 77068c5eca225e658baea54ff2a833b05f7c9ece | |
parent | c3f421e4046faf8b5f39cd1ad36bc4869405fcc9 (diff) |
Use errno to handle getconfint() failing.
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | blabouncer.c | 30 | ||||
-rw-r--r-- | config.c | 4 | ||||
-rw-r--r-- | config.h | 2 |
4 files changed, 35 insertions, 3 deletions
@@ -8,5 +8,3 @@ Add various auto replay options: Might need to #include <limits.h> in blabouncer.c to make some operating systems and/or compilers happy. Send a PING to the server before assuming a timeout is definite. - -Use errno to handle getconfint() failing. diff --git a/blabouncer.c b/blabouncer.c index 2410625..0347ec7 100644 --- a/blabouncer.c +++ b/blabouncer.c @@ -38,6 +38,7 @@ #define DEBUG_CRIT 0 #define DEBUG_SOME 1 #define DEBUG_FULL 2 +#define ECONFINT 1 // errno value if getconfint() failed #define STDIN 0 // stdin is fd 0 #define SIGINT 2 // SIGINT is signal 2 @@ -2688,6 +2689,11 @@ int main(int argc, char *argv[]) { // How many seconds of replay log should automatically be replayed - TODO - Can we do error checking on this? settings.replayseconds = getconfint("replayseconds", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'replayseconds' from configuration file.\n"); + exit(1); + } + // What port should the bouncer listen on if (!getconfstr("clientport", settings.conffile, settings.clientport)) { printf("main(): error getting 'clientport' from configuration file.\n"); @@ -2752,9 +2758,17 @@ int main(int argc, char *argv[]) { // Should the bouncer use TLS for the IRC server? settings.servertls = getconfint("servertls", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'servertls' from configuration file.\n"); + exit(1); + } // Should the bouncer use TLS for clients? settings.clienttls = getconfint("clienttls", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'clienttls' from configuration file.\n"); + exit(1); + } // If so, load the certificates if (settings.clienttls) { @@ -2790,15 +2804,31 @@ int main(int argc, char *argv[]) { // Is logging enabled? settings.logging = getconfint("logging", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'logging' from configuration file.\n"); + exit(1); + } // Is replay logging enabled? settings.replaylogging = getconfint("replaylogging", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'replaylogging' from configuration file.\n"); + exit(1); + } // How many debug logs should we keep? settings.debugkeep = getconfint("debugkeep", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'debugkeep' from configuration file.\n"); + exit(1); + } // Is debugging enabled? debug = getconfint("debug", settings.conffile); + if (errno == ECONFINT) { + printf("main(): error getting 'debug' from configuration file.\n"); + exit(1); + } if (!snprintf(debugpath, PATH_MAX, "%s/debug/debug.txt", settings.basedir)) { fprintf(stderr, "Error while preparing debug path location!\n"); exit(1); @@ -91,11 +91,13 @@ int getconfstr(char *confname, char *filename, char* dest) { // Returns the value of the configuration option with name // 'confname' from configuration file 'filename'. +// Sets errno to 0 on success, or ECONFINT if it fails, in which case the return value is undefined. int getconfint(char *confname, char *filename) { + errno = 0; char result[MAXCHAR]; if (!getconfstr(confname, filename, result)) { - printf("getconfint(): error getting configuration option '%s' from configuration file '%s'.\n", confname, filename); debugprint(DEBUG_CRIT, "getconfint(): error getting configuration option '%s' from configuration file '%s'.\n", confname, filename); + errno = ECONFINT; } return strtol(result, NULL, 10); // Convert resulting string to an integer, base 10 @@ -13,6 +13,7 @@ #define DEBUG_CRIT 0 #define DEBUG_SOME 1 #define DEBUG_FULL 2 +#define ECONFINT 1 // errno value if getconfint() failed #define MAXCHAR 1000 @@ -24,6 +25,7 @@ int getconfstr(char *confname, char *filename, char* dest); // Returns the avlue of the configuration option with name // 'confname' from configuration file 'filename'. +// Sets errno to 0 on success, or ECONFINT if it fails, in which case the return value is undefined. int getconfint(char *confname, char *filename); // Check the password provided in the string 'str' against what is in |