summaryrefslogtreecommitdiffstats
path: root/daemon/worker.c
diff options
context:
space:
mode:
authorOto Šťáva <oto.stava@nic.cz>2024-06-18 17:18:37 +0200
committerOto Šťáva <oto.stava@nic.cz>2024-06-18 17:18:37 +0200
commitead0fed0bce014b5268ce9c67942618c9cc9de6f (patch)
treef9c95454afb6a93ed131f75a57cab31831f803c7 /daemon/worker.c
parentMerge branch 'manager-dir-cleaning' into 'master' (diff)
downloadknot-resolver-ead0fed0bce014b5268ce9c67942618c9cc9de6f.tar.xz
knot-resolver-ead0fed0bce014b5268ce9c67942618c9cc9de6f.zip
daemon: use __attribute__((constructor)) for protolayer_globals
The `protolayer_globals` array can basically be treated as a constant by most of the program and its initialization only uses compile-time-known values. We basically only initialize parts of the array in different files throughout the codebase to maintain separation of concerns, so that each piece of Knot Resolver initializes the part that pertains to it. Therefore, I believe that it is more ergonomic to just use `__attribute__((constructor))` for these functions, so as not to pollute `daemon/main.c` with these calls.
Diffstat (limited to 'daemon/worker.c')
-rw-r--r--daemon/worker.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/daemon/worker.c b/daemon/worker.c
index 562ebf07..2abaee07 100644
--- a/daemon/worker.c
+++ b/daemon/worker.c
@@ -2269,13 +2269,9 @@ static void pl_dns_stream_request_init(struct session2 *session,
req->qsource.comm_flags.tcp = true;
}
-int worker_init(void)
+__attribute__((constructor))
+static void worker_protolayers_init(void)
{
- if (kr_fails_assert(the_worker == NULL))
- return kr_error(EINVAL);
- kr_bindings_register(the_engine->L); // TODO move
-
- /* DNS protocol layers */
protolayer_globals[PROTOLAYER_TYPE_DNS_DGRAM] = (struct protolayer_globals){
.wire_buf_overhead_cb = pl_dns_dgram_wire_buf_overhead,
.wire_buf_max_overhead = KNOT_WIRE_MAX_PKTSIZE,
@@ -2303,6 +2299,13 @@ int worker_init(void)
protolayer_globals[PROTOLAYER_TYPE_DNS_MULTI_STREAM].sess_init = pl_dns_stream_sess_init;
protolayer_globals[PROTOLAYER_TYPE_DNS_SINGLE_STREAM] = stream_common;
protolayer_globals[PROTOLAYER_TYPE_DNS_SINGLE_STREAM].sess_init = pl_dns_single_stream_sess_init;
+}
+
+int worker_init(void)
+{
+ if (kr_fails_assert(the_worker == NULL))
+ return kr_error(EINVAL);
+ kr_bindings_register(the_engine->L); // TODO move
/* Create main worker. */
the_worker = &the_worker_value;