From 72098df8439411b65ddeeddc1e50c8fb3f06be47 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Tue, 10 Jun 2025 00:01:53 +0200 Subject: [PATCH] sd-varlink: unify AF_UNIX check in sd_varlink_set_allow_fd_passing_output() Currently, the socket type is only checked if the fd passing is being enabled. The special handling seems unnecessary though, as in the disable case, either fd passing is already false and would be caught by the (... == !!b) shortcut at the beginning, or the AF_UNIX check wouldn't have succeeded in the first place, for the initial toggle to true. Hence, just uniformly check AF_UNIX. While at it, sd_varlink_set_allow_fd_passing_*() oddly return 1 iff changed and !b, which doesn't fit into our coding style and I can't come up with any use case for such behavior. Let's return 1 on changed and 0 otherwise. sd_varlink_set_allow_fd_passing_input() will be fixed in the later commits with other enhancements. --- src/libsystemd/sd-varlink/sd-varlink.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/libsystemd/sd-varlink/sd-varlink.c b/src/libsystemd/sd-varlink/sd-varlink.c index 545311a1182..bf764bb97f1 100644 --- a/src/libsystemd/sd-varlink/sd-varlink.c +++ b/src/libsystemd/sd-varlink/sd-varlink.c @@ -3271,17 +3271,12 @@ _public_ int sd_varlink_set_allow_fd_passing_output(sd_varlink *v, int b) { if (v->allow_fd_passing_output == !!b) return 0; - if (!b) { - v->allow_fd_passing_output = false; - return 1; - } - r = verify_unix_socket(v); if (r < 0) return r; - v->allow_fd_passing_output = true; - return 0; + v->allow_fd_passing_output = !!b; + return 1; } _public_ int sd_varlink_set_input_sensitive(sd_varlink *v) { -- 2.47.3