17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
57257d1b4Sraf * Common Development and Distribution License (the "License").
67257d1b4Sraf * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
213e5de5d0SEric Sproul /*
223e5de5d0SEric Sproul * Copyright 2015 Circonus, Inc. All rights reserved.
233e5de5d0SEric Sproul */
247257d1b4Sraf
257c478bd9Sstevel@tonic-gate /*
267257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
277c478bd9Sstevel@tonic-gate * Use is subject to license terms.
287c478bd9Sstevel@tonic-gate */
297c478bd9Sstevel@tonic-gate
307c478bd9Sstevel@tonic-gate /* Copyright (c) 1988 AT&T */
317c478bd9Sstevel@tonic-gate /* All Rights Reserved */
327c478bd9Sstevel@tonic-gate
337c478bd9Sstevel@tonic-gate /*
347c478bd9Sstevel@tonic-gate * Print the name of the siginfo indicated by "sig", along with the
357c478bd9Sstevel@tonic-gate * supplied message
367c478bd9Sstevel@tonic-gate */
377c478bd9Sstevel@tonic-gate
387257d1b4Sraf #include "lint.h"
397257d1b4Sraf #include "_libc_gettext.h"
407257d1b4Sraf #include <sys/types.h>
417257d1b4Sraf #include <stdio.h>
427257d1b4Sraf #include <unistd.h>
437257d1b4Sraf #include <string.h>
447257d1b4Sraf #include <signal.h>
457257d1b4Sraf #include <siginfo.h>
467c478bd9Sstevel@tonic-gate
477c478bd9Sstevel@tonic-gate #define strsignal(i) (_libc_gettext(_sys_siglistp[i]))
487c478bd9Sstevel@tonic-gate
497c478bd9Sstevel@tonic-gate void
psiginfo(const siginfo_t * sip,const char * s)503e5de5d0SEric Sproul psiginfo(const siginfo_t *sip, const char *s)
517c478bd9Sstevel@tonic-gate {
527c478bd9Sstevel@tonic-gate char buf[256];
537c478bd9Sstevel@tonic-gate char *c;
54*49add8ecSRobert Mustacchi size_t l = 0;
557c478bd9Sstevel@tonic-gate const struct siginfolist *listp;
567c478bd9Sstevel@tonic-gate
57*49add8ecSRobert Mustacchi if (sip == NULL)
587c478bd9Sstevel@tonic-gate return;
597c478bd9Sstevel@tonic-gate
60*49add8ecSRobert Mustacchi if (s != NULL && *s != '\0') {
61*49add8ecSRobert Mustacchi l = snprintf(buf, sizeof (buf), _libc_gettext("%s : "), s);
62*49add8ecSRobert Mustacchi if (l > sizeof (buf))
63*49add8ecSRobert Mustacchi l = sizeof (buf);
64*49add8ecSRobert Mustacchi }
65*49add8ecSRobert Mustacchi
667c478bd9Sstevel@tonic-gate
677c478bd9Sstevel@tonic-gate if (sip->si_code <= 0) {
68*49add8ecSRobert Mustacchi (void) snprintf(buf + l, sizeof (buf) - l,
69*49add8ecSRobert Mustacchi _libc_gettext("%s ( from process %d )\n"),
70*49add8ecSRobert Mustacchi strsignal(sip->si_signo), sip->si_pid);
717c478bd9Sstevel@tonic-gate } else if (((listp = &_sys_siginfolist[sip->si_signo-1]) != NULL) &&
727c478bd9Sstevel@tonic-gate sip->si_code <= listp->nsiginfo) {
737c478bd9Sstevel@tonic-gate c = _libc_gettext(listp->vsiginfo[sip->si_code-1]);
747c478bd9Sstevel@tonic-gate switch (sip->si_signo) {
757c478bd9Sstevel@tonic-gate case SIGSEGV:
767c478bd9Sstevel@tonic-gate case SIGBUS:
777c478bd9Sstevel@tonic-gate case SIGILL:
787c478bd9Sstevel@tonic-gate case SIGFPE:
79*49add8ecSRobert Mustacchi (void) snprintf(buf + l, sizeof (buf) - l,
80*49add8ecSRobert Mustacchi _libc_gettext("%s ( [%p] %s)\n"),
81*49add8ecSRobert Mustacchi strsignal(sip->si_signo),
827257d1b4Sraf sip->si_addr, c);
837c478bd9Sstevel@tonic-gate break;
847c478bd9Sstevel@tonic-gate default:
85*49add8ecSRobert Mustacchi (void) snprintf(buf + l, sizeof (buf) - l,
86*49add8ecSRobert Mustacchi _libc_gettext("%s (%s)\n"),
87*49add8ecSRobert Mustacchi strsignal(sip->si_signo), c);
887c478bd9Sstevel@tonic-gate break;
897c478bd9Sstevel@tonic-gate }
907c478bd9Sstevel@tonic-gate } else {
91*49add8ecSRobert Mustacchi (void) snprintf(buf + l, sizeof (buf) - l,
92*49add8ecSRobert Mustacchi _libc_gettext("%s\n"), strsignal(sip->si_signo));
937c478bd9Sstevel@tonic-gate }
947c478bd9Sstevel@tonic-gate (void) write(2, buf, strlen(buf));
957c478bd9Sstevel@tonic-gate }
96