From 253432c918dacc8bfd5d9a6a46c45a9dc682c7ec Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 3 Nov 2026 02:45:55 +0100 Subject: Give the live sync worker a real workstruct --- src/opentracker.c | 2 +- src/ot_livesync.c | 12 ++++++++---- src/ot_worker.c | 2 +- src/trackerlogic.c | 6 ++++-- src/trackerlogic.h | 2 +- 5 files changed, 15 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/opentracker.c b/src/opentracker.c index 14b817e..60a6d8c 100644 --- a/src/opentracker.c +++ b/src/opentracker.c @@ -109,7 +109,7 @@ static void *server_mainloop(void *args) { (void)args; - if (workstruct_init(&ws) == -1) + if (workstruct_init(&ws, G_INBUF_SIZE) == -1) panic("Initializing worker failed"); while (g_opentracker_running) { diff --git a/src/ot_livesync.c b/src/ot_livesync.c index 083fe1a..18dae0d 100644 --- a/src/ot_livesync.c +++ b/src/ot_livesync.c @@ -4,6 +4,7 @@ /* System */ #include #include +#include #include #include #include @@ -200,9 +201,12 @@ static void *livesync_worker(void *args) { (void)args; - /* Initialize our "thread local storage" */ - ws.inbuf = ws.request = malloc(LIVESYNC_INCOMING_BUFFSIZE); - ws.outbuf = ws.reply = 0; + if (workstruct_init(&ws, LIVESYNC_INCOMING_BUFFSIZE) == -1) { + fprintf(stderr, "Warning: live sync could not get its buffers and will not run.\n"); + atomic_store(&thread_left, 1); + return NULL; + } + ws.request = ws.inbuf; while (g_opentracker_running) { uint32_t packet_type; @@ -233,7 +237,7 @@ static void *livesync_worker(void *args) { } } - free(ws.inbuf); + workstruct_deinit(&ws); atomic_store(&thread_left, 1); return NULL; } diff --git a/src/ot_worker.c b/src/ot_worker.c index 432d272..ef50945 100644 --- a/src/ot_worker.c +++ b/src/ot_worker.c @@ -20,7 +20,7 @@ static size_t g_worker_count; static void *worker_trampoline(void *args) { struct ot_worker *me = args; - if (workstruct_init(&me->ws) == -1) + if (workstruct_init(&me->ws, G_INBUF_SIZE) == -1) fprintf(stderr, "Warning: a worker could not get its buffers and will not run.\n"); else { me->run(me); diff --git a/src/trackerlogic.c b/src/trackerlogic.c index 9565090..8e30a48 100644 --- a/src/trackerlogic.c +++ b/src/trackerlogic.c @@ -567,9 +567,11 @@ void trackerlogic_init(void) { stats_init(); } -int workstruct_init(struct ot_workstruct *ws) { +/* Live sync reads whole packets rather than requests and wants a larger + inbuf than the request path does, hence the size. */ +int workstruct_init(struct ot_workstruct *ws, size_t inbuf_size) { memset(ws, 0, sizeof(*ws)); - ws->inbuf = malloc(G_INBUF_SIZE); + ws->inbuf = malloc(inbuf_size); ws->outbuf = malloc(G_OUTBUF_SIZE); #ifdef _DEBUG_HTTPERROR ws->debugbuf = malloc(G_DEBUGBUF_SIZE); diff --git a/src/trackerlogic.h b/src/trackerlogic.h index 7292d36..692b6af 100644 --- a/src/trackerlogic.h +++ b/src/trackerlogic.h @@ -242,7 +242,7 @@ struct ot_workstruct { /* Everything a thread that serves requests needs for itself. Set up and torn down in one place so that a new kind of worker cannot miss a piece. Returns -1 if the buffers could not be had. */ -int workstruct_init(struct ot_workstruct *ws); +int workstruct_init(struct ot_workstruct *ws, size_t inbuf_size); void workstruct_deinit(struct ot_workstruct *ws); /* -- cgit v1.3