~nloomans/ft_select

61246d56e1967072f9b87a1aa022798468dbba50 — Noah Loomans 1 year, 8 months ago bbfd2f7
always leave terminal in a clean state after receiving signal.

Reference:

Whichever way your program ends, the default configuration of your
terminal MUST be restored.  This is true even after it received a signal
(except for the signals that we cannot intercept, but this would mean
that your program does not work).
1 files changed, 35 insertions(+), 6 deletions(-)

M src/event.c
M src/event.c => src/event.c +35 -6
@@ 1,4 1,4 @@
#include <assert.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdbool.h>
#include <signal.h>


@@ 34,16 34,45 @@ static void						handle_continue(int signum)
	handle_generic(signum);
}

static void						handle_exit_signal(int signum)
{
	terminal_configure(TERMINAL_CONFIGURE_RESTORE);
	ft_dprintf(STDERR_FILENO, "ft_select: received signal sig%s, exiting...\n",
		sys_signame[signum]);
	exit(1);
}

const struct s_event_signal_map	g_event_signal_map[] = {
	[ SIGWINCH ] =
		{ .global = &g_event_sigwinch, .action = action_update_size },
	[ SIGTSTP ] =
		{ .handler = handle_suspend },
	[ SIGCONT ] = {
	[SIGHUP]	= { .handler = handle_exit_signal },
	[SIGINT]	= { .handler = handle_exit_signal },
	[SIGQUIT]	= { .handler = handle_exit_signal },
	[SIGILL]	= { .handler = handle_exit_signal },
	[SIGTRAP]	= { .handler = handle_exit_signal },
	[SIGABRT]	= { .handler = handle_exit_signal },
	[SIGEMT]	= { .handler = handle_exit_signal },
	[SIGFPE]	= { .handler = handle_exit_signal },
	[SIGBUS]	= { .handler = handle_exit_signal },
	[SIGSEGV]	= { .handler = handle_exit_signal },
	[SIGSYS]	= { .handler = handle_exit_signal },
	[SIGPIPE]	= { .handler = handle_exit_signal },
	[SIGALRM]	= { .handler = handle_exit_signal },
	[SIGTERM]	= { .handler = handle_exit_signal },
	[SIGTSTP]	= { .handler = handle_suspend },
	[SIGCONT]	= {
		.handler = handle_continue,
		.global = &g_event_sigcont,
		.action = action_update_size,
	},
	[SIGTTIN]	= { .handler = handle_exit_signal },
	[SIGTTOU]	= { .handler = handle_exit_signal },
	[SIGXCPU]	= { .handler = handle_exit_signal },
	[SIGXFSZ]	= { .handler = handle_exit_signal },
	[SIGVTALRM]	= { .handler = handle_exit_signal },
	[SIGPROF]	= { .handler = handle_exit_signal },
	[SIGWINCH]	= {
		.global = &g_event_sigwinch,
		.action = action_update_size
	},
};

static void						handle_generic(int signum)