1 /* Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
2    This file is part of the GNU C Library.
3 
4    The GNU C Library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public
6    License as published by the Free Software Foundation; either
7    version 2.1 of the License, or (at your option) any later version.
8 
9    The GNU C Library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with the GNU C Library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA.  */
18 
19 /* Modified 05/30/02 by Jeff Johnston, Red Hat Inc. */
20 
21 #include <errno.h>
22 #include <signal.h>
23 #include <string.h>
24 
25 #include <machine/syscall.h>
26 
27 /* The difference here is that the sigaction structure used in the
28    kernel is not the same as we use in the libc.  Therefore we must
29    translate it here.  */
30 #include <kernel_sigaction.h>
31 
32 #define __NR___rt_sigaction __NR_rt_sigaction
33 
34 static _syscall4(int,__rt_sigaction,int,sig,
35                  const struct kernel_sigaction *,act,
36                  struct kernel_sigaction *,oact,size_t,size);
37 
38 /* If ACT is not NULL, change the action for SIG to *ACT.
39    If OACT is not NULL, put the old action for SIG in *OACT.  */
40 int
__libc_sigaction(sig,act,oact)41 __libc_sigaction (sig, act, oact)
42      int sig;
43      const struct sigaction *act;
44      struct sigaction *oact;
45 {
46   int result;
47   struct kernel_sigaction kact, koact;
48   /* Save the current error value for later.  We need not do this
49      if we are guaranteed to have realtime signals.  */
50 
51   if (act)
52     {
53       kact.k_sa_handler = act->sa_handler;
54       memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
55       kact.sa_flags = act->sa_flags;
56       kact.sa_restorer = act->sa_restorer;
57     }
58 
59   /* XXX The size argument hopefully will have to be changed to the
60      real size of the user-level sigset_t.  */
61   result = __rt_sigaction (sig,
62 	       act ? (&kact) : NULL,
63 	       oact ? (&koact) : NULL, NSIG / 8);
64 
65   if (oact && result >= 0)
66     {
67       oact->sa_handler = koact.k_sa_handler;
68       memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
69       oact->sa_flags = koact.sa_flags;
70       oact->sa_restorer = koact.sa_restorer;
71     }
72 
73   return result;
74 }
75 
76 weak_alias (__libc_sigaction, __sigaction)
77 weak_alias (__libc_sigaction, sigaction)
78