From: Ricardo Branco Subject: Re: [PATCH]: Add missing POSIX psiginfo(3) call To: tech@openbsd.org Date: Thu, 7 Aug 2025 00:43:09 +0200 Attached patch following Philip Guenther's suggestion. For now a simple implementation should be enough until a better implementation can be agreed for all *BSD. Best, From c29830f974c73e9bd61956858b832e0cab54f1ca Mon Sep 17 00:00:00 2001 From: Ricardo Branco Date: Wed, 16 Apr 2025 10:16:13 +0200 Subject: [PATCH] Add POSIX psiginfo(3) call --- include/signal.h | 1 + lib/libc/Symbols.list | 1 + lib/libc/gen/Makefile.inc | 4 ++-- lib/libc/gen/psiginfo.c | 42 +++++++++++++++++++++++++++++++++++++++ lib/libc/gen/psignal.3 | 21 +++++++++++++++++++- lib/libc/gen/psignal.c | 1 + lib/libc/hidden/signal.h | 3 ++- 7 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 lib/libc/gen/psiginfo.c diff --git a/include/signal.h b/include/signal.h index 07982bd75a1..7506ef0fbe7 100644 --- a/include/signal.h +++ b/include/signal.h @@ -132,6 +132,7 @@ int thrkill(pid_t _tid, int _signum, void *_tcb); int sigwait(const sigset_t *__restrict, int *__restrict); #endif #if __BSD_VISIBLE || __POSIX_VISIBLE >= 200809 +void psiginfo(const siginfo_t *, const char *); void psignal(unsigned int, const char *); #endif #endif /* __BSD_VISIBLE || __POSIX_VISIBLE || __XPG_VISIBLE */ diff --git a/lib/libc/Symbols.list b/lib/libc/Symbols.list index 7b1dbdeca69..12e04f89fb4 100644 --- a/lib/libc/Symbols.list +++ b/lib/libc/Symbols.list @@ -745,6 +745,7 @@ posix_spawnattr_setschedpolicy posix_spawnattr_setsigdefault posix_spawnattr_setsigmask posix_spawnp +psiginfo psignal pw_dup raise diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index f87cc7a89e5..4b82d1e645c 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -14,8 +14,8 @@ SRCS+= alarm.c assert.c auth_subr.c authenticate.c \ getloadavg.c getlogin.c getmntinfo.c getnetgrent.c getpagesize.c \ getprogname.c getpwent.c getttyent.c getusershell.c glob.c \ initgroups.c isatty.c isctype.c isfdtype.c isfinite.c isinf.c \ - isnan.c isnormal.c signbit.c lockf.c login_cap.c nice.c \ - nlist.c nftw.c opendir.c pause.c popen.c posix_spawn.c psignal.c \ + isnan.c isnormal.c signbit.c lockf.c login_cap.c nice.c nlist.c \ + nftw.c opendir.c pause.c popen.c posix_spawn.c psignal.c psiginfo.c \ pw_dup.c pwcache.c raise.c readdir.c readdir_r.c readpassphrase.c \ rewinddir.c scandir.c seekdir.c setdomainname.c sethostname.c \ setprogname.c setmode.c setproctitle.c shm_open.c \ diff --git a/lib/libc/gen/psiginfo.c b/lib/libc/gen/psiginfo.c new file mode 100644 index 00000000000..65ab516499c --- /dev/null +++ b/lib/libc/gen/psiginfo.c @@ -0,0 +1,42 @@ +/* $OpenBSD */ +/* + * Copyright (c) 1983, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +/* + * Print the signal information + * along with the supplied message. + */ +#include +#include + +void +psiginfo(const siginfo_t *si, const char *s) +{ + psignal(si->si_signo, s); +} diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3 index 3fd2ebbf7bf..015e968a107 100644 --- a/lib/libc/gen/psignal.3 +++ b/lib/libc/gen/psignal.3 @@ -27,11 +27,12 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: May 16 2019 $ +.Dd $Mdocdate: Apr 16 2025 $ .Dt PSIGNAL 3 .Os .Sh NAME .Nm psignal , +.Nm psiginfo , .Nm sys_siglist , .Nm sys_signame .Nd system signal messages @@ -39,6 +40,7 @@ .In signal.h .Ft void .Fn psignal "unsigned int sig" "const char *s" +.Fn psiginfo "const siginfo_t *si" "const char *s" .Vt extern char *sys_siglist[]; .Vt extern char *sys_signame[]; .Sh DESCRIPTION @@ -64,6 +66,16 @@ the string .Dq Unknown signal is produced. .Pp +The +.Fn psiginfo +function is similar to +.Fn psignal , +except that the signal number information is taken from the +.Fa si +argument which is a +.Vt siginfo_t +structure. +.Pp The message strings can be accessed directly using the external array .Va sys_siglist , indexed by recognized signal numbers. @@ -87,6 +99,13 @@ The .Fn psignal function appeared in .Bx 4.2 . +The +.Fn psiginfo +function appeared in +.Fx 15.0 , +.Nx 6.0 , +and +.Dx 4.1 . .Sh CAVEATS On systems other than .Ox , diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index dca921d5a5a..6863d7cc05e 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -61,3 +61,4 @@ psignal(unsigned int sig, const char *s) iov[niov+1].iov_len = 1; (void)writev(STDERR_FILENO, iov, niov+2); } +DEF_WEAK(psignal); diff --git a/lib/libc/hidden/signal.h b/lib/libc/hidden/signal.h index 7fdfcef7532..7fff33ee352 100644 --- a/lib/libc/hidden/signal.h +++ b/lib/libc/hidden/signal.h @@ -52,7 +52,8 @@ PROTO_NORMAL(__errno); PROTO_DEPRECATED(bsd_signal); PROTO_NORMAL(kill); /* wrap to ban SIGTHR? */ PROTO_DEPRECATED(killpg); -PROTO_DEPRECATED(psignal); +PROTO_DEPRECATED(psiginfo); +PROTO_NORMAL(psignal); PROTO_DEPRECATED(pthread_sigmask); PROTO_NORMAL(raise); PROTO_WRAP(sigaction); -- 2.50.1