From 322d4afd141f413e242e966202c6653426a3c2d5 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Tue, 31 Aug 2021 15:29:38 +0200 Subject: tools: ipc-modem: Fail if there is no chosen command Without that fix, if some arguments were set and no command was given, ipc-modem would proceed anyway: $ ./tools/ipc-modem --debug [I] Debug enabled [...] As it's expected to at least be used with a command to do something meaningful, without that fix, it could misslead users into thinking that everything is fine when it's not or vice versa. Signed-off-by: Denis 'GNUtoo' Carikli --- tools/ipc-modem.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/ipc-modem.c b/tools/ipc-modem.c index 71031eb..de9910b 100644 --- a/tools/ipc-modem.c +++ b/tools/ipc-modem.c @@ -50,6 +50,7 @@ char call_number[14]; char sim_pin[8]; enum command { + CMD_NONE, CMD_START, CMD_BOOT, CMD_POWER_ON, @@ -553,7 +554,7 @@ modem_quit: int main(int argc, char *argv[]) { - enum command command; + enum command command = CMD_NONE; int c = 0; int opt_i = 0; bool debug = false; @@ -639,5 +640,14 @@ int main(int argc, char *argv[]) optind++; } + if (command == CMD_NONE) { + printf("\n"); + printf("Error: No command given. You need to use a command.\n"); + printf(" See the help below for more details.\n"); + printf("\n"); + print_help(); + return 1; + } + return handle_command(command, debug); } -- cgit v1.2.3