summaryrefslogtreecommitdiff
path: root/sig_dfl.c
blob: a92bd7b4c3d54a926908bc237dabe6859ddd60f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <signal.h>
#include "sig.h"
#include "hassgact.h"
#include "hassgprm.h"

/* tnx to Chris Torek for some improvements in previous versions */

static int flagcont;

static void sigcont() { flagcont = 1; }

void sig_dfl(sig)
int sig;
{
#ifdef HASSIGPROCMASK
  sigset_t ssorig;
  sigset_t ssnew;
#else
  int maskorig;
  int masknew;
#endif
#ifdef HASSIGACTION
  struct sigaction saorig;
  struct sigaction sanew;
#else
  struct sigvec svorig;
  struct sigvec svnew;
#endif

  if (sig == SIGCONT) return;

#ifdef HASSIGPROCMASK
  sigfillset(&ssnew);
  sigprocmask(SIG_SETMASK,&ssnew,&ssorig);
#else
  masknew = ~0;
  maskorig = sigsetmask(masknew);
#endif

#ifdef HASSIGACTION
  sanew.sa_handler = SIG_DFL;
  sanew.sa_flags = 0;
  sigemptyset(&sanew.sa_mask);
  sigaction(sig,&sanew,&saorig);
  sanew.sa_handler = sigcont;
  sigaction(SIGCONT,&sanew,(struct sigaction *) 0);
#else
  svnew.sv_handler = SIG_DFL;
  svnew.sv_flags = 0;
  svnew.sv_mask = 0;
  sigvec(sig,&svnew,&svorig);
  svnew.sv_handler = sigcont;
  sigvec(SIGCONT,&svnew,(struct sigvec *) 0);
#endif

  flagcont = 0;
  if (kill(getpid(),sig) == 0) {
#ifdef HASSIGPROCMASK
    sigdelset(&ssnew,sig);
    sigdelset(&ssnew,SIGCONT);
    while (!flagcont)
      sigsuspend(&ssnew);
#else
    masknew &= ~(1 << (sig - 1));
    masknew &= ~(1 << (SIGCONT - 1));
    while (!flagcont)
      sigpause(masknew);
#endif
  }

#ifdef HASSIGACTION
  sigaction(sig,&saorig,(struct sigaction *) 0);
#else
  sigvec(sig,&svorig,(struct sigvec *) 0);
#endif

#ifdef HASSIGPROCMASK
  sigprocmask(SIG_SETMASK,&ssorig,(sigset_t *) 0);
#else
  sigsetmask(maskorig);
#endif
}