summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUwe Kleine-König <uwe@kleine-koenig.org>2020-09-18 22:55:37 +0200
committerUwe Kleine-König <uwe@kleine-koenig.org>2020-09-18 22:55:37 +0200
commit596b478f82d9b920f0ed5f886b21225186ca1820 (patch)
tree7ec802513f74748aa1b957cb8bd3076d3c684044
parent780a6f94c4fee3bcfc2e3b06c757d0ce88945cfc (diff)
downloadmicrocom-596b478f82d9b920f0ed5f886b21225186ca1820.tar.gz
microcom-596b478f82d9b920f0ed5f886b21225186ca1820.tar.xz
Properly cleanup after failure to set speed
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 <uwe@kleine-koenig.org>
-rw-r--r--microcom.c12
1 files 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);
}