List Info

Thread: Meaningful non-interactive wpa_cli exit code




Meaningful non-interactive wpa_cli exit code
country flaguser name
United Kingdom
2007-07-18 14:10:24
When you run wpa_cli with an unrecognised command in
non-interactive
mode, e.g. "wpa_cli asdf", you get a zero exit
code.

This patch makes it nonzero for unrecognised commands like
this, to
allow easy detection of failure.

One use of this: It will be possible to easily detect
whether wpa_cli
supports the 'reconnect' command I proposed in another
recent patch, by
detecting the bad exit code (and then a fallback on
reassociate can be
implemented)

---
 wpa_supplicant/wpa_cli.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/wpa_supplicant/wpa_cli.c
b/wpa_supplicant/wpa_cli.c
index 4779a4c..f862aad 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
 -1073,10
+1073,11  static struct wpa_cli_cmd wpa_cli_commands[] = {
 };
 
 
-static void wpa_request(struct wpa_ctrl *ctrl, int argc,
char *argv[])
+static int wpa_request(struct wpa_ctrl *ctrl, int argc,
char *argv[])
 {
 	struct wpa_cli_cmd *cmd, *match = NULL;
 	int count;
+	int ret = 0;
 
 	count = 0;
 	cmd = wpa_cli_commands;
 -1107,9
+1108,12  static void wpa_request(struct wpa_ctrl *ctrl, int
argc, char *argv[])
 		printf("n");
 	} else if (count == 0) {
 		printf("Unknown command '%s'n", argv[0]);
+		ret = 1;
 	} else {
 		match->handler(ctrl, argc - 1, &argv[1]);
 	}
+
+	return ret;
 }
 
 
 -1564,6
+1568,7  int main(int argc, char *argv[])
 	int warning_displayed = 0;
 	int c;
 	int daemonize = 0;
+	int ret = 0;
 	const char *global = NULL;
 
 	if (os_program_init())
 -1675,12
+1680,12  int main(int argc, char *argv[])
 	else if (action_file)
 		wpa_cli_action(ctrl_conn);
 	else
-		wpa_request(ctrl_conn, argc - optind,
&argv[optind]);
+		ret = wpa_request(ctrl_conn, argc - optind,
&argv[optind]);
 
 	os_free(ctrl_ifname);
 	wpa_cli_cleanup();
 
-	return 0;
+	return ret;
 }
 
 #else /* CONFIG_CTRL_IFACE */
-- 
1.5.2.2

_______________________________________________
HostAP mailing list
HostAPshmoo.com
http:/
/lists.shmoo.com/mailman/listinfo/hostap

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )