Add global error handling

This commit is contained in:
2023-01-09 00:28:12 +01:00
parent 7f7a07c4d2
commit c36ad8c113
13 changed files with 181 additions and 105 deletions

View File

@ -75,7 +75,6 @@ static int request_handler(client_ctx_t *ctx) {
sock *client = &ctx->socket;
char *err_msg = ctx->err_msg;
http_res *res = &ctx->res;
http_status_ctx *status = &ctx->status;
long ret;
char buf0[1024], buf1[1024];
@ -353,7 +352,7 @@ int respond(client_ctx_t *ctx) {
if (ctx->msg_buf != NULL) {
ret = sock_send(client, ctx->msg_buf, ctx->content_length, 0);
if (ret <= 0) {
error("Unable to send: %s", sock_strerror(client));
error("Unable to send");
}
} else if (ctx->file != NULL) {
unsigned long len, snd_len = 0;
@ -364,7 +363,7 @@ int respond(client_ctx_t *ctx) {
}
ret = sock_send(client, buffer, len, feof(ctx->file) ? 0 : MSG_MORE);
if (ret <= 0) {
error("Unable to send: %s", sock_strerror(client));
error("Unable to send");
break;
}
snd_len += ret;

View File

@ -12,6 +12,7 @@
#include "../lib/geoip.h"
#include "../workers.h"
#include "../server.h"
#include "../lib/error.h"
#include <string.h>
#include <errno.h>
@ -63,7 +64,7 @@ static int tcp_acceptor(client_ctx_t *ctx) {
sprintf(buf, "dig @%s +short +time=1 -x %s", config.dns_server, ctx->socket.addr);
FILE *dig = popen(buf, "r");
if (dig == NULL) {
error("Unable to start dig: %s", strerror(errno));
error("Unable to start dig: %s");
goto dig_err;
}
unsigned long read = fread(buf, 1, sizeof(buf), dig);
@ -101,11 +102,9 @@ static int tcp_acceptor(client_ctx_t *ctx) {
SSL_set_accept_state(client->ssl);
ret = SSL_accept(client->ssl);
client->_last_ret = ret;
client->_errno = errno;
client->_ssl_error = ERR_get_error();
if (ret <= 0) {
info("Unable to perform handshake: %s", sock_strerror(client));
if (ret != 1) {
error_ssl(SSL_get_error(client->ssl, ret));
info("Unable to perform handshake");
return - 1;
}
client->ts_last = clock_micros();