diff options
| -rw-r--r-- | usr/src/lib/libc/port/gen/psiginfo.c | 32 | ||||
| -rw-r--r-- | usr/src/lib/libc/port/gen/psignal.c | 9 | ||||
| -rw-r--r-- | usr/src/man/man3c/psignal.3c | 7 | ||||
| -rw-r--r-- | usr/src/pkg/manifests/system-test-libctest.mf | 3 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/runfiles/default.run | 1 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/Makefile | 4 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/psignal-5097.c | 38 | ||||
| -rw-r--r-- | usr/src/test/libc-tests/tests/psignal.ksh | 59 |
8 files changed, 132 insertions, 21 deletions
diff --git a/usr/src/lib/libc/port/gen/psiginfo.c b/usr/src/lib/libc/port/gen/psiginfo.c index a648c81094..e7cf46abef 100644 --- a/usr/src/lib/libc/port/gen/psiginfo.c +++ b/usr/src/lib/libc/port/gen/psiginfo.c @@ -51,16 +51,23 @@ psiginfo(const siginfo_t *sip, const char *s) { char buf[256]; char *c; + size_t l = 0; const struct siginfolist *listp; - if (sip == 0) + if (sip == NULL) return; + if (s != NULL && *s != '\0') { + l = snprintf(buf, sizeof (buf), _libc_gettext("%s : "), s); + if (l > sizeof (buf)) + l = sizeof (buf); + } + if (sip->si_code <= 0) { - (void) snprintf(buf, sizeof (buf), - _libc_gettext("%s : %s ( from process %d )\n"), - s, strsignal(sip->si_signo), sip->si_pid); + (void) snprintf(buf + l, sizeof (buf) - l, + _libc_gettext("%s ( from process %d )\n"), + strsignal(sip->si_signo), sip->si_pid); } else if (((listp = &_sys_siginfolist[sip->si_signo-1]) != NULL) && sip->si_code <= listp->nsiginfo) { c = _libc_gettext(listp->vsiginfo[sip->si_code-1]); @@ -69,21 +76,20 @@ psiginfo(const siginfo_t *sip, const char *s) case SIGBUS: case SIGILL: case SIGFPE: - (void) snprintf(buf, sizeof (buf), - _libc_gettext("%s : %s ( [%p] %s)\n"), - s, strsignal(sip->si_signo), + (void) snprintf(buf + l, sizeof (buf) - l, + _libc_gettext("%s ( [%p] %s)\n"), + strsignal(sip->si_signo), sip->si_addr, c); break; default: - (void) snprintf(buf, sizeof (buf), - _libc_gettext("%s : %s (%s)\n"), - s, strsignal(sip->si_signo), c); + (void) snprintf(buf + l, sizeof (buf) - l, + _libc_gettext("%s (%s)\n"), + strsignal(sip->si_signo), c); break; } } else { - (void) snprintf(buf, sizeof (buf), - _libc_gettext("%s : %s\n"), - s, strsignal(sip->si_signo)); + (void) snprintf(buf + l, sizeof (buf) - l, + _libc_gettext("%s\n"), strsignal(sip->si_signo)); } (void) write(2, buf, strlen(buf)); } diff --git a/usr/src/lib/libc/port/gen/psignal.c b/usr/src/lib/libc/port/gen/psignal.c index 201beaacd7..2a61cd9610 100644 --- a/usr/src/lib/libc/port/gen/psignal.c +++ b/usr/src/lib/libc/port/gen/psignal.c @@ -37,8 +37,6 @@ * contributors. */ -#pragma ident "%Z%%M% %I% %E% SMI" - /* * Print the name of the signal indicated by "sig", along with the * supplied message @@ -61,14 +59,15 @@ void psignal(int sig, const char *s) { char *c; - size_t n; + size_t n = 0; char buf[256]; if (sig < 0 || sig >= NSIG) sig = 0; c = strsignal(sig); - n = strlen(s); - if (n) { + if (s != NULL) + n = strlen(s); + if (n != 0) { (void) snprintf(buf, sizeof (buf), "%s: %s\n", s, c); } else { (void) snprintf(buf, sizeof (buf), "%s\n", c); diff --git a/usr/src/man/man3c/psignal.3c b/usr/src/man/man3c/psignal.3c index 655dedb022..20653e1f98 100644 --- a/usr/src/man/man3c/psignal.3c +++ b/usr/src/man/man3c/psignal.3c @@ -1,10 +1,11 @@ '\" te .\" Copyright 1989 AT&T. Copyright (c) 2005, Sun Microsystems, Inc. All Rights Reserved. +.\" Copyright (c) 2014, Joyent, Inc. All rights reserved. .\" Copyright 2015 Circonus, Inc. All rights reserved. .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License. .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License. .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner] -.TH PSIGNAL 3C "Mar 31, 2005" +.TH PSIGNAL 3C "Aug 14, 2014" .SH NAME psignal, psiginfo \- system signal messages .SH SYNOPSIS @@ -28,7 +29,9 @@ that may have been passed as the first argument to a signal handler. The \fIpinfo\fR argument is a pointer to a \fBsiginfo\fR structure that may have been passed as the second argument to an enhanced signal handler. See \fBsigaction\fR(2). The argument string \fIs\fR is printed first, followed by a -colon and a blank, followed by the message and a \fBNEWLINE\fR character. +colon and a blank, followed by the message and a \fBNEWLINE\fR character. If +\fBs\fR is the value \fBNULL\fR or an empty string, then nothing is printed for +the user's string and the colon and blank are omitted. .SH USAGE .LP Messages printed from these functions are in the native language specified by diff --git a/usr/src/pkg/manifests/system-test-libctest.mf b/usr/src/pkg/manifests/system-test-libctest.mf index 558dbdb622..6cc5b2ebcb 100644 --- a/usr/src/pkg/manifests/system-test-libctest.mf +++ b/usr/src/pkg/manifests/system-test-libctest.mf @@ -95,6 +95,9 @@ file path=opt/libc-tests/tests/nl_langinfo_test.$(ARCH) mode=0555 file path=opt/libc-tests/tests/nl_langinfo_test.$(ARCH64) mode=0555 file path=opt/libc-tests/tests/printf-6961.64 mode=0555 file path=opt/libc-tests/tests/priv_gettext mode=0555 +file path=opt/libc-tests/tests/psignal mode=0555 +file path=opt/libc-tests/tests/psignal-5097.32 mode=0555 +file path=opt/libc-tests/tests/psignal-5097.64 mode=0555 file path=opt/libc-tests/tests/pthread_attr_get_np mode=0555 file path=opt/libc-tests/tests/quick_exit mode=0555 file path=opt/libc-tests/tests/quick_exit_order.32 mode=0555 diff --git a/usr/src/test/libc-tests/runfiles/default.run b/usr/src/test/libc-tests/runfiles/default.run index 0119248c7e..149d696f03 100644 --- a/usr/src/test/libc-tests/runfiles/default.run +++ b/usr/src/test/libc-tests/runfiles/default.run @@ -74,6 +74,7 @@ timeout = 600 [/opt/libc-tests/tests/endian.32] [/opt/libc-tests/tests/endian.64] [/opt/libc-tests/tests/quick_exit] +[/opt/libc-tests/tests/psignal] [/opt/libc-tests/tests/printf-6961.64] [/opt/libc-tests/tests/priv_gettext] [/opt/libc-tests/tests/strerror] diff --git a/usr/src/test/libc-tests/tests/Makefile b/usr/src/test/libc-tests/tests/Makefile index 86d16c8d81..e9e15616d0 100644 --- a/usr/src/test/libc-tests/tests/Makefile +++ b/usr/src/test/libc-tests/tests/Makefile @@ -36,6 +36,7 @@ PROGS = \ call_once \ endian \ env-7076 \ + psignal-5097 \ quick_exit_order \ quick_exit_status \ strcoll-strxfrm-6907 \ @@ -45,7 +46,8 @@ PROGS = \ wcsncasecmp-7350 SCRIPTS = \ - quick_exit + quick_exit \ + psignal CPPFLAGS += -D_REENTRANT diff --git a/usr/src/test/libc-tests/tests/psignal-5097.c b/usr/src/test/libc-tests/tests/psignal-5097.c new file mode 100644 index 0000000000..cfed126bdf --- /dev/null +++ b/usr/src/test/libc-tests/tests/psignal-5097.c @@ -0,0 +1,38 @@ +/* + * This file and its contents are supplied under the terms of the + * Common Development and Distribution License ("CDDL"), version 1.0. + * You may only use this file in accordance with the terms of version + * 1.0 of the CDDL. + * + * A full copy of the text of the CDDL should have accompanied this + * source. A copy of the CDDL is also available via the Internet at + * http://www.illumos.org/license/CDDL. + */ + +/* + * Copyright 2016 Joyent, Inc. + */ + +/* + * psignal and psiginfo test cases. + */ + +#include <signal.h> +#include <strings.h> +#include <siginfo.h> + +int +main(void) +{ + struct siginfo sinfo; + + psignal(SIGSEGV, "hello world"); + psignal(SIGINFO, NULL); + + bzero(&sinfo, sizeof (struct siginfo)); + sinfo.si_signo = SIGSEGV; + psiginfo(&sinfo, "hello world"); + sinfo.si_signo = SIGINFO; + psiginfo(&sinfo, NULL); + return (0); +} diff --git a/usr/src/test/libc-tests/tests/psignal.ksh b/usr/src/test/libc-tests/tests/psignal.ksh new file mode 100644 index 0000000000..fc8e1a6205 --- /dev/null +++ b/usr/src/test/libc-tests/tests/psignal.ksh @@ -0,0 +1,59 @@ +#!/usr/bin/ksh +# +# This file and its contents are supplied under the terms of the +# Common Development and Distribution License ("CDDL"), version 1.0. +# You may only use this file in accordance with the terms of version +# 1.0 of the CDDL. +# +# A full copy of the text of the CDDL should have accompanied this +# source. A copy of the CDDL is also available via the Internet at +# http://www.illumos.org/license/CDDL. +# + +# +# Copyright 2016 Joyent, Inc. +# + +# +# Add regression tests for illumos#5079. Verify that psignal and +# psiginfo print what we expect to stderr. +# + +set -o errexit +set -o pipefail + +ps_root=$(dirname $0) +ps_sig32=$ps_root/psignal-5097.32 +ps_sig64=$ps_root/psignal-5097.64 +ps_out=/tmp/$(basename $0).$$ + +function fatal +{ + typeset msg="$*" + echo "Test Failed: $msg" >&2 + exit 1 +} + +function test_one +{ + typeset prog=$1 + typeset outfile=$ps_out.test + + $prog >/dev/null 2>$outfile || fatal "$prog unexpectedly failed" + diff $ps_out $outfile || fatal "$ps_out and $outfile differ " \ + "unexpectedly" + rm -f $outfile +} + +cat > $ps_out <<EOF +hello world: Segmentation Fault +Information Request +hello world : Segmentation Fault ( from process 0 ) +Information Request ( from process 0 ) +EOF + +[[ $? -ne 0 ]] && fatal "failed to set up output file" +test_one $ps_sig32 +test_one $ps_sig64 +rm -f $ps_out +exit 0 |
