]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-varlink: unify AF_UNIX check in sd_varlink_set_allow_fd_passing_output()
authorMike Yuan <me@yhndnzj.com>
Mon, 9 Jun 2025 22:01:53 +0000 (00:01 +0200)
committerMike Yuan <me@yhndnzj.com>
Tue, 17 Jun 2025 11:16:43 +0000 (13:16 +0200)
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

index 545311a1182c340eda547d8f26b80c421efb0877..bf764bb97f1652d0aacd496bdfef58fc17f1eff2 100644 (file)
@@ -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) {