From 596b478f82d9b920f0ed5f886b21225186ca1820 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 18 Sep 2020 22:55:37 +0200 Subject: Properly cleanup after failure to set speed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After failure to set the speed, exit() was called without calling ios->exit() which results in the lock file not being removed. In this case restoring the terminal attributes must not be done as sots isn't initialized yet, so swap the order of terminal restoring and ios cleanup. Signed-off-by: Uwe Kleine-König --- microcom.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/microcom.c b/microcom.c index 1218ec4..d4b1815 100644 --- a/microcom.c +++ b/microcom.c @@ -302,10 +302,11 @@ int main(int argc, char *argv[]) exit(1); } - current_flow = FLOW_NONE; - if (ios->set_speed(ios, current_speed)) - exit(EXIT_FAILURE); + ret = ios->set_speed(ios, current_speed); + if (ret) + goto cleanup_ios; + current_flow = FLOW_NONE; ios->set_flow(ios, current_flow); if (!listenonly) { @@ -329,10 +330,11 @@ int main(int argc, char *argv[]) /* run the main program loop */ ret = mux_loop(ios); - ios->exit(ios); - if (!listenonly) tcsetattr(STDIN_FILENO, TCSANOW, &sots); +cleanup_ios: + ios->exit(ios); + exit(ret ? 1 : 0); } -- cgit v1.2.3 From 472597ccbc83ad5268b8a973a84bdfe5cf3457f0 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Fri, 18 Sep 2020 22:58:16 +0200 Subject: Don't use plain 0 as NULL pointer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes several warnings à la: microcom.c:214:40: warning: Using plain integer as NULL pointer Signed-off-by: Uwe Kleine-König --- microcom.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/microcom.c b/microcom.c index d4b1815..5bda7b4 100644 --- a/microcom.c +++ b/microcom.c @@ -211,18 +211,18 @@ int main(int argc, char *argv[]) char *logfile = NULL; struct option long_options[] = { - { "help", no_argument, 0, 'h' }, - { "port", required_argument, 0, 'p'}, - { "speed", required_argument, 0, 's'}, - { "telnet", required_argument, 0, 't'}, - { "can", required_argument, 0, 'c'}, - { "debug", no_argument, 0, 'd' }, - { "force", no_argument, 0, 'f' }, - { "logfile", required_argument, 0, 'l'}, - { "listenonly", no_argument, 0, 'o'}, - { "answerback", required_argument, 0, 'a'}, - { "version", no_argument, 0, 'v' }, - { 0, 0, 0, 0}, + { "help", no_argument, NULL, 'h' }, + { "port", required_argument, NULL, 'p'}, + { "speed", required_argument, NULL, 's'}, + { "telnet", required_argument, NULL, 't'}, + { "can", required_argument, NULL, 'c'}, + { "debug", no_argument, NULL, 'd' }, + { "force", no_argument, NULL, 'f' }, + { "logfile", required_argument, NULL, 'l'}, + { "listenonly", no_argument, NULL, 'o'}, + { "answerback", required_argument, NULL, 'a'}, + { "version", no_argument, NULL, 'v' }, + { }, }; while ((opt = getopt_long(argc, argv, "hp:s:t:c:dfl:oi:a:v", long_options, NULL)) != -1) { -- cgit v1.2.3