~ubuntu-branches/ubuntu/quantal/uclibc/quantal

« back to all changes in this revision

Viewing changes to libc/signal/sigset.c

  • Committer: Bazaar Package Importer
  • Author(s): Hector Oron
  • Date: 2011-06-11 03:06:20 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110611030620-ywjfvyuqvrpsm282
Tags: 0.9.32-1
* New upstream release
* Add myself as maintainer
* Bump standards version 
* Add Vcs-Git, Vcs-Browser and Homepage fields
* Add watch file 

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
#include <signal.h>
23
23
#include <string.h>     /* For the real memset prototype.  */
24
24
 
25
 
libc_hidden_proto(sigaction)
26
 
libc_hidden_proto(sigprocmask)
27
25
 
28
26
/* Set the disposition for SIG.  */
29
27
__sighandler_t sigset (int sig, __sighandler_t disp)
31
29
  struct sigaction act, oact;
32
30
  sigset_t set;
33
31
 
 
32
  /* Check signal extents to protect __sigismember.  */
 
33
  if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
 
34
    {
 
35
      __set_errno (EINVAL);
 
36
      return SIG_ERR;
 
37
    }
 
38
 
34
39
#ifdef SIG_HOLD
35
40
  /* Handle SIG_HOLD first.  */
36
41
  if (disp == SIG_HOLD)
37
42
    {
38
 
      /* Create an empty signal set.  */
39
 
      if (__sigemptyset (&set) < 0)
40
 
        return SIG_ERR;
41
 
 
42
 
      /* Add the specified signal.  */
43
 
      if (__sigaddset (&set, sig) < 0)
44
 
        return SIG_ERR;
 
43
      __sigemptyset (&set);
 
44
      __sigaddset (&set, sig);
45
45
 
46
46
      /* Add the signal set to the current signal mask.  */
47
 
      if (sigprocmask (SIG_BLOCK, &set, NULL) < 0)
48
 
        return SIG_ERR;
 
47
      sigprocmask (SIG_BLOCK, &set, NULL); /* can't fail */
49
48
 
50
49
      return SIG_HOLD;
51
50
    }
52
51
#endif  /* SIG_HOLD */
53
52
 
54
 
  /* Check signal extents to protect __sigismember.  */
55
 
  if (disp == SIG_ERR || sig < 1 || sig >= NSIG)
56
 
    {
57
 
      __set_errno (EINVAL);
58
 
      return SIG_ERR;
59
 
    }
60
 
 
 
53
  memset(&act, 0, sizeof(act));
61
54
  act.sa_handler = disp;
62
 
  if (__sigemptyset (&act.sa_mask) < 0)
63
 
    return SIG_ERR;
64
 
  act.sa_flags = 0;
 
55
  /* In Linux (as of 2.6.25), fails only if sig is SIGKILL or SIGSTOP */
65
56
  if (sigaction (sig, &act, &oact) < 0)
66
57
    return SIG_ERR;
67
58
 
68
 
  /* Create an empty signal set.  */
69
 
  if (__sigemptyset (&set) < 0)
70
 
    return SIG_ERR;
71
 
 
72
 
  /* Add the specified signal.  */
73
 
  if (__sigaddset (&set, sig) < 0)
74
 
    return SIG_ERR;
 
59
  /* Create an empty signal set. Add the specified signal.  */
 
60
  __sigemptyset (&set);
 
61
  __sigaddset (&set, sig);
75
62
 
76
63
  /* Remove the signal set from the current signal mask.  */
77
 
  if (sigprocmask (SIG_UNBLOCK, &set, NULL) < 0)
78
 
    return SIG_ERR;
 
64
  sigprocmask (SIG_UNBLOCK, &set, NULL); /* can't fail */
79
65
 
80
66
  return oact.sa_handler;
81
67
}