1 /* Copyright (C) 2009-2023 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 <https://www.gnu.org/licenses/>. */
18 #include <array_length.h>
27 #include <not-cancel.h>
31 #define MF1(l) str_##l
32 #define C(s1, s2) C1 (s1, s2)
33 #define C1(s1, s2) s1##s2
36 #include "psiginfo-define.h"
39 #include "psiginfo-define.h"
42 #include "psiginfo-define.h"
45 #include "psiginfo-define.h"
48 #include "psiginfo-define.h"
51 #include "psiginfo-define.h"
54 #include "psiginfo-define.h"
57 /* Print out on stderr a line consisting of the test in S, a colon, a space,
58 a message describing the meaning of the signal number PINFO and a newline.
59 If S is NULL or "", the colon and space are omitted. */
61 psiginfo (const siginfo_t
*pinfo
, const char *s
)
64 FILE *fp
= __fmemopen (buf
, sizeof (buf
), "w");
69 if (s
== NULL
|| *s
== '\0')
74 __fxprintf (NULL
, "%s%ssignal %d\n", s
, colon
, pinfo
->si_signo
);
78 if (s
!= NULL
&& *s
!= '\0')
79 fprintf (fp
, "%s: ", s
);
82 if (pinfo
->si_signo
>= 0 && pinfo
->si_signo
< NSIG
83 && ((desc
= __sys_siglist
[pinfo
->si_signo
]) != NULL
85 || (pinfo
->si_signo
>= SIGRTMIN
&& pinfo
->si_signo
< SIGRTMAX
)
92 if (pinfo
->si_signo
- SIGRTMIN
< SIGRTMAX
- pinfo
->si_signo
)
94 if (pinfo
->si_signo
== SIGRTMIN
)
95 fprintf (fp
, "SIGRTMIN (");
97 fprintf (fp
, "SIGRTMIN+%d (", pinfo
->si_signo
- SIGRTMIN
);
101 if (pinfo
->si_signo
== SIGRTMAX
)
102 fprintf (fp
, "SIGRTMAX (");
104 fprintf (fp
, "SIGRTMAX-%d (", SIGRTMAX
- pinfo
->si_signo
);
109 fprintf (fp
, "%s (", _(desc
));
111 const char *base
= NULL
;
112 const uint8_t *offarr
= NULL
;
113 size_t offarr_len
= 0;
114 switch (pinfo
->si_signo
)
118 base = C(codestrs_, sig).str; \
119 offarr = C (codes_, sig); \
120 offarr_len = array_length (C (codes_, sig)); \
132 const char *str
= NULL
;
134 && pinfo
->si_code
>= 1 && pinfo
->si_code
<= offarr_len
)
135 str
= base
+ offarr
[pinfo
->si_code
- 1];
137 switch (pinfo
->si_code
)
140 str
= N_("Signal sent by kill()");
143 str
= N_("Signal sent by sigqueue()");
146 str
= N_("Signal generated by the expiration of a timer");
150 Signal generated by the completion of an asynchronous I/O request");
154 Signal generated by the arrival of a message on an empty message queue");
158 str
= N_("Signal sent by tkill()");
164 Signal generated by the completion of an asynchronous name lookup request");
170 Signal generated by the completion of an I/O request");
175 str
= N_("Signal sent by the kernel");
181 fprintf (fp
, "%s ", _(str
));
183 fprintf (fp
, "%d ", pinfo
->si_code
);
185 if (pinfo
->si_signo
== SIGILL
|| pinfo
->si_signo
== SIGFPE
186 || pinfo
->si_signo
== SIGSEGV
|| pinfo
->si_signo
== SIGBUS
)
187 fprintf (fp
, "[%p])\n", pinfo
->si_addr
);
188 else if (pinfo
->si_signo
== SIGCHLD
)
189 fprintf (fp
, "%ld %d %ld)\n",
190 (long int) pinfo
->si_pid
, pinfo
->si_status
,
191 (long int) pinfo
->si_uid
);
192 else if (pinfo
->si_signo
== SIGPOLL
)
193 fprintf (fp
, "%ld)\n", (long int) pinfo
->si_band
);
195 fprintf (fp
, "%ld %ld)\n",
196 (long int) pinfo
->si_pid
, (long int) pinfo
->si_uid
);
199 fprintf (fp
, _("Unknown signal %d\n"), pinfo
->si_signo
);
203 __write_nocancel (STDERR_FILENO
, buf
, strlen (buf
));