From: Mike Yuan Date: Mon, 9 Jun 2025 22:01:53 +0000 (+0200) Subject: sd-varlink: unify AF_UNIX check in sd_varlink_set_allow_fd_passing_output() X-Git-Tag: v258-rc1~301^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=72098df8439411b65ddeeddc1e50c8fb3f06be47;p=thirdparty%2Fsystemd.git 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. --- 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) {