xref: /titanic_44/usr/src/lib/libc/port/gen/psiginfo.c (revision 95efa359b507db290a2484b8f615822b1e06096f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1988 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Print the name of the siginfo indicated by "sig", along with the
34  * supplied message
35  */
36 
37 #include "lint.h"
38 #include "_libc_gettext.h"
39 #include <sys/types.h>
40 #include <stdio.h>
41 #include <unistd.h>
42 #include <string.h>
43 #include <signal.h>
44 #include <siginfo.h>
45 
46 #define	strsignal(i)	(_libc_gettext(_sys_siglistp[i]))
47 
48 void
49 psiginfo(siginfo_t *sip, char *s)
50 {
51 	char buf[256];
52 	char *c;
53 	const struct siginfolist *listp;
54 
55 	if (sip == 0)
56 		return;
57 
58 
59 	if (sip->si_code <= 0) {
60 		(void) snprintf(buf, sizeof (buf),
61 		    _libc_gettext("%s : %s ( from process  %d )\n"),
62 		    s, strsignal(sip->si_signo), sip->si_pid);
63 	} else if (((listp = &_sys_siginfolist[sip->si_signo-1]) != NULL) &&
64 	    sip->si_code <= listp->nsiginfo) {
65 		c = _libc_gettext(listp->vsiginfo[sip->si_code-1]);
66 		switch (sip->si_signo) {
67 		case SIGSEGV:
68 		case SIGBUS:
69 		case SIGILL:
70 		case SIGFPE:
71 			(void) snprintf(buf, sizeof (buf),
72 			    _libc_gettext("%s : %s ( [%p] %s)\n"),
73 			    s, strsignal(sip->si_signo),
74 			    sip->si_addr, c);
75 			break;
76 		default:
77 			(void) snprintf(buf, sizeof (buf),
78 			    _libc_gettext("%s : %s (%s)\n"),
79 			    s, strsignal(sip->si_signo), c);
80 			break;
81 		}
82 	} else {
83 		(void) snprintf(buf, sizeof (buf),
84 		    _libc_gettext("%s : %s\n"),
85 		    s, strsignal(sip->si_signo));
86 	}
87 	(void) write(2, buf, strlen(buf));
88 }
89