From d373ec5f7908419c871e1250ec59cfbd5d8e5f94 Mon Sep 17 00:00:00 2001 From: schwarze Date: Thu, 2 Sep 2021 11:19:02 +0000 Subject: [PATCH] Make all signal handler functions async-signal-safe by deleting the redundant "killersig" struct member and using the existing sig_atomic_t cl_sigterm variable instead. While here, garbage collect the h_hup() signal handler which is essentially identical to h_term(). This also gets rid of the last #define & #undef in cl_main.c. OK martijn@, and also tested by Tim . --- usr.bin/vi/cl/cl.h | 4 +--- usr.bin/vi/cl/cl_funcs.c | 6 +++--- usr.bin/vi/cl/cl_main.c | 31 +++++++------------------------ usr.bin/vi/cl/cl_read.c | 10 ++++++---- 4 files changed, 17 insertions(+), 34 deletions(-) diff --git a/usr.bin/vi/cl/cl.h b/usr.bin/vi/cl/cl.h index bfef0dc225a..8613313a0a5 100644 --- a/usr.bin/vi/cl/cl.h +++ b/usr.bin/vi/cl/cl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cl.h,v 1.11 2021/09/01 14:28:15 schwarze Exp $ */ +/* $OpenBSD: cl.h,v 1.12 2021/09/02 11:19:02 schwarze Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -11,7 +11,6 @@ * @(#)cl.h 10.19 (Berkeley) 9/24/96 */ -extern volatile sig_atomic_t cl_sighup; extern volatile sig_atomic_t cl_sigint; extern volatile sig_atomic_t cl_sigterm; extern volatile sig_atomic_t cl_sigwinch; @@ -31,7 +30,6 @@ typedef struct _cl_private { char *rmso, *smso; /* Inverse video terminal strings. */ char *smcup, *rmcup; /* Terminal start/stop strings. */ - int killersig; /* Killer signal. */ #define INDX_HUP 0 #define INDX_INT 1 #define INDX_TERM 2 diff --git a/usr.bin/vi/cl/cl_funcs.c b/usr.bin/vi/cl/cl_funcs.c index eeb6046358f..24b18c675bf 100644 --- a/usr.bin/vi/cl/cl_funcs.c +++ b/usr.bin/vi/cl/cl_funcs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_funcs.c,v 1.21 2021/09/01 14:28:15 schwarze Exp $ */ +/* $OpenBSD: cl_funcs.c,v 1.22 2021/09/02 11:19:02 schwarze Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -437,7 +437,7 @@ cl_refresh(SCR *sp, int repaint) * If we received a killer signal, we're done, there's no point * in refreshing the screen. */ - if (clp->killersig) + if (cl_sigterm) return (0); /* @@ -582,7 +582,7 @@ cl_suspend(SCR *sp, int *allowedp) * unchanged. In addition, the terminal has already been reset * correctly, so leave it alone. */ - if (clp->killersig) { + if (cl_sigterm) { F_CLR(clp, CL_SCR_EX_INIT | CL_SCR_VI_INIT); return (0); } diff --git a/usr.bin/vi/cl/cl_main.c b/usr.bin/vi/cl/cl_main.c index 4cd624e72bf..5c38139c76d 100644 --- a/usr.bin/vi/cl/cl_main.c +++ b/usr.bin/vi/cl/cl_main.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_main.c,v 1.34 2021/09/01 14:28:15 schwarze Exp $ */ +/* $OpenBSD: cl_main.c,v 1.35 2021/09/02 11:19:02 schwarze Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -33,7 +33,6 @@ GS *__global_list; /* GLOBAL: List of screens. */ -volatile sig_atomic_t cl_sighup; volatile sig_atomic_t cl_sigint; volatile sig_atomic_t cl_sigterm; volatile sig_atomic_t cl_sigwinch; @@ -120,9 +119,9 @@ main(int argc, char *argv[]) } /* If a killer signal arrived, pretend we just got it. */ - if (clp->killersig) { - (void)signal(clp->killersig, SIG_DFL); - (void)kill(getpid(), clp->killersig); + if (cl_sigterm) { + (void)signal(cl_sigterm, SIG_DFL); + (void)kill(getpid(), cl_sigterm); /* NOTREACHED */ } @@ -215,17 +214,6 @@ term_init(char *ttype) } } -#define GLOBAL_CLP \ - CL_PRIVATE *clp = GCLP(__global_list); -static void -h_hup(int signo) -{ - GLOBAL_CLP; - - cl_sighup = 1; - clp->killersig = SIGHUP; -} - static void h_int(int signo) { @@ -235,10 +223,7 @@ h_int(int signo) static void h_term(int signo) { - GLOBAL_CLP; - - cl_sigterm = 1; - clp->killersig = SIGTERM; + cl_sigterm = signo; } static void @@ -246,7 +231,6 @@ h_winch(int signo) { cl_sigwinch = 1; } -#undef GLOBAL_CLP /* * sig_init -- @@ -261,20 +245,19 @@ sig_init(GS *gp, SCR *sp) clp = GCLP(gp); - cl_sighup = 0; cl_sigint = 0; cl_sigterm = 0; cl_sigwinch = 0; if (sp == NULL) { - if (setsig(SIGHUP, &clp->oact[INDX_HUP], h_hup) || + if (setsig(SIGHUP, &clp->oact[INDX_HUP], h_term) || setsig(SIGINT, &clp->oact[INDX_INT], h_int) || setsig(SIGTERM, &clp->oact[INDX_TERM], h_term) || setsig(SIGWINCH, &clp->oact[INDX_WINCH], h_winch) ) err(1, NULL); } else - if (setsig(SIGHUP, NULL, h_hup) || + if (setsig(SIGHUP, NULL, h_term) || setsig(SIGINT, NULL, h_int) || setsig(SIGTERM, NULL, h_term) || setsig(SIGWINCH, NULL, h_winch) diff --git a/usr.bin/vi/cl/cl_read.c b/usr.bin/vi/cl/cl_read.c index aa3e1ba0dd4..0e4166aa146 100644 --- a/usr.bin/vi/cl/cl_read.c +++ b/usr.bin/vi/cl/cl_read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cl_read.c,v 1.22 2021/09/01 14:28:15 schwarze Exp $ */ +/* $OpenBSD: cl_read.c,v 1.23 2021/09/02 11:19:02 schwarze Exp $ */ /*- * Copyright (c) 1993, 1994 @@ -62,13 +62,15 @@ retest: if (LF_ISSET(EC_INTERRUPT) || cl_sigint) { evp->e_event = E_TIMEOUT; return (0); } - if (cl_sighup) { + switch (cl_sigterm) { + case SIGHUP: evp->e_event = E_SIGHUP; return (0); - } - if (cl_sigterm) { + case SIGTERM: evp->e_event = E_SIGTERM; return (0); + default: + break; } if (cl_sigwinch) { cl_sigwinch = 0; -- 2.20.1