From f49d8202560a777f033de1f50d0b3372c5a12fe7 Mon Sep 17 00:00:00 2001 From: Konstantin Belousov Date: Tue, 12 Jul 2011 20:37:18 +0000 Subject: [PATCH] Implement an RFTSIGZMB flag to rfork(2) to specify a signal that is delivered to parent when the child exists. Submitted by: Petr Salinger (Debian/kFreeBSD) MFC after: 1 week X-MFC-note: bump __FreeBSD_version --- sys/kern/kern_fork.c | 17 ++++++++++++++++- sys/sys/unistd.h | 8 ++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_fork.c b/sys/kern/kern_fork.c index a8abd8e86c83..9d3e22d224cf 100644 --- a/sys/kern/kern_fork.c +++ b/sys/kern/kern_fork.c @@ -476,7 +476,10 @@ do_fork(struct thread *td, int flags, struct proc *p2, struct thread *td2, sigacts_copy(newsigacts, p1->p_sigacts); p2->p_sigacts = newsigacts; } - if (flags & RFLINUXTHPN) + + if (flags & RFTSIGZMB) + p2->p_sigparent = RFTSIGNUM(flags); + else if (flags & RFLINUXTHPN) p2->p_sigparent = SIGUSR1; else p2->p_sigparent = SIGCHLD; @@ -719,10 +722,22 @@ fork1(struct thread *td, int flags, int pages, struct proc **procp) static int curfail; static struct timeval lastfail; + /* Check for the undefined or unimplemented flags. */ + if ((flags & ~(RFFLAGS | RFTSIGFLAGS(RFTSIGMASK))) != 0) + return (EINVAL); + + /* Signal value requires RFTSIGZMB. */ + if ((flags & RFTSIGFLAGS(RFTSIGMASK)) != 0 && (flags & RFTSIGZMB) == 0) + return (EINVAL); + /* Can't copy and clear. */ if ((flags & (RFFDG|RFCFDG)) == (RFFDG|RFCFDG)) return (EINVAL); + /* Check the validity of the signal number. */ + if ((flags & RFTSIGZMB) != 0 && (u_int)RFTSIGNUM(flags) > _SIG_MAXSIG) + return (EINVAL); + p1 = td->td_proc; /* diff --git a/sys/sys/unistd.h b/sys/sys/unistd.h index 378308de8204..9d56a3a42730 100644 --- a/sys/sys/unistd.h +++ b/sys/sys/unistd.h @@ -180,8 +180,16 @@ #define RFLINUXTHPN (1<<16) /* do linux clone exit parent notification */ #define RFSTOPPED (1<<17) /* leave child in a stopped state */ #define RFHIGHPID (1<<18) /* use a pid higher than 10 (idleproc) */ +#define RFTSIGZMB (1<<19) /* select signal for exit parent notification */ +#define RFTSIGSHIFT 20 /* selected signal number is in bits 20-27 */ +#define RFTSIGMASK 0xFF +#define RFTSIGNUM(flags) (((flags) >> RFTSIGSHIFT) & RFTSIGMASK) +#define RFTSIGFLAGS(signum) ((signum) << RFTSIGSHIFT) #define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */ #define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPPWAIT) +#define RFFLAGS (RFFDG | RFPROC | RFMEM | RFNOWAIT | RFCFDG | \ + RFTHREAD | RFSIGSHARE | RFLINUXTHPN | RFSTOPPED | RFHIGHPID | RFTSIGZMB | \ + RFPPWAIT) #endif /* __BSD_VISIBLE */