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