Move dc(1) from legacy sigset(3) to sigaction(2)

This commit is contained in:
Juhani Krekelä 2021-04-18 22:48:16 +03:00
parent 68a2eff733
commit b00b6a04fa
2 changed files with 16 additions and 9 deletions

6
README
View File

@ -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.

19
dc/dc.c
View File

@ -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);
}