Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ static int cmd_break(int argc, char *argv[])
static int cmd_quit(int argc, char *argv[])
{
fflush(NULL);
microcom_exit(0);
exit(0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct? You're commit message implies that exit(0) will somehow call microcom_exit() but when I tested this PR, that is not what happened.
Specifically exiting is not printed when stopping microcom with the quit command.

return 0;
}
Expand Down
41 changes: 18 additions & 23 deletions microcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ static struct termios sots; /* old stdout/in termios settings to restore */
struct ios_ops *ios;
int debug = 0;

int opt_force = 0;
unsigned long current_speed = DEFAULT_BAUDRATE;
int current_flow = FLOW_NONE;
int listenonly = 0;
char escape_char = DEFAULT_ESCAPE_CHAR;

void init_terminal(void)
{
struct termios sts;
Expand Down Expand Up @@ -51,7 +57,8 @@ void microcom_exit(int signal)
write(1, "exiting\n", 8);

ios->exit(ios);
tcsetattr(STDIN_FILENO, TCSANOW, &sots);
if (listenonly)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be if (!listenonly) right? The terminal is configured for !listenonly so it should be restored in that case as well.

tcsetattr(STDIN_FILENO, TCSANOW, &sots);

if (signal)
_Exit(0);
Expand Down Expand Up @@ -96,12 +103,6 @@ void main_usage(int exitcode, char *str, char *dev)
exit(exitcode);
}

int opt_force = 0;
unsigned long current_speed = DEFAULT_BAUDRATE;
int current_flow = FLOW_NONE;
int listenonly = 0;
char escape_char = DEFAULT_ESCAPE_CHAR;

int main(int argc, char *argv[])
{
struct sigaction sact = {0}; /* used to initialize the signal handler */
Expand Down Expand Up @@ -210,7 +211,7 @@ int main(int argc, char *argv[])

ret = ios->set_speed(ios, current_speed);
if (ret)
goto cleanup_ios;
exit(1);

current_flow = FLOW_NONE;
ios->set_flow(ios, current_flow);
Expand All @@ -220,27 +221,21 @@ int main(int argc, char *argv[])
printf("Type the escape character to get to the prompt.\n");

/* Now deal with the local terminal side */
/* microcom_exit will restore the old termios handler */
tcgetattr(STDIN_FILENO, &sots);
init_terminal();

/* set the signal handler to restore the old
* termios handler */
sact.sa_handler = &microcom_exit;
sigaction(SIGHUP, &sact, NULL);
sigaction(SIGINT, &sact, NULL);
sigaction(SIGPIPE, &sact, NULL);
sigaction(SIGTERM, &sact, NULL);
sigaction(SIGQUIT, &sact, NULL);
}

/* run the main program loop */
ret = mux_loop(ios);
sact.sa_handler = &microcom_exit;

if (!listenonly)
tcsetattr(STDIN_FILENO, TCSANOW, &sots);
sigaction(SIGHUP, &sact, NULL);
sigaction(SIGINT, &sact, NULL);
sigaction(SIGPIPE, &sact, NULL);
sigaction(SIGTERM, &sact, NULL);
sigaction(SIGQUIT, &sact, NULL);

cleanup_ios:
ios->exit(ios);
/* run the main program loop */
ret = mux_loop(ios);

exit(ret ? 1 : 0);
}