1 /* Copyright (C) 2009, 2010 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, see
16 <http://www.gnu.org/licenses/>. */
26 #include <not-cancel.h>
29 /* Defined in sys_siglist.c. */
30 extern const char *const _sys_siglist
[];
31 extern const char *const _sys_siglist_internal
[] attribute_hidden
;
35 #define MF1(l) str_##l
36 #define C(s1, s2) C1 (s1, s2)
37 #define C1(s1, s2) s1##s2
40 #include "psiginfo-define.h"
43 #include "psiginfo-define.h"
46 #include "psiginfo-define.h"
49 #include "psiginfo-define.h"
52 #include "psiginfo-define.h"
55 #include "psiginfo-define.h"
58 #include "psiginfo-define.h"
61 /* Print out on stderr a line consisting of the test in S, a colon, a space,
62 a message describing the meaning of the signal number PINFO and a newline.
63 If S is NULL or "", the colon and space are omitted. */
65 psiginfo (const siginfo_t
*pinfo
, const char *s
)
68 FILE *fp
= fmemopen (buf
, sizeof (buf
), "w");
73 if (s
== NULL
|| *s
== '\0')
78 __fxprintf (NULL
, "%s%ssignal %d\n", s
, colon
, pinfo
->si_signo
);
82 if (s
!= NULL
&& *s
!= '\0')
83 fprintf (fp
, "%s: ", s
);
86 if (pinfo
->si_signo
>= 0 && pinfo
->si_signo
< NSIG
87 && ((desc
= INTUSE(_sys_siglist
)[pinfo
->si_signo
]) != NULL
89 || (pinfo
->si_signo
>= SIGRTMIN
&& pinfo
->si_signo
< SIGRTMAX
)
96 if (pinfo
->si_signo
- SIGRTMIN
< SIGRTMAX
- pinfo
->si_signo
)
98 if (pinfo
->si_signo
== SIGRTMIN
)
99 fprintf (fp
, "SIGRTMIN (");
101 fprintf (fp
, "SIGRTMIN+%d (", pinfo
->si_signo
- SIGRTMIN
);
105 if (pinfo
->si_signo
== SIGRTMAX
)
106 fprintf (fp
, "SIGRTMAX (");
108 fprintf (fp
, "SIGRTMAX-%d (", SIGRTMAX
- pinfo
->si_signo
);
113 fprintf (fp
, "%s (", _(desc
));
115 const char *base
= NULL
;
116 const uint8_t *offarr
= NULL
;
117 size_t offarr_len
= 0;
118 switch (pinfo
->si_signo
)
122 base = C(codestrs_, sig).str; \
123 offarr = C (codes_, sig); \
124 offarr_len = sizeof (C (codes_, sig)) / sizeof (C (codes_, sig)[0]);\
136 const char *str
= NULL
;
138 && pinfo
->si_code
>= 1 && pinfo
->si_code
<= offarr_len
)
139 str
= base
+ offarr
[pinfo
->si_code
- 1];
141 switch (pinfo
->si_code
)
144 str
= N_("Signal sent by kill()");
147 str
= N_("Signal sent by sigqueue()");
150 str
= N_("Signal generated by the expiration of a timer");
154 Signal generated by the completion of an asynchronous I/O request");
158 Signal generated by the arrival of a message on an empty message queue");
162 str
= N_("Signal sent by tkill()");
168 Signal generated by the completion of an asynchronous name lookup request");
174 Signal generated by the completion of an I/O request");
179 str
= N_("Signal sent by the kernel");
185 fprintf (fp
, "%s ", _(str
));
187 fprintf (fp
, "%d ", pinfo
->si_code
);
189 if (pinfo
->si_signo
== SIGILL
|| pinfo
->si_signo
== SIGFPE
190 || pinfo
->si_signo
== SIGSEGV
|| pinfo
->si_signo
== SIGBUS
)
191 fprintf (fp
, "[%p])\n", pinfo
->si_addr
);
192 else if (pinfo
->si_signo
== SIGCHLD
)
193 fprintf (fp
, "%ld %d %ld)\n",
194 (long int) pinfo
->si_pid
, pinfo
->si_status
,
195 (long int) pinfo
->si_uid
);
196 else if (pinfo
->si_signo
== SIGPOLL
)
197 fprintf (fp
, "%ld)\n", (long int) pinfo
->si_band
);
199 fprintf (fp
, "%ld %ld)\n",
200 (long int) pinfo
->si_pid
, (long int) pinfo
->si_uid
);
203 fprintf (fp
, _("Unknown signal %d\n"), pinfo
->si_signo
);
207 write_not_cancel (STDERR_FILENO
, buf
, strlen (buf
));