summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO2
-rw-r--r--blabouncer.c30
-rw-r--r--config.c4
-rw-r--r--config.h2
4 files changed, 35 insertions, 3 deletions
diff --git a/TODO b/TODO
index 5b78261..ead2645 100644
--- a/TODO
+++ b/TODO
@@ -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);
diff --git a/config.c b/config.c
index 41f07d6..ad7e31c 100644
--- a/config.c
+++ b/config.c
@@ -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
diff --git a/config.h b/config.h
index c997750..ce80177 100644
--- a/config.h
+++ b/config.h
@@ -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