From b00b6a04fabe5c0d04bae976c7672ae88f578593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 18 Apr 2021 22:48:16 +0300 Subject: [PATCH] Move dc(1) from legacy sigset(3) to sigaction(2) --- README | 6 ++++-- dc/dc.c | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/README b/README index 9d79ad2..54cc5c5 100644 --- a/README +++ b/README @@ -1,9 +1,11 @@ Heirloom bc & dc provides a stand-alone project of the Heirloom Project versions of bc(1) and dc(1) with simpler build system and no unnecessary -compatibility layers. +compatibility layers. The code has been modernized as needed to get it +working, but otherwise stays close to the original Heirloom Project +sources. At the moment the code compiles and appears to run correctly with Glibc -and Musl under Linux. +and Musl under Linux as well as Sortix. The code contains parts licensed under both 4BSD and zlib licenses. See the COPYING file in the relevant subdirectory for more details. diff --git a/dc/dc.c b/dc/dc.c index 68ff9c1..c86c477 100644 --- a/dc/dc.c +++ b/dc/dc.c @@ -934,9 +934,13 @@ void init(int argc,char **argv) { register struct sym *sp; + struct sigaction sa; - if (sigset(SIGINT, SIG_IGN) != SIG_IGN) - sigset(SIGINT,onintr); + sigaction(SIGINT, NULL, &sa); + if (sa.sa_handler != SIG_IGN){ + sa.sa_handler = onintr; + sigaction(SIGINT, &sa, NULL); + } setbuf(stdout,(char *)NULL); svargc = --argc; svargv = argv; @@ -990,8 +994,6 @@ init(int argc,char **argv) void onintr(int signum){ - - sigset(SIGINT,onintr); while(readptr != &readstk[0]){ if(*readptr != 0){release(*readptr);} readptr--; @@ -1644,7 +1646,7 @@ command(void){ static char *line; static int linesize; char *sl; - register void (*savint)(int); + struct sigaction sa,savint; register int pid,rpid; int retcode; @@ -1673,9 +1675,12 @@ command(void){ execl("/bin/sh","sh","-c",line,NULL); exit(0100); } - savint = sigset(SIGINT, SIG_IGN); + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sa.sa_handler = SIG_IGN; + sigaction(SIGINT, &sa, &savint); while((rpid = wait(&retcode)) != pid && rpid != -1); - sigset(SIGINT,savint); + sigaction(SIGINT, &savint, NULL); printf("!\n"); return(0); }