Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145918700
D19058.id62564.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D19058.id62564.diff
View Options
Index: head/lib/libc/sys/rfork.2
===================================================================
--- head/lib/libc/sys/rfork.2
+++ head/lib/libc/sys/rfork.2
@@ -5,7 +5,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd July 12, 2011
+.Dd September 25, 2019
.Dt RFORK 2
.Os
.Sh NAME
@@ -34,7 +34,9 @@
The
.Fa flags
argument
-is the logical OR of some subset of:
+is either
+.Dv RFSPAWN
+or the logical OR of some subset of:
.Bl -tag -width ".Dv RFLINUXTHPN"
.It Dv RFPROC
If set a new process is created; otherwise changes affect the
@@ -103,6 +105,14 @@
File descriptors in a shared file descriptor table are kept
open until either they are explicitly closed
or all processes sharing the table exit.
+.Pp
+If
+.Dv RFSPAWN
+is passed,
+.Nm
+will use
+.Xr vfork 2
+semantics but reset all signal actions in the child to default.
.Pp
If
.Dv RFPROC
Index: head/sys/kern/kern_fork.c
===================================================================
--- head/sys/kern/kern_fork.c
+++ head/sys/kern/kern_fork.c
@@ -170,10 +170,18 @@
/* Don't allow kernel-only flags. */
if ((uap->flags & RFKERNELONLY) != 0)
return (EINVAL);
+ /* RFSPAWN must not appear with others */
+ if ((uap->flags & RFSPAWN) != 0 && uap->flags != RFSPAWN)
+ return (EINVAL);
AUDIT_ARG_FFLAGS(uap->flags);
bzero(&fr, sizeof(fr));
- fr.fr_flags = uap->flags;
+ if ((uap->flags & RFSPAWN) != 0) {
+ fr.fr_flags = RFFDG | RFPROC | RFPPWAIT | RFMEM;
+ fr.fr_flags2 = FR2_DROPSIG_CAUGHT;
+ } else {
+ fr.fr_flags = uap->flags;
+ }
fr.fr_pidp = &pid;
error = fork1(td, &fr);
if (error == 0) {
@@ -471,6 +479,11 @@
} else {
sigacts_copy(newsigacts, p1->p_sigacts);
p2->p_sigacts = newsigacts;
+ if ((fr->fr_flags2 & FR2_DROPSIG_CAUGHT) != 0) {
+ mtx_lock(&p2->p_sigacts->ps_mtx);
+ sig_drop_caught(p2);
+ mtx_unlock(&p2->p_sigacts->ps_mtx);
+ }
}
if (fr->fr_flags & RFTSIGZMB)
Index: head/sys/kern/kern_sig.c
===================================================================
--- head/sys/kern/kern_sig.c
+++ head/sys/kern/kern_sig.c
@@ -986,12 +986,7 @@
PROC_LOCK_ASSERT(p, MA_OWNED);
ps = p->p_sigacts;
mtx_lock(&ps->ps_mtx);
- while (SIGNOTEMPTY(ps->ps_sigcatch)) {
- sig = sig_ffs(&ps->ps_sigcatch);
- sigdflt(ps, sig);
- if ((sigprop(sig) & SIGPROP_IGNORE) != 0)
- sigqueue_delete_proc(p, sig);
- }
+ sig_drop_caught(p);
/*
* As CloudABI processes cannot modify signal handlers, fully
@@ -3856,4 +3851,21 @@
{
return (ps->ps_refcnt > 1);
+}
+
+void
+sig_drop_caught(struct proc *p)
+{
+ int sig;
+ struct sigacts *ps;
+
+ ps = p->p_sigacts;
+ PROC_LOCK_ASSERT(p, MA_OWNED);
+ mtx_assert(&ps->ps_mtx, MA_OWNED);
+ while (SIGNOTEMPTY(ps->ps_sigcatch)) {
+ sig = sig_ffs(&ps->ps_sigcatch);
+ sigdflt(ps, sig);
+ if ((sigprop(sig) & SIGPROP_IGNORE) != 0)
+ sigqueue_delete_proc(p, sig);
+ }
}
Index: head/sys/sys/proc.h
===================================================================
--- head/sys/sys/proc.h
+++ head/sys/sys/proc.h
@@ -1006,6 +1006,8 @@
int *fr_pd_fd;
int fr_pd_flags;
struct filecaps *fr_pd_fcaps;
+ int fr_flags2;
+#define FR2_DROPSIG_CAUGHT 0x00001 /* Drop caught non-DFL signals */
};
/*
Index: head/sys/sys/signalvar.h
===================================================================
--- head/sys/sys/signalvar.h
+++ head/sys/sys/signalvar.h
@@ -381,6 +381,7 @@
void sigacts_free(struct sigacts *ps);
struct sigacts *sigacts_hold(struct sigacts *ps);
int sigacts_shared(struct sigacts *ps);
+void sig_drop_caught(struct proc *p);
void sigexit(struct thread *td, int sig) __dead2;
int sigev_findtd(struct proc *p, struct sigevent *sigev, struct thread **);
int sig_ffs(sigset_t *set);
Index: head/sys/sys/unistd.h
===================================================================
--- head/sys/sys/unistd.h
+++ head/sys/sys/unistd.h
@@ -188,11 +188,14 @@
#define RFTSIGNUM(flags) (((flags) >> RFTSIGSHIFT) & RFTSIGMASK)
#define RFTSIGFLAGS(signum) ((signum) << RFTSIGSHIFT)
#define RFPROCDESC (1<<28) /* return a process descriptor */
-#define RFPPWAIT (1<<31) /* parent sleeps until child exits (vfork) */
+/* kernel: parent sleeps until child exits (vfork) */
+#define RFPPWAIT (1<<31)
+/* user: vfork(2) semantics, clear signals */
+#define RFSPAWN (1U<<31)
#define RFFLAGS (RFFDG | RFPROC | RFMEM | RFNOWAIT | RFCFDG | \
RFTHREAD | RFSIGSHARE | RFLINUXTHPN | RFSTOPPED | RFHIGHPID | RFTSIGZMB | \
- RFPROCDESC | RFPPWAIT)
-#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPPWAIT | RFPROCDESC)
+ RFPROCDESC | RFSPAWN | RFPPWAIT)
+#define RFKERNELONLY (RFSTOPPED | RFHIGHPID | RFPROCDESC)
#endif /* __BSD_VISIBLE */
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Feb 27, 4:10 AM (17 h, 53 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29013817
Default Alt Text
D19058.id62564.diff (4 KB)
Attached To
Mode
D19058: posix_spawn(3): handle potential signal issues with vfork
Attached
Detach File
Event Timeline
Log In to Comment