From 8fb1c09df1540aa3fca1148bed6a08ffc3090669 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 27 Oct 2026 19:15:22 +0100 Subject: All OSes now do have a cheap monotonic clock, so no caching thread is needed. Also add some relative time helpers --- opentracker.c | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) (limited to 'opentracker.c') diff --git a/opentracker.c b/opentracker.c index 11da486..6271b9e 100644 --- a/opentracker.c +++ b/opentracker.c @@ -39,7 +39,6 @@ #include "trackerlogic.h" /* Globals */ -time_t g_now_seconds; uint32_t g_tracker_id; volatile int g_opentracker_running = 1; int g_self_pipe[2]; @@ -203,7 +202,7 @@ static void handle_write(const int64_t sock) { waiting to write and go back to waiting for the next request */ http_interest_drop(sock, cookie, EVENT_OUT); http_interest_add(sock, cookie, EVENT_IN); - fdstate_set_expiry(sock, g_now_seconds + OT_CLIENT_TIMEOUT); + fdstate_set_expiry(sock, time_future_seconds(OT_CLIENT_TIMEOUT)); } else handle_dead(sock); } @@ -226,7 +225,7 @@ static void handle_accept(const int64_t serversocket) { memcpy(cookie->ip, ip, sizeof(ot_ip6)); cookie->interest = EVENT_IN; - if (event_add((int)sock, EVENT_IN, fdstate_open(sock, cookie, g_now_seconds + OT_CLIENT_TIMEOUT)) == -1) { + if (event_add((int)sock, EVENT_IN, fdstate_open(sock, cookie, time_future_seconds(OT_CLIENT_TIMEOUT))) == -1) { fdstate_close(sock); free(cookie); close((int)sock); @@ -242,7 +241,7 @@ static void handle_accept(const int64_t serversocket) { static void *server_mainloop(void *args) { struct ot_workstruct ws; - time_t next_timeout_check = g_now_seconds + OT_CLIENT_TIMEOUT_CHECKINTERVAL; + time_t next_timeout_check = time_future_seconds(OT_CLIENT_TIMEOUT_CHECKINTERVAL); struct iovec *iovector; size_t iovec_entries; int is_partial; @@ -461,17 +460,7 @@ int drop_privileges(const char *const serveruser, const char *const serverdir) { } /* Maintain our copy of the clock. time() on BSDs is very expensive. */ -static void *time_caching_worker(void *args) { - (void)args; - while (1) { - g_now_seconds = time(NULL); - sleep(5); - } - return NULL; -} - int main(int argc, char **argv) { - pthread_t thread_id; /* time cacher */ random_init(); if (fdstate_init() == -1) @@ -492,8 +481,6 @@ int main(int argc, char **argv) { if (drop_privileges(g_serveruser ? g_serveruser : "nobody", g_serverdir) == -1) panic("drop_privileges failed, exiting. Last error"); - g_now_seconds = time(NULL); - pthread_create(&thread_id, NULL, time_caching_worker, NULL); /* Create our self pipe which allows us to interrupt mainloops wait in case some data is available to send out */ -- cgit v1.3