1 /* Copyright (C) 2009 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
27 #include <not-cancel.h>
30 /* Defined in sys_siglist.c. */
31 extern const char *const _sys_siglist
[];
32 extern const char *const _sys_siglist_internal
[] attribute_hidden
;
36 #define MF1(l) str_##l
37 #define C(s1, s2) C1 (s1, s2)
38 #define C1(s1, s2) s1##s2
41 #include "psiginfo-define.h"
44 #include "psiginfo-define.h"
47 #include "psiginfo-define.h"
50 #include "psiginfo-define.h"
53 #include "psiginfo-define.h"
56 #include "psiginfo-define.h"
59 #include "psiginfo-define.h"
62 /* Print out on stderr a line consisting of the test in S, a colon, a space,
63 a message describing the meaning of the signal number PINFO and a newline.
64 If S is NULL or "", the colon and space are omitted. */
66 psiginfo (const siginfo_t
*pinfo
, const char *s
)
69 FILE *fp
= fmemopen (buf
, sizeof (buf
), "w");
74 if (s
== NULL
|| *s
== '\0')
79 __fxprintf (NULL
, "%s%ssignal %d\n", s
, colon
, pinfo
->si_signo
);
83 if (s
!= NULL
&& *s
!= '\0')
84 fprintf (fp
, "%s: ", s
);
87 if (pinfo
->si_signo
>= 0 && pinfo
->si_signo
< NSIG
88 && (desc
= INTUSE(_sys_siglist
)[pinfo
->si_signo
]) != NULL
)
90 fprintf (fp
, "%s (", _(desc
));
92 const char *base
= NULL
;
93 const uint8_t *offarr
= NULL
;
94 size_t offarr_len
= 0;
95 switch (pinfo
->si_signo
)
99 base = C(codestrs_, sig).str; \
100 offarr = C (codes_, sig); \
101 offarr_len = sizeof (C (codes_, sig)) / sizeof (C (codes_, sig)[0]);\
113 const char *str
= NULL
;
115 && pinfo
->si_code
>= 1 && pinfo
->si_code
<= offarr_len
)
116 str
= base
+ offarr
[pinfo
->si_code
- 1];
118 switch (pinfo
->si_code
)
121 str
= N_("Signal sent by kill()");
124 str
= N_("Signal sent by sigqueue()");
127 str
= N_("Signal generated by the expiration of a timer");
131 Signal generated by the completion of an asynchronous I/O request");
135 Signal generated by the arrival of a message on an empty message queue");
139 str
= N_("Signal sent by tkill()");
145 Signal generated by the completion of an asynchronous name lookup request");
151 Signal generated by the completion of an I/O request");
156 str
= N_("Signal sent by the kernel");
162 fprintf (fp
, "%s ", _(str
));
164 fprintf (fp
, "%d ", pinfo
->si_code
);
166 if (pinfo
->si_signo
== SIGILL
|| pinfo
->si_signo
== SIGFPE
167 || pinfo
->si_signo
== SIGSEGV
|| pinfo
->si_signo
== SIGBUS
)
168 fprintf (fp
, "[%p])", pinfo
->si_addr
);
169 else if (pinfo
->si_signo
== SIGCHLD
)
170 fprintf (fp
, "%ld %d %ld)", (long int) pinfo
->si_pid
, pinfo
->si_status
,
171 (long int) pinfo
->si_uid
);
172 else if (pinfo
->si_signo
== SIGPOLL
)
173 fprintf (fp
, "%ld)", (long int) pinfo
->si_band
);
175 fprintf (fp
, "%ld %ld)",
176 (long int) pinfo
->si_pid
, (long int) pinfo
->si_uid
);
179 fprintf (fp
, _("Unknown signal %d\n"), pinfo
->si_signo
);
183 write_not_cancel (STDERR_FILENO
, buf
, strlen (buf
));