Index: virtual_int.h =================================================================== --- virtual_int.h +++ virtual_int.h @@ -26,6 +26,7 @@ #ifndef _VIRTUAL_INT_H_ #define _VIRTUAL_INT_H_ +#include #include #define VMAX_CHAN 64 @@ -225,6 +226,7 @@ extern char voss_dsp_rx_device[VMAX_STRING]; extern char voss_dsp_tx_device[VMAX_STRING]; extern char voss_ctl_device[VMAX_STRING]; +extern volatile sig_atomic_t voss_exit; extern void atomic_lock(void); extern void atomic_unlock(void); Index: virtual_main.c =================================================================== --- virtual_main.c +++ virtual_main.c @@ -1629,6 +1629,7 @@ uint8_t voss_libsamplerate_quality = SRC_SINC_FASTEST; int voss_is_recording = 1; int voss_has_synchronization; +volatile sig_atomic_t voss_exit = 0; static int voss_dsp_perm = 0666; static int voss_do_background; @@ -1996,6 +1997,12 @@ init_mapping(pvp); } +static void +virtual_sig_exit(int sig) +{ + voss_exit = 1; +} + static const char * parse_options(int narg, char **pparg, int is_main) { @@ -2558,6 +2565,7 @@ } const char *ptrerr; + struct sigaction sa; TAILQ_INIT(&virtual_profile_client_head); TAILQ_INIT(&virtual_profile_loopback_head); @@ -2579,6 +2587,14 @@ signal(SIGPIPE, &virtual_pipe); + memset(&sa, 0, sizeof(sa)); + sigfillset(&sa.sa_mask); + sa.sa_handler = virtual_sig_exit; + if (sigaction(SIGINT, &sa, NULL) < 0) + err(1, "sigaction(SIGINT)"); + if (sigaction(SIGTERM, &sa, NULL) < 0) + err(1, "sigaction(SIGTERM)"); + ptrerr = parse_options(argc, argv, 1); if (ptrerr != NULL) errx(EX_USAGE, "%s", ptrerr); Index: virtual_oss.c =================================================================== --- virtual_oss.c +++ virtual_oss.c @@ -271,6 +271,8 @@ rx_be->close(rx_be); tx_be->close(tx_be); + if (voss_exit) + break; if (need_delay) sleep(2); @@ -337,6 +339,8 @@ uint64_t delta_time; /* Check if DSP device should be re-opened */ + if (voss_exit) + break; if (voss_dsp_rx_refresh || voss_dsp_tx_refresh) { need_delay = false; break; @@ -897,5 +901,13 @@ } } } + + free(buffer_dsp); + free(buffer_temp); + free(buffer_monitor); + free(buffer_local); + free(buffer_data); + free(buffer_orig); + return (NULL); }