kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit a2d312d0a06f9e7c6e2aec4988809bfab3176e70
parent 52ff37c5be249646b98a02212d3351fde4cac565
Author: Joris Vink <joris@coders.se>
Date:   Thu, 18 Aug 2022 15:20:55 +0200

kore_debug() has been unused for years.

Kill all useless messages, convert useful ones into kore_log() instead.

Diffstat:
Makefile | 2+-
include/kore/kore.h | 11-----------
src/auth.c | 5-----
src/bsd.c | 4----
src/config.c | 2+-
src/connection.c | 28+++-------------------------
src/domain.c | 2--
src/http.c | 34++--------------------------------
src/kore.c | 12++----------
src/linux.c | 21+++------------------
src/module.c | 2--
src/net.c | 20--------------------
src/pool.c | 8+-------
src/tasks.c | 17-----------------
src/tls_openssl.c | 6------
src/utils.c | 44+++++++++++++++++---------------------------
src/websocket.c | 21++++-----------------
src/worker.c | 13++++---------
18 files changed, 38 insertions(+), 214 deletions(-)

diff --git a/Makefile b/Makefile @@ -62,7 +62,7 @@ ifneq ("$(KORE_SINGLE_BINARY)", "") endif ifneq ("$(DEBUG)", "") - CFLAGS+=-DKORE_DEBUG -g + CFLAGS+=-g FEATURES+=-DKORE_DEBUG endif diff --git a/include/kore/kore.h b/include/kore/kore.h @@ -104,14 +104,6 @@ typedef void KORE_PRIVATE_KEY; #define KORE_DHPARAM_PATH PREFIX "/share/kore/ffdhe4096.pem" #define KORE_DEFAULT_CIPHER_LIST "AEAD-AES256-GCM-SHA384:AEAD-CHACHA20-POLY1305-SHA256:AEAD-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256" -#if defined(KORE_DEBUG) -#define kore_debug(...) \ - if (kore_debug) \ - kore_debug_internal(__FILE__, __LINE__, __VA_ARGS__) -#else -#define kore_debug(...) -#endif - #define NETBUF_RECV 0 #define NETBUF_SEND 1 #define NETBUF_SEND_PAYLOAD_MAX 8192 @@ -714,7 +706,6 @@ extern char *config_file; extern pid_t kore_pid; extern int kore_quit; extern int kore_quiet; -extern int kore_debug; extern int skip_chroot; extern int skip_runas; extern int kore_foreground; @@ -927,8 +918,6 @@ void kore_pool_init(struct kore_pool *, const char *, void kore_pool_cleanup(struct kore_pool *); /* utils.c */ -void kore_debug_internal(char *, int, const char *, ...) - __attribute__((format (printf, 3, 4))); void fatal(const char *, ...) __attribute__((noreturn)) __attribute__((format (printf, 1, 2))); void fatalx(const char *, ...) __attribute__((noreturn)) diff --git a/src/auth.c b/src/auth.c @@ -55,8 +55,6 @@ kore_auth_run(struct http_request *req, struct kore_auth *auth) { int r; - kore_debug("kore_auth(%p, %p)", req, auth); - switch (auth->type) { case KORE_AUTH_TYPE_COOKIE: r = kore_auth_cookie(req, auth); @@ -75,7 +73,6 @@ kore_auth_run(struct http_request *req, struct kore_auth *auth) switch (r) { case KORE_RESULT_OK: req->flags |= HTTP_REQUEST_AUTHED; - kore_debug("kore_auth_run() for %s successful", req->path); /* FALLTHROUGH */ case KORE_RESULT_RETRY: return (r); @@ -87,8 +84,6 @@ kore_auth_run(struct http_request *req, struct kore_auth *auth) if (auth->type == KORE_AUTH_TYPE_REQUEST) return (r); - kore_debug("kore_auth_run() for %s failed", req->path); - if (auth->redirect == NULL) { http_response(req, HTTP_STATUS_FORBIDDEN, NULL, 0); return (KORE_RESULT_ERROR); diff --git a/src/bsd.c b/src/bsd.c @@ -54,7 +54,6 @@ kore_platform_init(void) int mib[] = { CTL_HW, HW_NCPU }; if (sysctl(mib, 2, &n, &len, NULL, 0) == -1) { - kore_debug("kore_platform_init(): sysctl %s", errno_s); cpu_count = 1; } else { cpu_count = (u_int16_t)n; @@ -128,9 +127,6 @@ kore_platform_event_wait(u_int64_t timer) fatal("kevent(): %s", errno_s); } - if (n > 0) - kore_debug("main(): %d sockets available", n); - for (i = 0; i < n; i++) { evt = (struct kore_event *)events[i].udata; diff --git a/src/config.c b/src/config.c @@ -1363,7 +1363,7 @@ static int configure_accesslog(char *path) { if (current_domain == NULL) { - kore_debug("accesslog not specified in domain context\n"); + kore_log(LOG_ERR, "accesslog not specified in domain context"); return (KORE_RESULT_ERROR); } diff --git a/src/connection.c b/src/connection.c @@ -47,8 +47,6 @@ kore_connection_init(void) void kore_connection_cleanup(void) { - kore_debug("connection_cleanup()"); - /* Drop all connections */ kore_connection_prune(KORE_CONNECTION_PRUNE_ALL); kore_pool_cleanup(&connection_pool); @@ -102,8 +100,6 @@ kore_connection_accept(struct listener *listener, struct connection **out) struct sockaddr *s; socklen_t len; - kore_debug("kore_connection_accept(%p)", listener); - *out = NULL; c = kore_connection_new(listener); @@ -128,7 +124,6 @@ kore_connection_accept(struct listener *listener, struct connection **out) if ((c->fd = accept(listener->fd, s, &len)) == -1) { kore_pool_put(&connection_pool, c); - kore_debug("accept(): %s", errno_s); return (KORE_RESULT_ERROR); } @@ -225,7 +220,6 @@ void kore_connection_disconnect(struct connection *c) { if (c->state != CONN_STATE_DISCONNECTING) { - kore_debug("preparing %p for disconnection", c); c->state = CONN_STATE_DISCONNECTING; if (c->disconnect) c->disconnect(c); @@ -254,7 +248,6 @@ kore_connection_handle(struct connection *c) { struct listener *listener; - kore_debug("kore_connection_handle(%p) -> %d", c, c->state); kore_connection_stop_idletimer(c); switch (c->state) { @@ -304,7 +297,6 @@ kore_connection_handle(struct connection *c) case CONN_STATE_DISCONNECTING: break; default: - kore_debug("unknown state on %d (%d)", c->fd, c->state); break; } @@ -321,8 +313,6 @@ kore_connection_remove(struct connection *c) struct http_request *req, *rnext; #endif - kore_debug("kore_connection_remove(%p)", c); - kore_tls_connection_cleanup(c); close(c->fd); @@ -370,17 +360,13 @@ kore_connection_check_idletimer(u_int64_t now, struct connection *c) else d = 0; - if (d >= c->idle_timer.length) { - kore_debug("%p idle for %" PRIu64 " ms, expiring", c, d); + if (d >= c->idle_timer.length) kore_connection_disconnect(c); - } } void kore_connection_start_idletimer(struct connection *c) { - kore_debug("kore_connection_start_idletimer(%p)", c); - c->flags |= CONN_IDLE_TIMER_ACT; c->idle_timer.start = kore_time_ms(); } @@ -388,8 +374,6 @@ kore_connection_start_idletimer(struct connection *c) void kore_connection_stop_idletimer(struct connection *c) { - kore_debug("kore_connection_stop_idletimer(%p)", c); - c->flags &= ~CONN_IDLE_TIMER_ACT; c->idle_timer.start = 0; } @@ -399,18 +383,12 @@ kore_connection_nonblock(int fd, int nodelay) { int flags; - kore_debug("kore_connection_nonblock(%d)", fd); - - if ((flags = fcntl(fd, F_GETFL, 0)) == -1) { - kore_debug("fcntl(): F_GETFL %s", errno_s); + if ((flags = fcntl(fd, F_GETFL, 0)) == -1) return (KORE_RESULT_ERROR); - } flags |= O_NONBLOCK; - if (fcntl(fd, F_SETFL, flags) == -1) { - kore_debug("fcntl(): F_SETFL %s", errno_s); + if (fcntl(fd, F_SETFL, flags) == -1) return (KORE_RESULT_ERROR); - } if (nodelay) { if (!kore_sockopt(fd, IPPROTO_TCP, TCP_NODELAY)) { diff --git a/src/domain.c b/src/domain.c @@ -54,8 +54,6 @@ kore_domain_new(const char *domain) { struct kore_domain *dom; - kore_debug("kore_domain_new(%s)", domain); - dom = kore_calloc(1, sizeof(*dom)); dom->id = domain_id++; diff --git a/src/http.c b/src/http.c @@ -286,8 +286,6 @@ void http_request_sleep(struct http_request *req) { if (!(req->flags & HTTP_REQUEST_SLEEPING)) { - kore_debug("http_request_sleep: %p napping", req); - req->flags |= HTTP_REQUEST_SLEEPING; TAILQ_REMOVE(&http_requests, req, list); TAILQ_INSERT_TAIL(&http_requests_sleeping, req, list); @@ -298,8 +296,6 @@ void http_request_wakeup(struct http_request *req) { if (req->flags & HTTP_REQUEST_SLEEPING) { - kore_debug("http_request_wakeup: %p woke up", req); - req->flags &= ~HTTP_REQUEST_SLEEPING; TAILQ_REMOVE(&http_requests_sleeping, req, list); TAILQ_INSERT_TAIL(&http_requests, req, list); @@ -344,9 +340,6 @@ http_process_request(struct http_request *req) { int r; - kore_debug("http_process_request: %p->%p (%s)", - req->owner, req, req->path); - if (req->flags & HTTP_REQUEST_DELETE || req->rt == NULL) return; @@ -404,7 +397,6 @@ http_response_header(struct http_request *req, struct http_header *hdr; hdr = NULL; - kore_debug("http_response_header(%p, %s, %s)", req, header, value); TAILQ_FOREACH(hdr, &req->resp_headers, list) { if (!strcasecmp(hdr->header, header)) { @@ -461,10 +453,8 @@ http_request_free(struct http_request *req) } } - if (pending_tasks) { - kore_debug("http_request_free %d pending tasks", pending_tasks); + if (pending_tasks) return; - } #endif #if defined(KORE_USE_PYTHON) @@ -490,7 +480,6 @@ http_request_free(struct http_request *req) kore_curl_cleanup(client); } #endif - kore_debug("http_request_free: %p->%p", req->owner, req); kore_free(req->headers); req->host = NULL; @@ -601,8 +590,6 @@ http_response(struct http_request *req, int code, const void *d, size_t l) if (req->owner == NULL) return; - kore_debug("%s(%p, %d, %p, %zu)", __func__, req, code, d, l); - req->status = code; switch (req->owner->proto) { @@ -622,8 +609,6 @@ http_response_close(struct http_request *req, int code, const void *d, size_t l) if (req->owner == NULL) return; - kore_debug("%s(%p, %d, %p, %zu)", __func__, req, code, d, l); - req->status = code; req->owner->flags |= CONN_CLOSE_EMPTY; @@ -647,8 +632,6 @@ http_response_json(struct http_request *req, int status, if (req->owner == NULL) return; - kore_debug("%s(%p, %d)", __func__, req, status); - buf = kore_buf_alloc(1024); kore_json_item_tobuf(json, buf); kore_json_item_free(json); @@ -815,7 +798,6 @@ http_header_recv(struct netbuf *nb) char *value, *host, *request[4], *hbuf; c = nb->owner; - kore_debug("http_header_recv(%p)", nb); if (nb->b_len < 4) return (KORE_RESULT_OK); @@ -1038,10 +1020,8 @@ http_argument_urldecode(char *arg) continue; } - if ((p + 2) >= (arg + len)) { - kore_debug("overflow in '%s'", arg); + if ((p + 2) >= (arg + len)) return (KORE_RESULT_ERROR); - } if (!isxdigit((unsigned char)*(p + 1)) || !isxdigit((unsigned char)*(p + 2))) { @@ -1422,9 +1402,6 @@ http_state_run(struct http_state *states, u_int8_t elm, req->fsm_state, elm); } - kore_debug("http_state_run: running %s", - states[req->fsm_state].name); - r = states[req->fsm_state].cb(req); switch (r) { case HTTP_STATE_ERROR: @@ -1442,7 +1419,6 @@ http_state_run(struct http_state *states, u_int8_t elm, } req->fsm_state = 0; - kore_debug("http_state_run(%p): done", req); return (KORE_RESULT_OK); } @@ -1918,9 +1894,6 @@ http_request_new(struct connection *c, const char *host, return (NULL); } - kore_debug("http_request_new(%p, %s, %s, %s, %s)", c, host, - method, path, version); - if (strlen(host) >= KORE_DOMAINNAME_LEN - 1) { http_error_response(c, HTTP_STATUS_BAD_REQUEST); return (NULL); @@ -2234,8 +2207,6 @@ multipart_parse_headers(struct http_request *req, struct kore_buf *in, in, name, fname, boundary, blen); } kore_free(fname); - } else { - kore_debug("got unknown: %s", opt[2]); } kore_free(name); @@ -2402,7 +2373,6 @@ http_body_update(struct http_request *req, const void *data, size_t len) static void http_error_response(struct connection *c, int status) { - kore_debug("http_error_response(%p, %d)", c, status); c->flags |= CONN_CLOSE_EMPTY; switch (c->proto) { diff --git a/src/kore.c b/src/kore.c @@ -56,7 +56,6 @@ u_int8_t nlisteners; int kore_argc = 0; pid_t kore_pid = -1; u_int16_t cpu_count = 1; -int kore_debug = 0; int kore_quiet = 0; int skip_runas = 0; int skip_chroot = 0; @@ -304,9 +303,9 @@ kore_default_getopt(int argc, char **argv) int ch; #if !defined(KORE_SINGLE_BINARY) - while ((ch = getopt(argc, argv, "c:dfhnqrv")) != -1) { + while ((ch = getopt(argc, argv, "c:fhnqrv")) != -1) { #else - while ((ch = getopt(argc, argv, "dfhnqrv")) != -1) { + while ((ch = getopt(argc, argv, "fhnqrv")) != -1) { #endif switch (ch) { #if !defined(KORE_SINGLE_BINARY) @@ -316,11 +315,6 @@ kore_default_getopt(int argc, char **argv) fatal("strdup"); break; #endif -#if defined(KORE_DEBUG) - case 'd': - kore_debug = 1; - break; -#endif case 'f': kore_foreground = 1; break; @@ -353,8 +347,6 @@ kore_server_bind(struct kore_server *srv, const char *ip, const char *port, struct listener *l; struct addrinfo hints, *results; - kore_debug("kore_server_bind(%s, %s, %s)", srv->name, ip, port); - memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; diff --git a/src/linux.c b/src/linux.c @@ -44,7 +44,6 @@ kore_platform_init(void) kore_seccomp_init(); if ((n = sysconf(_SC_NPROCESSORS_ONLN)) == -1) { - kore_debug("could not get number of cpu's falling back to 1"); cpu_count = 1; } else { cpu_count = (u_int16_t)n; @@ -58,12 +57,9 @@ kore_platform_worker_setcpu(struct kore_worker *kw) CPU_ZERO(&cpuset); CPU_SET(kw->cpu, &cpuset); - if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset) == -1) { - kore_debug("kore_worker_setcpu(): %s", errno_s); - } else { - kore_debug("kore_worker_setcpu(): worker %d on cpu %d", - kw->id, kw->cpu); - } + + if (sched_setaffinity(0, sizeof(cpu_set_t), &cpuset) == -1) + kore_log(LOG_WARNING, "kore_worker_setcpu(): %s", errno_s); } void @@ -114,10 +110,6 @@ kore_platform_event_wait(u_int64_t timer) fatal("epoll_wait(): %s", errno_s); } - if (n > 0) { - kore_debug("main(): %d sockets available", n); - } - r = 0; for (i = 0; i < n; i++) { if (events[i].data.ptr == NULL) @@ -165,9 +157,6 @@ kore_platform_event_schedule(int fd, int type, int flags, void *udata) { struct epoll_event evt; - kore_debug("kore_platform_event_schedule(%d, %d, %d, %p)", - fd, type, flags, udata); - evt.events = type; evt.data.ptr = udata; if (epoll_ctl(efd, EPOLL_CTL_ADD, fd, &evt) == -1) { @@ -205,8 +194,6 @@ kore_platform_enable_accept(void) struct listener *l; struct kore_server *srv; - kore_debug("kore_platform_enable_accept()"); - LIST_FOREACH(srv, &kore_servers, list) { LIST_FOREACH(l, &srv->listeners, list) kore_platform_event_schedule(l->fd, EPOLLIN, 0, l); @@ -219,8 +206,6 @@ kore_platform_disable_accept(void) struct listener *l; struct kore_server *srv; - kore_debug("kore_platform_disable_accept()"); - LIST_FOREACH(srv, &kore_servers, list) { LIST_FOREACH(l, &srv->listeners, list) { if (epoll_ctl(efd, EPOLL_CTL_DEL, l->fd, NULL) == -1) { diff --git a/src/module.c b/src/module.c @@ -67,8 +67,6 @@ kore_module_load(const char *path, const char *onload, int type) struct stat st; struct kore_module *module; - kore_debug("kore_module_load(%s, %s)", path, onload); - module = kore_malloc(sizeof(struct kore_module)); module->ocb = NULL; module->type = type; diff --git a/src/net.c b/src/net.c @@ -45,7 +45,6 @@ net_init(void) void net_cleanup(void) { - kore_debug("net_cleanup()"); kore_pool_cleanup(&nb_pool); } @@ -83,8 +82,6 @@ net_send_queue(struct connection *c, const void *data, size_t len) struct netbuf *nb; size_t avail; - kore_debug("net_send_queue(%p, %p, %zu)", c, data, len); - d = data; nb = TAILQ_LAST(&(c->send_queue), netbuf_head); if (nb != NULL && !(nb->flags & NETBUF_IS_STREAM) && @@ -128,8 +125,6 @@ net_send_stream(struct connection *c, void *data, size_t len, { struct netbuf *nb; - kore_debug("net_send_stream(%p, %p, %zu)", c, data, len); - nb = net_netbuf_get(); nb->cb = cb; nb->owner = c; @@ -179,8 +174,6 @@ net_send_fileref(struct connection *c, struct kore_fileref *ref) void net_recv_reset(struct connection *c, size_t len, int (*cb)(struct netbuf *)) { - kore_debug("net_recv_reset(): %p %zu", c, len); - c->rnb->cb = cb; c->rnb->s_off = 0; c->rnb->b_len = len; @@ -198,8 +191,6 @@ void net_recv_queue(struct connection *c, size_t len, int flags, int (*cb)(struct netbuf *)) { - kore_debug("net_recv_queue(): %p %zu %d", c, len, flags); - if (c->rnb != NULL) fatal("net_recv_queue(): called incorrectly"); @@ -216,8 +207,6 @@ net_recv_queue(struct connection *c, size_t len, int flags, void net_recv_expand(struct connection *c, size_t len, int (*cb)(struct netbuf *)) { - kore_debug("net_recv_expand(): %p %d", c, len); - c->rnb->cb = cb; c->rnb->b_len += len; c->rnb->m_len = c->rnb->b_len; @@ -263,8 +252,6 @@ net_send(struct connection *c) int net_send_flush(struct connection *c) { - kore_debug("net_send_flush(%p)", c); - while (!TAILQ_EMPTY(&(c->send_queue)) && (c->evt.flags & KORE_EVENT_WRITE)) { if (!net_send(c)) @@ -283,8 +270,6 @@ net_recv_flush(struct connection *c) { size_t r; - kore_debug("net_recv_flush(%p)", c); - if (c->rnb == NULL) return (KORE_RESULT_OK); @@ -315,13 +300,10 @@ net_recv_flush(struct connection *c) void net_remove_netbuf(struct connection *c, struct netbuf *nb) { - kore_debug("net_remove_netbuf(%p, %p)", c, nb); - if (nb->type == NETBUF_RECV) fatal("net_remove_netbuf(): cannot remove recv netbuf"); if (nb->flags & NETBUF_MUST_RESEND) { - kore_debug("retaining %p (MUST_RESEND)", nb); nb->flags |= NETBUF_FORCE_REMOVE; return; } @@ -355,7 +337,6 @@ net_write(struct connection *c, size_t len, size_t *written) c->evt.flags &= ~KORE_EVENT_WRITE; return (KORE_RESULT_OK); default: - kore_debug("write: %s", errno_s); return (KORE_RESULT_ERROR); } } @@ -381,7 +362,6 @@ net_read(struct connection *c, size_t *bytes) c->evt.flags &= ~KORE_EVENT_READ; return (KORE_RESULT_OK); default: - kore_debug("read(): %s", errno_s); return (KORE_RESULT_ERROR); } } diff --git a/src/pool.c b/src/pool.c @@ -39,8 +39,6 @@ void kore_pool_init(struct kore_pool *pool, const char *name, size_t len, size_t elm) { - kore_debug("kore_pool_init(%p, %s, %zu, %zu)", pool, name, len, elm); - if (elm < POOL_MIN_ELEMENTS) elm = POOL_MIN_ELEMENTS; @@ -92,7 +90,7 @@ kore_pool_get(struct kore_pool *pool) entry = LIST_FIRST(&(pool->freelist)); if (entry->state != POOL_ELEMENT_FREE) - fatal("%s: element %p was not free", pool->name, (void*) entry); + fatal("%s: element %p was not free", pool->name, (void *)entry); LIST_REMOVE(entry, list); entry->state = POOL_ELEMENT_BUSY; @@ -140,8 +138,6 @@ pool_region_create(struct kore_pool *pool, size_t elms) struct kore_pool_region *reg; struct kore_pool_entry *entry; - kore_debug("pool_region_create(%p, %zu)", pool, elms); - if ((reg = calloc(1, sizeof(struct kore_pool_region))) == NULL) fatal("pool_region_create: calloc: %s", errno_s); @@ -175,8 +171,6 @@ pool_region_destroy(struct kore_pool *pool) { struct kore_pool_region *reg; - kore_debug("pool_region_destroy(%p)", pool); - /* Take care iterating when modifying list contents */ while (!LIST_EMPTY(&pool->regions)) { reg = LIST_FIRST(&pool->regions); diff --git a/src/tasks.c b/src/tasks.c @@ -113,8 +113,6 @@ kore_task_run(struct kore_task *t) void kore_task_bind_request(struct kore_task *t, struct http_request *req) { - kore_debug("kore_task_bind_request: %p bound to %p", req, t); - if (t->cb != NULL) fatal("cannot bind cbs and requests at the same time"); @@ -138,8 +136,6 @@ kore_task_bind_callback(struct kore_task *t, void (*cb)(struct kore_task *)) void kore_task_destroy(struct kore_task *t) { - kore_debug("kore_task_destroy: %p", t); - #if !defined(KORE_NO_HTTP) if (t->req != NULL) { t->req = NULL; @@ -172,7 +168,6 @@ kore_task_finished(struct kore_task *t) void kore_task_finish(struct kore_task *t) { - kore_debug("kore_task_finished: %p (%d)", t, t->result); pthread_rwlock_wrlock(&(t->lock)); if (t->fds[1] != -1) { @@ -188,8 +183,6 @@ kore_task_channel_write(struct kore_task *t, void *data, u_int32_t len) { int fd; - kore_debug("kore_task_channel_write: %p <- %p (%ld)", t, data, len); - THREAD_FD_ASSIGN(t->thread->tid, fd, t->fds[1], t->fds[0]); task_channel_write(fd, &len, sizeof(len)); task_channel_write(fd, data, len); @@ -201,8 +194,6 @@ kore_task_channel_read(struct kore_task *t, void *out, u_int32_t len) int fd; u_int32_t dlen, bytes; - kore_debug("kore_task_channel_read: %p -> %p (%ld)", t, out, len); - THREAD_FD_ASSIGN(t->thread->tid, fd, t->fds[1], t->fds[0]); task_channel_read(fd, &dlen, sizeof(dlen)); @@ -221,8 +212,6 @@ kore_task_handle(void *arg, int finished) { struct kore_task *t = arg; - kore_debug("kore_task_handle: %p, %d", t, finished); - #if !defined(KORE_NO_HTTP) if (t->req != NULL) http_request_wakeup(t->req); @@ -350,22 +339,16 @@ task_thread(void *arg) struct kore_task *t; struct kore_task_thread *tt = arg; - kore_debug("task_thread: #%d starting", tt->idx); - pthread_mutex_lock(&(tt->lock)); for (;;) { if (TAILQ_EMPTY(&(tt->tasks))) pthread_cond_wait(&(tt->cond), &(tt->lock)); - kore_debug("task_thread#%d: woke up", tt->idx); - t = TAILQ_FIRST(&(tt->tasks)); TAILQ_REMOVE(&(tt->tasks), t, list); pthread_mutex_unlock(&(tt->lock)); - kore_debug("task_thread#%d: executing %p", tt->idx, t); - kore_task_set_state(t, KORE_TASK_STATE_RUNNING); kore_task_set_result(t, t->entry(t)); kore_task_finish(t); diff --git a/src/tls_openssl.c b/src/tls_openssl.c @@ -207,8 +207,6 @@ kore_tls_domain_setup(struct kore_domain *dom, int type, EC_KEY *eckey; const SSL_METHOD *method; - kore_debug("kore_domain_tlsinit(%s)", dom->domain); - if (dom->tls_ctx != NULL) SSL_CTX_free(dom->tls_ctx); @@ -519,7 +517,6 @@ kore_tls_read(struct connection *c, size_t *bytes) } /* FALLTHROUGH */ default: - kore_debug("SSL_read(): %s", ssl_errno_s); if (c->flags & CONN_LOG_TLS_FAILURE) { kore_log(LOG_NOTICE, "SSL_read(): %s", ssl_errno_s); @@ -568,7 +565,6 @@ kore_tls_write(struct connection *c, size_t len, size_t *written) } /* FALLTHROUGH */ default: - kore_debug("SSL_write(): %s", ssl_errno_s); if (c->flags & CONN_LOG_TLS_FAILURE) { kore_log(LOG_NOTICE, "SSL_write(): %s", ssl_errno_s); @@ -794,7 +790,6 @@ tls_sni_cb(SSL *ssl, int *ad, void *arg) fatal("no connection data in %s", __func__); sname = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name); - kore_debug("kore_tls_sni_cb(): received host %s", sname); if (sname != NULL) c->tls_sni = kore_strdup(sname); @@ -808,7 +803,6 @@ tls_sni_cb(SSL *ssl, int *ad, void *arg) return (SSL_TLSEXT_ERR_NOACK); } - kore_debug("kore_ssl_sni_cb(): Using %s CTX", sname); SSL_set_SSL_CTX(ssl, dom->tls_ctx); if (dom->cafile != NULL) { diff --git a/src/utils.c b/src/utils.c @@ -63,21 +63,6 @@ static char b64url_table[] = \ /* b64_table and b64url_table are the same size. */ #define B64_TABLE_LEN (sizeof(b64_table)) -#if defined(KORE_DEBUG) -void -kore_debug_internal(char *file, int line, const char *fmt, ...) -{ - va_list args; - char buf[2048]; - - va_start(args, fmt); - (void)vsnprintf(buf, sizeof(buf), fmt, args); - va_end(args); - - printf("[%d] %s:%d - %s\n", kore_pid, file, line, buf); -} -#endif - size_t kore_strlcpy(char *dst, const char *src, const size_t len) { @@ -288,7 +273,7 @@ kore_date_to_time(const char *http_date) t = KORE_RESULT_ERROR; if (kore_split_string(sdup, " ", args, 7) != 6) { - kore_debug("misformed http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed http-date: '%s'", http_date); goto out; } @@ -296,7 +281,8 @@ kore_date_to_time(const char *http_date) tm.tm_year = kore_strtonum(args[3], 10, 1900, 2068, &err) - 1900; if (err == KORE_RESULT_ERROR) { - kore_debug("misformed year in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed year in http-date: '%s'", + http_date); goto out; } @@ -308,36 +294,42 @@ kore_date_to_time(const char *http_date) } if (month_names[i].name == NULL) { - kore_debug("misformed month in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed month in http-date: '%s'", + http_date); goto out; } tm.tm_mday = kore_strtonum(args[1], 10, 1, 31, &err); if (err == KORE_RESULT_ERROR) { - kore_debug("misformed mday in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed mday in http-date: '%s'", + http_date); goto out; } if (kore_split_string(args[4], ":", tbuf, 5) != 3) { - kore_debug("misformed HH:MM:SS in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed HH:MM:SS in http-date: '%s'", + http_date); goto out; } tm.tm_hour = kore_strtonum(tbuf[0], 10, 0, 23, &err); if (err == KORE_RESULT_ERROR) { - kore_debug("misformed hour in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed hour in http-date: '%s'", + http_date); goto out; } tm.tm_min = kore_strtonum(tbuf[1], 10, 0, 59, &err); if (err == KORE_RESULT_ERROR) { - kore_debug("misformed minutes in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed minutes in http-date: '%s'", + http_date); goto out; } tm.tm_sec = kore_strtonum(tbuf[2], 10, 0, 60, &err); if (err == KORE_RESULT_ERROR) { - kore_debug("misformed seconds in http-date: '%s'", http_date); + kore_log(LOG_WARNING, "misformed seconds in http-date: '%s'", + http_date); goto out; } @@ -345,7 +337,7 @@ kore_date_to_time(const char *http_date) t = mktime(&tm) + ltm->tm_gmtoff; if (t == -1) { t = 0; - kore_debug("mktime() on '%s' failed", http_date); + kore_log(LOG_WARNING, "mktime() on '%s' failed", http_date); } out: @@ -364,10 +356,8 @@ kore_time_to_date(time_t now) last = now; tm = gmtime(&now); - if (!strftime(tbuf, sizeof(tbuf), "%a, %d %b %Y %T GMT", tm)) { - kore_debug("strftime() gave us NULL (%ld)", now); + if (!strftime(tbuf, sizeof(tbuf), "%a, %d %b %Y %T GMT", tm)) return (NULL); - } } return (tbuf); diff --git a/src/websocket.c b/src/websocket.c @@ -84,7 +84,6 @@ kore_websocket_handshake(struct http_request *req, const char *onconnect, kore_buf_free(buf); if (!kore_base64_encode(digest, sizeof(digest), &base64)) { - kore_debug("failed to base64 encode digest"); http_response(req, HTTP_STATUS_INTERNAL_ERROR, NULL, 0); return; } @@ -94,8 +93,6 @@ kore_websocket_handshake(struct http_request *req, const char *onconnect, http_response_header(req, "sec-websocket-accept", base64); kore_free(base64); - kore_debug("%p: new websocket connection", req->owner); - req->owner->proto = CONN_PROTO_WEBSOCKET; http_response(req, HTTP_STATUS_SWITCHING_PROTOCOLS, NULL, 0); net_recv_reset(req->owner, WEBSOCKET_FRAME_HDR, websocket_recv_opcode); @@ -231,16 +228,12 @@ websocket_recv_opcode(struct netbuf *nb) u_int8_t op, len; struct connection *c = nb->owner; - if (!WEBSOCKET_HAS_MASK(nb->buf[1])) { - kore_debug("%p: frame did not have a mask set", c); + if (!WEBSOCKET_HAS_MASK(nb->buf[1])) return (KORE_RESULT_ERROR); - } if (WEBSOCKET_RSV(nb->buf[0], 1) || WEBSOCKET_RSV(nb->buf[0], 2) || - WEBSOCKET_RSV(nb->buf[0], 3)) { - kore_debug("%p: RSV bits are not zero", c); + WEBSOCKET_RSV(nb->buf[0], 3)) return (KORE_RESULT_ERROR); - } len = WEBSOCKET_FRAME_LENGTH(nb->buf[1]); @@ -254,13 +247,10 @@ websocket_recv_opcode(struct netbuf *nb) case WEBSOCKET_OP_PING: case WEBSOCKET_OP_PONG: if (len > WEBSOCKET_PAYLOAD_SINGLE || - !WEBSOCKET_HAS_FINFLAG(nb->buf[0])) { - kore_debug("%p: large or fragmented control frame", c); + !WEBSOCKET_HAS_FINFLAG(nb->buf[0])) return (KORE_RESULT_ERROR); - } break; default: - kore_debug("%p: bad websocket op %d", c, op); return (KORE_RESULT_ERROR); } @@ -308,10 +298,8 @@ websocket_recv_frame(struct netbuf *nb) break; } - if (len > kore_websocket_maxframe) { - kore_debug("%p: frame too big", c); + if (len > kore_websocket_maxframe) return (KORE_RESULT_ERROR); - } extra += WEBSOCKET_FRAME_HDR; total = len + extra + WEBSOCKET_MASK_LEN; @@ -356,7 +344,6 @@ websocket_recv_frame(struct netbuf *nb) &nb->buf[moff + 4], len); break; default: - kore_debug("%p: bad websocket op %d", c, op); return (KORE_RESULT_ERROR); } diff --git a/src/worker.c b/src/worker.c @@ -132,12 +132,8 @@ kore_worker_init(void) sizeof(*accept_lock)); memset(kore_workers, 0, sizeof(struct kore_worker) * worker_count); - kore_debug("kore_worker_init(): system has %d cpu's", cpu_count); - kore_debug("kore_worker_init(): starting %d workers", worker_count); - - if (worker_count > cpu_count) { - kore_debug("kore_worker_init(): more workers than cpu's"); - } + if (worker_count > cpu_count) + kore_log(LOG_NOTICE, "more worker processes than cpu cores"); /* Setup log buffers. */ for (idx = KORE_WORKER_BASE; idx < worker_count; idx++) { @@ -357,7 +353,8 @@ kore_worker_dispatch_signal(int sig) continue; if (kill(kw->pid, sig) == -1) { - kore_debug("kill(%d, %d): %s", kw->pid, sig, errno_s); + kore_log(LOG_WARNING, "kill(%d, %d): %s", + kw->pid, sig, errno_s); } } } @@ -650,8 +647,6 @@ kore_worker_entry(struct kore_worker *kw) kore_pgsql_sys_cleanup(); #endif - kore_debug("worker %d shutting down", kw->id); - kore_mem_cleanup(); exit(0); }