system/cu: do not exit directly from getopt loop, bad in flat builds

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
Juha Niskanen 2020-10-19 18:43:09 +03:00 committed by Xiang Xiao
parent 8375a2177e
commit a20cf0980d
2 changed files with 24 additions and 12 deletions

View File

@ -49,7 +49,8 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ***********************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE #ifndef CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE
# define CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE "/dev/ttyS0" # define CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE "/dev/ttyS0"

View File

@ -214,7 +214,7 @@ errout:
return rc; return rc;
} }
static int retrive_termios(int fd) static int retrieve_termios(int fd)
{ {
tcsetattr(fd, TCSANOW, &g_tio_dev); tcsetattr(fd, TCSANOW, &g_tio_dev);
if (fd_std_tty >= 0) if (fd_std_tty >= 0)
@ -241,10 +241,11 @@ static void print_help(void)
" -?: This help\n", " -?: This help\n",
#ifdef CONFIG_SERIAL_TERMIOS #ifdef CONFIG_SERIAL_TERMIOS
CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE, CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE,
CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD); CONFIG_SYSTEM_CUTERM_DEFAULT_BAUD
#else #else
CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE); CONFIG_SYSTEM_CUTERM_DEFAULT_DEVICE
#endif #endif
);
} }
static void print_escape_help(void) static void print_escape_help(void)
@ -300,6 +301,7 @@ int main(int argc, FAR char *argv[])
int bcmd; int bcmd;
int start_of_line = 1; int start_of_line = 1;
int exitval = EXIT_FAILURE; int exitval = EXIT_FAILURE;
bool badarg = false;
/* Initialize global data */ /* Initialize global data */
@ -349,13 +351,22 @@ int main(int argc, FAR char *argv[])
case 'h': case 'h':
case '?': case '?':
print_help(); print_help();
return EXIT_SUCCESS; badarg = true;
exitval = EXIT_SUCCESS;
break;
default: default:
return EXIT_FAILURE; badarg = true;
exitval = EXIT_FAILURE;
break;
} }
} }
if (badarg)
{
return exitval;
}
/* Open the serial device for writing */ /* Open the serial device for writing */
g_cu.outfd = open(devname, O_WRONLY); g_cu.outfd = open(devname, O_WRONLY);
@ -435,6 +446,7 @@ int main(int argc, FAR char *argv[])
ret = pthread_create(&g_cu.listener, &attr, ret = pthread_create(&g_cu.listener, &attr,
cu_listener, (pthread_addr_t)0); cu_listener, (pthread_addr_t)0);
pthread_attr_destroy(&attr);
if (ret != 0) if (ret != 0)
{ {
fprintf(stderr, "cu_main: Error in thread creation: %d\n", ret); fprintf(stderr, "cu_main: Error in thread creation: %d\n", ret);
@ -499,7 +511,6 @@ int main(int argc, FAR char *argv[])
} }
pthread_cancel(g_cu.listener); pthread_cancel(g_cu.listener);
pthread_attr_destroy(&attr);
exitval = EXIT_SUCCESS; exitval = EXIT_SUCCESS;
/* Error exits */ /* Error exits */
@ -508,7 +519,7 @@ errout_with_fds:
close(g_cu.infd); close(g_cu.infd);
#ifdef CONFIG_SERIAL_TERMIOS #ifdef CONFIG_SERIAL_TERMIOS
errout_with_outfd_retrieve: errout_with_outfd_retrieve:
retrive_termios(g_cu.outfd); retrieve_termios(g_cu.outfd);
#endif #endif
errout_with_outfd: errout_with_outfd:
close(g_cu.outfd); close(g_cu.outfd);