From: Lennart Poettering Date: Wed, 13 Dec 2023 17:19:42 +0000 (+0100) Subject: userbd: modernize process_connection() fd possession logic X-Git-Tag: v256-rc1~1492^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=523121d543bb1f32dca48d62e1a88cc204e5bb96;p=thirdparty%2Fsystemd.git userbd: modernize process_connection() fd possession logic --- diff --git a/src/userdb/userwork.c b/src/userdb/userwork.c index b5b76c51e19..fa7c2dd3195 100644 --- a/src/userdb/userwork.c +++ b/src/userdb/userwork.c @@ -425,16 +425,16 @@ static int vl_method_get_memberships(Varlink *link, JsonVariant *parameters, Var JSON_BUILD_PAIR("groupName", JSON_BUILD_STRING(last_group_name)))); } -static int process_connection(VarlinkServer *server, int fd) { +static int process_connection(VarlinkServer *server, int _fd) { + _cleanup_close_ int fd = TAKE_FD(_fd); /* always take possesion */ _cleanup_(varlink_close_unrefp) Varlink *vl = NULL; int r; r = varlink_server_add_connection(server, fd, &vl); - if (r < 0) { - fd = safe_close(fd); + if (r < 0) return log_error_errno(r, "Failed to add connection: %m"); - } + TAKE_FD(fd); vl = varlink_ref(vl); for (;;) {