Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add "fork hooks", a'la "exec hooks" and "exit hooks" whi...
details: https://anonhg.NetBSD.org/src/rev/133c2f714dbd
branches: trunk
changeset: 542229:133c2f714dbd
user: thorpej <thorpej%NetBSD.org@localhost>
date: Fri Jan 24 01:42:52 2003 +0000
description:
Add "fork hooks", a'la "exec hooks" and "exit hooks" which allow
subsystems to do special processing to the parent and/or child at
fork time.
diffstat:
sys/kern/kern_fork.c | 10 ++++++++--
sys/kern/kern_subr.c | 35 +++++++++++++++++++++++++++++++++--
sys/sys/systm.h | 10 +++++++++-
3 files changed, 50 insertions(+), 5 deletions(-)
diffs (111 lines):
diff -r 8511e0b79fc1 -r 133c2f714dbd sys/kern/kern_fork.c
--- a/sys/kern/kern_fork.c Fri Jan 24 01:28:05 2003 +0000
+++ b/sys/kern/kern_fork.c Fri Jan 24 01:42:52 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_fork.c,v 1.105 2003/01/18 10:06:26 thorpej Exp $ */
+/* $NetBSD: kern_fork.c,v 1.106 2003/01/24 01:42:53 thorpej Exp $ */
/*-
* Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.105 2003/01/18 10:06:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_fork.c,v 1.106 2003/01/24 01:42:53 thorpej Exp $");
#include "opt_ktrace.h"
#include "opt_systrace.h"
@@ -376,6 +376,12 @@
(*p2->p_emul->e_proc_fork)(p2, p1);
/*
+ * ...and finally, any other random fork hooks that subsystems
+ * might have registered.
+ */
+ doforkhooks(p2, p1);
+
+ /*
* This begins the section where we must prevent the parent
* from being swapped.
*/
diff -r 8511e0b79fc1 -r 133c2f714dbd sys/kern/kern_subr.c
--- a/sys/kern/kern_subr.c Fri Jan 24 01:28:05 2003 +0000
+++ b/sys/kern/kern_subr.c Fri Jan 24 01:42:52 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_subr.c,v 1.95 2003/01/18 10:06:30 thorpej Exp $ */
+/* $NetBSD: kern_subr.c,v 1.96 2003/01/24 01:42:53 thorpej Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.95 2003/01/18 10:06:30 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_subr.c,v 1.96 2003/01/24 01:42:53 thorpej Exp $");
#include "opt_ddb.h"
#include "opt_md.h"
@@ -596,6 +596,37 @@
hook_proc_run(&exithook_list, p);
}
+hook_list_t forkhook_list;
+
+void *
+forkhook_establish(fn)
+ void (*fn) __P((struct proc *, struct proc *));
+{
+ return hook_establish(&forkhook_list, (void (*) __P((void *)))fn, NULL);
+}
+
+void
+forkhook_disestablish(vhook)
+ void *vhook;
+{
+ hook_disestablish(&forkhook_list, vhook);
+}
+
+/*
+ * Run fork hooks.
+ */
+void
+doforkhooks(p2, p1)
+ struct proc *p2, *p1;
+{
+ struct hook_desc *hd;
+
+ LIST_FOREACH(hd, &forkhook_list, hk_list) {
+ ((void (*) __P((struct proc *, struct proc *)))*hd->hk_fn)
+ (p2, p1);
+ }
+}
+
/*
* "Power hook" types, functions, and variables.
* The list of power hooks is kept ordered with the last registered hook
diff -r 8511e0b79fc1 -r 133c2f714dbd sys/sys/systm.h
--- a/sys/sys/systm.h Fri Jan 24 01:28:05 2003 +0000
+++ b/sys/sys/systm.h Fri Jan 24 01:42:52 2003 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: systm.h,v 1.156 2003/01/18 09:53:21 thorpej Exp $ */
+/* $NetBSD: systm.h,v 1.157 2003/01/24 01:42:52 thorpej Exp $ */
/*-
* Copyright (c) 1982, 1988, 1991, 1993
@@ -330,6 +330,14 @@
void doexithooks __P((struct proc *));
/*
+ * Fork hooks. Subsystems may want to do special processing when a process
+ * forks.
+ */
+void *forkhook_establish __P((void (*)(struct proc *, struct proc *)));
+void forkhook_disestablish __P((void *));
+void doforkhooks __P((struct proc *, struct proc *p));
+
+/*
* kernel syscall tracing/debugging hooks.
*/
int trace_enter __P((struct lwp *, register_t, register_t,
Home |
Main Index |
Thread Index |
Old Index