[PATCH 3/5] batctl: genl_json: don't return negative error codes to main

Sven Eckelmann <[email protected]> Sun, 05 Jul 2026 17:53:37 +0200
Newsgroups org.open-mesh.lists.batman
Message-ID <[email protected]>
handle_json_query() returns the result of netlink_print_query_json()
directly. This is a negative errno code on failure and main() passes it
straight to exit(). The process then terminates with a mangled exit status
like 161 (-95 & 0xff).

Limit the return codes to EXIT_SUCCESS and EXIT_FAILURE.

Fixes: 57cc3c472a7d ("batctl: Introduce handler for JSON_* command types")
Signed-off-by: Sven Eckelmann <[email protected]>
---
 genl_json.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/genl_json.c b/genl_json.c
index 356c5d7..917b255 100644
--- a/genl_json.c
+++ b/genl_json.c
@@ -600,6 +600,8 @@ int handle_json_query(struct state *state, int argc, char **argv)
 	}
 
 	err = netlink_print_query_json(state, json_query);
+	if (err < 0)
+		return EXIT_FAILURE;
 
-	return err;
+	return EXIT_SUCCESS;
 }

-- 
2.47.3