Date: Sat, 7 Sep 2002 02:20:03 -0700 From: Juli Mallett <jmallett@FreeBSD.org> To: freebsd-arch@FreeBSD.org Subject: CFR: signalinfo(3) Message-ID: <20020907022003.A66983@FreeBSD.org>
next in thread | raw e-mail | index | archive | help
--a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hey, I've been doing a bunch of signal related hackery tonight, adding a new signal, and testing things up and down, and I've run into something that irritated me a lot, and stalled me a number of times, to replicate a bit of code that I wasn't used to having to replicate. See, signal(3) installs handlers for the sa_handler variety of signal handlers, and yet this is not the only type of handler one might want to have, one might also want the "traditional" sa_sigaction handler style, which includes siginfo_t, and struct sigcontext, both of which are very useful, depending on the signal. So I wrote signalinfo(3) which installs *those* kinds of signal handlers, no fuss. And attached is a diff to libc, including minor modifications to signal(3)'s manual page, etc. I'd like to commit this pretty soon, so I can realistically look at providing sane means of doing a few things in the kernel, without it being impossible to write tiny little test cases on the fly. Plus I think others might find it useful, who knows. Thanks, juli. -- Juli Mallett <jmallett@FreeBSD.org> | FreeBSD: The Power To Serve Will break world for fulltime employment. | finger jmallett@FreeBSD.org --a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="signalinfo.diff" Index: signal.3 =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/signal.3,v retrieving revision 1.29 diff -d -u -r1.29 signal.3 --- signal.3 12 Jul 2002 01:30:18 -0000 1.29 +++ signal.3 7 Sep 2002 09:12:45 -0000 @@ -32,11 +32,11 @@ .\" @(#)signal.3 8.3 (Berkeley) 4/19/94 .\" $FreeBSD: src/lib/libc/gen/signal.3,v 1.29 2002/07/12 01:30:18 keramida Exp $ .\" -.Dd April 19, 1994 +.Dd September 6, 2002 .Dt SIGNAL 3 .Os .Sh NAME -.Nm signal +.Nm signal signalinfo .Nd simplified software signal facilities .Sh LIBRARY .Lb libc @@ -46,10 +46,13 @@ .\" fix it. .Ft void \*(lp* .Fn signal "int sig" "void \*(lp*func\*(rp\*(lpint\*(rp\*(rp\*(rp\*(lpint" +.Ft void \*(lp* +.Fn signalinfo "int sig" "void \*(lp*func\*(rp\*(lpint, siginfo_t *, struct sigcontext *\*(rp\*(rp\*(rp\*(lpint, siginfo_t *, struct sigcontext *\*(rp" .Pp or in .Fx Ns 's -equivalent but easier to read typedef'd version: +equivalent but easier to read typedef'd version of +.Nm .Ft typedef "void \*(lp*sig_t\*(rp \*(lpint\*(rp" .Ft sig_t .Fn signal "int sig" "sig_t func" @@ -60,6 +63,13 @@ is a simplified interface to the more general .Xr sigaction 2 facility. +The +.Fn signalinfo +facility is a simplified interface similar to the sighandler-specific +.Fn signal +facility, except that it is for full sigaction handlers, and sets the +.Dv SA_SIGINFO +.Em sa_flag . .Pp Signals allow the manipulation of a process from outside its domain as well as allowing the process to manipulate itself or @@ -241,3 +251,7 @@ .Fn signal facility appeared in .Bx 4.0 . +The +.Fn signalinfo +facility appreared in +.Fx 5.0 . Index: signal.c =================================================================== RCS file: /home/ncvs/src/lib/libc/gen/signal.c,v retrieving revision 1.3 diff -d -u -r1.3 signal.c --- signal.c 1 Feb 2002 00:57:29 -0000 1.3 +++ signal.c 7 Sep 2002 09:02:25 -0000 @@ -63,3 +63,20 @@ return (SIG_ERR); return (osa.sa_handler); } + +sig_t +signalinfo(s, a) + int s; + void (*a)(int, siginfo_t *, struct sigcontext *); +{ + struct sidaction sa, osa; + + sa.sa_sigaction = a; + sigemptyset(&sa.sa_mask); + sa.sa_flags = SA_SIGINFO; + if (!sigismember(&_sigintr, s)) + sa.sa_flags |= SA_RESTART; + if (_sigaction(s, &sa, &osa) < 0) + return (SIG_ERR); + return (osa.sa_sigaction); +} --a8Wt8u1KmwUX3Y2C-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020907022003.A66983>