Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F145241726
D55288.id171932.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
3 KB
Referenced Files
None
Subscribers
None
D55288.id171932.diff
View Options
diff --git a/sys/kern/kern_procctl.c b/sys/kern/kern_procctl.c
--- a/sys/kern/kern_procctl.c
+++ b/sys/kern/kern_procctl.c
@@ -43,7 +43,6 @@
#include <sys/sx.h>
#include <sys/syscallsubr.h>
#include <sys/sysproto.h>
-#include <sys/taskqueue.h>
#include <sys/wait.h>
#include <vm/vm.h>
@@ -256,14 +255,12 @@
ksiginfo_t *ksi;
struct procctl_reaper_kill *rk;
int *error;
- struct task t;
};
static void
reap_kill_proc_locked(struct reap_kill_proc_work *w)
{
int error1;
- bool need_stop;
PROC_LOCK_ASSERT(w->target, MA_OWNED);
PROC_ASSERT_HELD(w->target);
@@ -277,47 +274,39 @@
return;
}
- /*
- * The need_stop indicates if the target process needs to be
- * suspended before being signalled. This is needed when we
- * guarantee that all processes in subtree are signalled,
- * avoiding the race with some process not yet fully linked
- * into all structures during fork, ignored by iterator, and
- * then escaping signalling.
- *
- * The thread cannot usefully stop itself anyway, and if other
- * thread of the current process forks while the current
- * thread signals the whole subtree, it is an application
- * race.
- */
- if ((w->target->p_flag & (P_KPROC | P_SYSTEM | P_STOPPED)) == 0)
- need_stop = thread_single(w->target, SINGLE_ALLPROC) == 0;
- else
- need_stop = false;
-
(void)pksignal(w->target, w->rk->rk_sig, w->ksi);
w->rk->rk_killed++;
*w->error = error1;
-
- if (need_stop)
- thread_single_end(w->target, SINGLE_ALLPROC);
}
static void
-reap_kill_proc_work(void *arg, int pending __unused)
+reap_kill_proc_work(struct reap_kill_proc_work *w)
{
- struct reap_kill_proc_work *w;
+ struct pgrp *pgrp;
+
+ PROC_LOCK_ASSERT(w->target, MA_OWNED);
+ PROC_ASSERT_HELD(w->target);
+
+ /* Sync with forks. */
+ for (;;) {
+ if ((w->target->p_flag2 & P2_WEXIT) != 0)
+ break;
+
+ pgrp = w->target->p_pgrp;
+ if (pgrp == NULL || sx_try_xlock(&pgrp->pg_killsx))
+ break;
+
+ PROC_UNLOCK(w->target);
+ /* This is safe because pgrp zone is nofree. */
+ sx_xlock(&pgrp->pg_killsx);
+ sx_xunlock(&pgrp->pg_killsx);
+ PROC_LOCK(w->target);
+ }
- w = arg;
- PROC_LOCK(w->target);
if ((w->target->p_flag2 & P2_WEXIT) == 0)
reap_kill_proc_locked(w);
- PROC_UNLOCK(w->target);
-
- sx_xlock(&proctree_lock);
- w->target = NULL;
- wakeup(&w->target);
- sx_xunlock(&proctree_lock);
+ if (pgrp != NULL)
+ sx_xunlock(&pgrp->pg_killsx);
}
struct reap_kill_tracker {
@@ -465,16 +454,8 @@
if ((p2->p_flag2 & P2_WEXIT) == 0) {
_PHOLD(p2);
p2->p_flag2 |= P2_REAPKILLED;
- PROC_UNLOCK(p2);
w->target = p2;
- taskqueue_enqueue(taskqueue_thread,
- &w->t);
- while (w->target != NULL) {
- sx_sleep(&w->target,
- &proctree_lock, PWAIT,
- "reapst", 0);
- }
- PROC_LOCK(p2);
+ reap_kill_proc_work(w);
_PRELE(p2);
}
PROC_UNLOCK(p2);
@@ -572,7 +553,6 @@
w.ksi = &ksi;
w.rk = rk;
w.error = &error;
- TASK_INIT(&w.t, 0, reap_kill_proc_work, &w);
reap_kill_subtree(td, p, reaper, &w);
crfree(w.cr);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Feb 18, 12:11 PM (14 h, 36 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
28776388
Default Alt Text
D55288.id171932.diff (3 KB)
Attached To
Mode
D55288: procctl(PROC_REAP_KILL): use pgrp pg_killsx sx to sync with fork
Attached
Detach File
Event Timeline
Log In to Comment