Skip to content
Merged
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);
Comment thread
jonrebm marked this conversation as resolved.
Resolved
return 0;
}
Expand Down
64 changes: 38 additions & 26 deletions microcom.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ struct ios_ops *ios;
int debug = 0;
int quiet = 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 @@ -47,17 +53,31 @@ void restore_terminal(void)
}


void microcom_exit(int signal)
static void microcom_exit(int signal)
{
write(1, "exiting\n", 8);
static const char exit_msg[] = "exiting\n";
int ret;

if (!quiet) {
ret = write(STDOUT_FILENO, exit_msg, sizeof(exit_msg) - 1);

/* no error handling in exit handler */
(void)ret;
}

ios->exit(ios);
tcsetattr(STDIN_FILENO, TCSANOW, &sots);
if (!listenonly)
tcsetattr(STDIN_FILENO, TCSANOW, &sots);

if (signal)
_Exit(0);
}

static void atexit_cleanup(void)
{
microcom_exit(0);
}

/*
* Main functions
********************************************************************
Expand Down Expand Up @@ -98,12 +118,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 @@ -214,8 +228,10 @@ int main(int argc, char *argv[])
}

ret = ios->set_speed(ios, current_speed);
if (ret)
goto cleanup_ios;
if (ret) {
ios->exit(ios);
exit(1);
Comment thread
jonrebm marked this conversation as resolved.
Resolved
}

current_flow = FLOW_NONE;
ios->set_flow(ios, current_flow);
Expand All @@ -225,27 +241,23 @@ int main(int argc, char *argv[])
msg_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);
atexit(atexit_cleanup);

/* run the main program loop */
ret = mux_loop(ios);

exit(ret ? 1 : 0);
}
2 changes: 0 additions & 2 deletions microcom.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,6 @@ struct ios_ops *telnet_init(char *hostport);
struct ios_ops *serial_init(char *dev);
struct ios_ops *can_init(char *interfaceid);

void microcom_exit(int signal);

void microcom_cmd_usage(char *str);

void main_usage(int exitcode, char *str, char *dev);
Expand Down
Loading