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);
Comment thread
jonrebm marked this conversation as resolved.
return 0;
}
Expand Down
56 changes: 31 additions & 25 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,27 @@ 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";

if (write(STDOUT_FILENO, exit_msg, sizeof(exit_msg) - 1) < 0) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this to avoid a warning about ignoring the return value? or why is this here?

(void)write(...); is the typical way to handle that, I think.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, for compiler and reader to see that error checking is omitted purposely. I thought that it looked better this way but I'll change it given you find that more idiomatic.

/* couldn't write message but already exiting */
}

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 +114,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 @@ -216,7 +226,7 @@ int main(int argc, char *argv[])

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is before atexit() is configured. Don't you need to call at least ios->exit(ios); here?


current_flow = FLOW_NONE;
ios->set_flow(ios, current_flow);
Expand All @@ -226,27 +236,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