summaryrefslogtreecommitdiff
path: root/sys/kern
diff options
context:
space:
mode:
authorNiklas Hallqvist <niklas@cvs.openbsd.org>2001-07-27 09:55:09 +0000
committerNiklas Hallqvist <niklas@cvs.openbsd.org>2001-07-27 09:55:09 +0000
commit2c79e07d9d0b4ed47399ff2f19e7e620c0d22bb5 (patch)
treeea2f1f8609bffdb333048915106144a831973a11 /sys/kern
parentedcb7735c077d88259979d47cac926537a039def (diff)
Startup hooks. Can be used for providing root/swap devices from device
systems which want configuration to finish late, like I2O. Implemented via a general hooks mechanism which the shutdown hooks have been converted to use as well. It even has manpages!
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c4
-rw-r--r--sys/kern/kern_subr.c75
2 files changed, 40 insertions, 39 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 61f2ade8124..2f6d4da0e1e 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: init_main.c,v 1.72 2001/07/05 10:12:24 art Exp $ */
+/* $OpenBSD: init_main.c,v 1.73 2001/07/27 09:55:07 niklas Exp $ */
/* $NetBSD: init_main.c,v 1.84.4.1 1996/06/02 09:08:06 mrg Exp $ */
/*
@@ -360,6 +360,8 @@ main(framep)
/* Start the scheduler */
scheduler_start();
+ dostartuphooks();
+
/* Configure root/swap devices */
if (md_diskconf)
(*md_diskconf)();
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
index 69e9117c6e4..70b9dcecfe0 100644
--- a/sys/kern/kern_subr.c
+++ b/sys/kern/kern_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_subr.c,v 1.19 2001/06/27 04:49:45 art Exp $ */
+/* $OpenBSD: kern_subr.c,v 1.20 2001/07/27 09:55:07 niklas Exp $ */
/* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */
/*
@@ -183,72 +183,71 @@ hashinit(elements, type, flags, hashmask)
}
/*
- * "Shutdown hook" types, functions, and variables.
+ * "Shutdown/startup hook" types, functions, and variables.
*/
-struct shutdownhook_desc {
- LIST_ENTRY(shutdownhook_desc) sfd_list;
- void (*sfd_fn) __P((void *));
- void *sfd_arg;
-};
-
-LIST_HEAD(, shutdownhook_desc) shutdownhook_list;
-
-int shutdownhooks_done;
+struct hook_desc_head startuphook_list =
+ TAILQ_HEAD_INITIALIZER(startuphook_list);
+struct hook_desc_head shutdownhook_list =
+ TAILQ_HEAD_INITIALIZER(shutdownhook_list);
void *
-shutdownhook_establish(fn, arg)
+hook_establish(head, tail, fn, arg)
+ struct hook_desc_head *head;
+ int tail;
void (*fn) __P((void *));
void *arg;
{
- struct shutdownhook_desc *ndp;
+ struct hook_desc *hdp;
- ndp = (struct shutdownhook_desc *)
- malloc(sizeof (*ndp), M_DEVBUF, M_NOWAIT);
- if (ndp == NULL)
- return NULL;
+ hdp = (struct hook_desc *)malloc(sizeof (*hdp), M_DEVBUF, M_NOWAIT);
+ if (hdp == NULL)
+ return (NULL);
- ndp->sfd_fn = fn;
- ndp->sfd_arg = arg;
- LIST_INSERT_HEAD(&shutdownhook_list, ndp, sfd_list);
+ hdp->hd_fn = fn;
+ hdp->hd_arg = arg;
+ if (tail)
+ TAILQ_INSERT_TAIL(head, hdp, hd_list);
+ else
+ TAILQ_INSERT_HEAD(head, hdp, hd_list);
- return (ndp);
+ return (hdp);
}
void
-shutdownhook_disestablish(vhook)
+hook_disestablish(head, vhook)
+ struct hook_desc_head *head;
void *vhook;
{
#ifdef DIAGNOSTIC
- struct shutdownhook_desc *dp;
+ struct hook_desc *hdp;
- for (dp = shutdownhook_list.lh_first; dp != NULL;
- dp = dp->sfd_list.le_next)
- if (dp == vhook)
+ for (hdp = TAILQ_FIRST(head); hdp != NULL;
+ hdp = TAILQ_NEXT(hdp, hd_list))
+ if (hdp == vhook)
break;
- if (dp == NULL)
- panic("shutdownhook_disestablish: hook not established");
+ if (hdp == NULL)
+ panic("hook_disestablish: hook not established");
#endif
- LIST_REMOVE((struct shutdownhook_desc *)vhook, sfd_list);
+ TAILQ_REMOVE(head, (struct hook_desc *)vhook, hd_list);
}
/*
- * Run shutdown hooks. Should be invoked immediately before the
+ * Run hooks. Startup hooks are invoked right after scheduler_start but
+ * before root is mounted. Shutdown hooks are invoked immediately before the
* system is halted or rebooted, i.e. after file systems unmounted,
* after crash dump done, etc.
*/
void
-doshutdownhooks()
+dohooks(head)
+ struct hook_desc_head *head;
{
- struct shutdownhook_desc *dp;
-
- if (shutdownhooks_done)
- return;
+ struct hook_desc *hdp;
- for (dp = shutdownhook_list.lh_first; dp != NULL; dp =
- dp->sfd_list.le_next)
- (*dp->sfd_fn)(dp->sfd_arg);
+ for (hdp = TAILQ_FIRST(head); hdp != NULL;
+ hdp = TAILQ_NEXT(hdp, hd_list))
+ (*hdp->hd_fn)(hdp->hd_arg);
}
/*