From: Daniel Drake Date: Mon, 3 Sep 2007 22:37:35 +0000 (-0700) Subject: Meaningful non-interactive wpa_cli exit code X-Git-Url: http://hostap.epitest.fi/gitweb/gitweb.cgi?p=hostap.git;a=commitdiff_plain;h=111c2cecc711fd8fd68fc3822476b7b06025ea15 Meaningful non-interactive wpa_cli exit code 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) --- 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 */