1 /* Copyright (C) 2009-2012 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>
30 #define MF1(l) str_##l
31 #define C(s1, s2) C1 (s1, s2)
32 #define C1(s1, s2) s1##s2
35 #include "psiginfo-define.h"
38 #include "psiginfo-define.h"
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 /* Print out on stderr a line consisting of the test in S, a colon, a space,
57 a message describing the meaning of the signal number PINFO and a newline.
58 If S is NULL or "", the colon and space are omitted. */
60 psiginfo (const siginfo_t *pinfo, const char *s)
63 FILE *fp = fmemopen (buf, sizeof (buf), "w");
68 if (s == NULL || *s == '\0')
73 __fxprintf (NULL, "%s%ssignal %d\n", s, colon, pinfo->si_signo);
77 if (s != NULL && *s != '\0')
78 fprintf (fp, "%s: ", s);
81 if (pinfo->si_signo >= 0 && pinfo->si_signo < NSIG
82 && ((desc = _sys_siglist[pinfo->si_signo]) != NULL
84 || (pinfo->si_signo >= SIGRTMIN && pinfo->si_signo < SIGRTMAX)
91 if (pinfo->si_signo - SIGRTMIN < SIGRTMAX - pinfo->si_signo)
93 if (pinfo->si_signo == SIGRTMIN)
94 fprintf (fp, "SIGRTMIN (");
96 fprintf (fp, "SIGRTMIN+%d (", pinfo->si_signo - SIGRTMIN);
100 if (pinfo->si_signo == SIGRTMAX)
101 fprintf (fp, "SIGRTMAX (");
103 fprintf (fp, "SIGRTMAX-%d (", SIGRTMAX - pinfo->si_signo);
108 fprintf (fp, "%s (", _(desc));
110 const char *base = NULL;
111 const uint8_t *offarr = NULL;
112 size_t offarr_len = 0;
113 switch (pinfo->si_signo)
117 base = C(codestrs_, sig).str; \
118 offarr = C (codes_, sig); \
119 offarr_len = sizeof (C (codes_, sig)) / sizeof (C (codes_, sig)[0]);\
131 const char *str = NULL;
133 && pinfo->si_code >= 1 && pinfo->si_code <= offarr_len)
134 str = base + offarr[pinfo->si_code - 1];
136 switch (pinfo->si_code)
139 str = N_("Signal sent by kill()");
142 str = N_("Signal sent by sigqueue()");
145 str = N_("Signal generated by the expiration of a timer");
149 Signal generated by the completion of an asynchronous I/O request");
153 Signal generated by the arrival of a message on an empty message queue");
157 str = N_("Signal sent by tkill()");
163 Signal generated by the completion of an asynchronous name lookup request");
169 Signal generated by the completion of an I/O request");
174 str = N_("Signal sent by the kernel");
180 fprintf (fp, "%s ", _(str));
182 fprintf (fp, "%d ", pinfo->si_code);
184 if (pinfo->si_signo == SIGILL || pinfo->si_signo == SIGFPE
185 || pinfo->si_signo == SIGSEGV || pinfo->si_signo == SIGBUS)
186 fprintf (fp, "[%p])\n", pinfo->si_addr);
187 else if (pinfo->si_signo == SIGCHLD)
188 fprintf (fp, "%ld %d %ld)\n",
189 (long int) pinfo->si_pid, pinfo->si_status,
190 (long int) pinfo->si_uid);
191 else if (pinfo->si_signo == SIGPOLL)
192 fprintf (fp, "%ld)\n", (long int) pinfo->si_band);
194 fprintf (fp, "%ld %ld)\n",
195 (long int) pinfo->si_pid, (long int) pinfo->si_uid);
198 fprintf (fp, _("Unknown signal %d\n"), pinfo->si_signo);
202 write_not_cancel (STDERR_FILENO, buf, strlen (buf));