[PATCH 5/6] alfred: Report failure when the client refuses to change interfaces

Sven Eckelmann <[email protected]> Fri, 31 Jul 2026 13:44:54 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
alfred_client_change_interface() and alfred_client_change_bat_iface() open
the connection to the daemon and then an interface that fails the local
checks printed a warning but returned 0. That reported success to the
caller even though nothing was changed and left the connected unix socket
open.

Close the socket and return -1 on these paths so the exit status
reflects that the requested change was rejected.

Fixes: babd772a36e1 ("alfred: support for changing interfaces")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 client.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/client.c b/client.c
index f56042a..d25e3bb 100644
--- a/client.c
+++ b/client.c
@@ -265,7 +265,8 @@ int alfred_client_change_interface(struct globals *globals)
 	if (interface_len >= sizeof(change_interface.ifaces)) {
 		fprintf(stderr, "%s: interface name list too long, not changing\n",
 			__func__);
-		return 0;
+		unix_sock_close(globals);
+		return -1;
 	}
 
 	len = sizeof(change_interface);
@@ -286,8 +287,10 @@ int alfred_client_change_interface(struct globals *globals)
 		input = NULL;
 
 		ret = check_interface(token);
-		if (ret < 0)
-			return 0;
+		if (ret < 0) {
+			unix_sock_close(globals);
+			return -1;
+		}
 	}
 
 	ret = write(globals->unix_sock, &change_interface, len);
@@ -314,7 +317,8 @@ int alfred_client_change_bat_iface(struct globals *globals)
 	if (interface_len >= sizeof(change_bat_iface.bat_iface)) {
 		fprintf(stderr, "%s: batman-adv interface name list too long, not changing\n",
 			__func__);
-		return 0;
+		unix_sock_close(globals);
+		return -1;
 	}
 
 	len = sizeof(change_bat_iface);

-- 
2.47.3