summaryrefslogtreecommitdiff
path: root/sockets.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 /sockets.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 'sockets.c')
-rw-r--r--sockets.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/sockets.c b/sockets.c
index f20b727..4f5be83 100644
--- a/sockets.c
+++ b/sockets.c
@@ -69,6 +69,7 @@ int createclientsocket(char *listenport) {
if ((rv = getaddrinfo(NULL, listenport, &hints, &ai)) != 0) {
fprintf(stderr, "bouncer-client: %s\n", gai_strerror(rv));
+ debugprint(DEBUG_CRIT, "bouncer-client: %s\n", gai_strerror(rv));
exit(1);
}
@@ -105,13 +106,15 @@ int createclientsocket(char *listenport) {
// failed to bind
close(listener);
printf("bouncer-client: failed to bind, exiting...\n");
+ debugprint(DEBUG_CRIT, "bouncer-client: failed to bind, exiting...\n");
exit(1);
}
// if we got here, it means we didn't get bound
if (p == NULL) {
fprintf(stderr, "bouncer-client: failed to bind\n");
- exit(2);
+ debugprint(DEBUG_CRIT, "bouncer-client: failed to bind\n");
+ exit(1);
}
freeaddrinfo(ai); // all done with this
@@ -119,6 +122,7 @@ int createclientsocket(char *listenport) {
// listen
if (listen(listener, BACKLOG) == -1) {
perror("listen");
+ debugprint(DEBUG_CRIT, "bouncer-client failed to listen(), errno '%d'.\n", errno);
exit(1);
}
@@ -151,6 +155,7 @@ SSL_CTX *create_openssl_context(int type) {
if (!ctx) {
perror("Unable to create SSL context");
ERR_print_errors_fp(stderr);
+ debugprint(DEBUG_CRIT, "Unable to create SSL context, errno '%d'.\n", errno);
exit(EXIT_FAILURE);
}
@@ -171,12 +176,14 @@ void configure_openssl_context(SSL_CTX *ctx, char *certfile, char *keyfile) {
if (SSL_CTX_use_certificate_file(ctx, certfile, SSL_FILETYPE_PEM) <= 0) {
ERR_print_errors_fp(stderr);
printf("Couldn't load certificate file '%s'. Hint: You can generate your own with OpenSSL. Once created, set its location in blabouncer.conf which by default is in ~/.blabouncer/.\n", certfile);
+ debugprint(DEBUG_CRIT, "Couldn't load certificate file '%s'. Hint: You can generate your own with OpenSSL. Once created, set its location in blabouncer.conf which by default is in ~/.blabouncer/.\n", certfile);
exit(EXIT_FAILURE);
}
if (SSL_CTX_use_PrivateKey_file(ctx, keyfile, SSL_FILETYPE_PEM) <= 0 ) {
ERR_print_errors_fp(stderr);
printf("Couldn't load key file '%s'. Hint: You can generate your own with OpenSSL. Once created, set its location in blabouncer.conf which by default is in ~/.blabouncer/.\n", keyfile);
+ debugprint(DEBUG_CRIT, "Couldn't load key file '%s'. Hint: You can generate your own with OpenSSL. Once created, set its location in blabouncer.conf which by default is in ~/.blabouncer/.\n", keyfile);
exit(EXIT_FAILURE);
}
}