Remove *xattr syscalls.
[glibc.git] / sysdeps / unix / sysv / linux / sigaction.c
blobc95e3d158ca7e701a0bd6a6b42900ae930d92794
1 /* Copyright (C) 1997, 1998, 1999, 2000, 2002 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
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.
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.
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. */
19 #include <errno.h>
20 #include <signal.h>
21 #include <string.h>
23 #include <sysdep.h>
24 #include <sys/syscall.h>
26 #include "kernel-features.h"
28 /* The difference here is that the sigaction structure used in the
29 kernel is not the same as we use in the libc. Therefore we must
30 translate it here. */
31 #include <kernel_sigaction.h>
33 #if __ASSUME_REALTIME_SIGNALS == 0
34 /* The variable is shared between all wrappers around signal handling
35 functions which have RT equivalents. This is the definition. */
36 int __libc_missing_rt_sigs;
38 extern int __syscall_sigaction (int, const struct old_kernel_sigaction *__unbounded,
39 struct old_kernel_sigaction *__unbounded);
40 #endif
41 extern int __syscall_rt_sigaction (int, const struct kernel_sigaction *__unbounded,
42 struct kernel_sigaction *__unbounded, size_t);
45 /* If ACT is not NULL, change the action for SIG to *ACT.
46 If OACT is not NULL, put the old action for SIG in *OACT. */
47 int
48 __libc_sigaction (sig, act, oact)
49 int sig;
50 const struct sigaction *act;
51 struct sigaction *oact;
53 #if __ASSUME_REALTIME_SIGNALS == 0
54 struct old_kernel_sigaction k_sigact, k_osigact;
55 #endif
56 int result;
58 #if defined __NR_rt_sigaction || __ASSUME_REALTIME_SIGNALS > 0
59 /* First try the RT signals. */
60 # if __ASSUME_REALTIME_SIGNALS == 0
61 if (!__libc_missing_rt_sigs)
62 # endif
64 struct kernel_sigaction kact, koact;
65 /* Save the current error value for later. We need not do this
66 if we are guaranteed to have realtime signals. */
67 # if __ASSUME_REALTIME_SIGNALS == 0
68 int saved_errno = errno;
69 # endif
71 if (act)
73 kact.k_sa_handler = act->sa_handler;
74 memcpy (&kact.sa_mask, &act->sa_mask, sizeof (sigset_t));
75 kact.sa_flags = act->sa_flags;
76 # ifdef HAVE_SA_RESTORER
77 kact.sa_restorer = act->sa_restorer;
78 # endif
81 /* XXX The size argument hopefully will have to be changed to the
82 real size of the user-level sigset_t. */
83 result = INLINE_SYSCALL (rt_sigaction, 4, sig,
84 act ? __ptrvalue (&kact) : NULL,
85 oact ? __ptrvalue (&koact) : NULL, _NSIG / 8);
87 # if __ASSUME_REALTIME_SIGNALS == 0
88 if (result >= 0 || errno != ENOSYS)
89 # endif
91 if (oact && result >= 0)
93 oact->sa_handler = koact.k_sa_handler;
94 memcpy (&oact->sa_mask, &koact.sa_mask, sizeof (sigset_t));
95 oact->sa_flags = koact.sa_flags;
96 # ifdef HAVE_SA_RESTORER
97 oact->sa_restorer = koact.sa_restorer;
98 # endif
100 return result;
103 # if __ASSUME_REALTIME_SIGNALS == 0
104 __set_errno (saved_errno);
105 __libc_missing_rt_sigs = 1;
106 # endif
108 #endif
110 #if __ASSUME_REALTIME_SIGNALS == 0
111 if (act)
113 k_sigact.k_sa_handler = act->sa_handler;
114 k_sigact.sa_mask = act->sa_mask.__val[0];
115 k_sigact.sa_flags = act->sa_flags;
116 # ifdef HAVE_SA_RESTORER
117 k_sigact.sa_restorer = act->sa_restorer;
118 # endif
120 result = INLINE_SYSCALL (sigaction, 3, sig,
121 act ? __ptrvalue (&k_sigact) : NULL,
122 oact ? __ptrvalue (&k_osigact) : NULL);
123 if (oact && result >= 0)
125 oact->sa_handler = k_osigact.k_sa_handler;
126 oact->sa_mask.__val[0] = k_osigact.sa_mask;
127 oact->sa_flags = k_osigact.sa_flags;
128 # ifdef HAVE_SA_RESTORER
129 oact->sa_restorer = k_osigact.sa_restorer;
130 # endif
132 return result;
133 #endif
136 weak_alias (__libc_sigaction, __sigaction)
137 libc_hidden_weak (__sigaction)
138 weak_alias (__libc_sigaction, sigaction)