From 37edefb33fea41cd06073d14c53eece3d1c620af Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 13 Apr 2025 01:19:44 +0900 Subject: [PATCH] socket-proxy: use event_source_hash_ops for managing event sources --- src/socket-proxy/socket-proxyd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/socket-proxy/socket-proxyd.c b/src/socket-proxy/socket-proxyd.c index bf4264a94cc..1428e59a161 100644 --- a/src/socket-proxy/socket-proxyd.c +++ b/src/socket-proxy/socket-proxyd.c @@ -90,7 +90,7 @@ DEFINE_PRIVATE_HASH_OPS_WITH_VALUE_DESTRUCTOR( static void context_done(Context *context) { assert(context); - set_free_with_destructor(context->listen, sd_event_source_unref); + set_free(context->listen); set_free(context->connections); sd_event_unref(context->event); @@ -528,7 +528,6 @@ static int accept_cb(sd_event_source *s, int fd, uint32_t revents, void *userdat } static int add_listen_socket(Context *context, int fd) { - sd_event_source *source; int r; assert(context); @@ -545,16 +544,11 @@ static int add_listen_socket(Context *context, int fd) { if (r < 0) return log_error_errno(r, "Failed to mark file descriptor non-blocking: %m"); + _cleanup_(sd_event_source_unrefp) sd_event_source *source = NULL; r = sd_event_add_io(context->event, &source, fd, EPOLLIN, accept_cb, context); if (r < 0) return log_error_errno(r, "Failed to add event source: %m"); - r = set_ensure_put(&context->listen, NULL, source); - if (r < 0) { - sd_event_source_unref(source); - return log_error_errno(r, "Failed to add source to set: %m"); - } - r = sd_event_source_set_exit_on_failure(source, true); if (r < 0) return log_error_errno(r, "Failed to enable exit-on-failure logic: %m"); @@ -565,6 +559,10 @@ static int add_listen_socket(Context *context, int fd) { if (r < 0) return log_error_errno(r, "Failed to enable oneshot mode: %m"); + r = set_ensure_consume(&context->listen, &event_source_hash_ops, TAKE_PTR(source)); + if (r < 0) + return log_error_errno(r, "Failed to add source to set: %m"); + return 0; } -- 2.47.3