summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorArtur Grabowski <art@cvs.openbsd.org>2002-07-12 13:31:21 +0000
committerArtur Grabowski <art@cvs.openbsd.org>2002-07-12 13:31:21 +0000
commit3dc8cff9e6875638e98e202b9d06bd6d4f1e59cc (patch)
tree5523026d8e026265fd71cf2cbfa77fbe69319db4 /sys
parentf90e7f70ccd22bbaedf27946aa5f0900fbdd01db (diff)
- Add a flags argument to dohooks.
The flag can be either HOOK_REMOVE or HOOK_REMOVE|HOOK_FREE. o HOOK_REMOVE removes the hook from the list before executing it. o HOOK_FREE frees the hook after that. - Let dostartuphooks use HOOK_REMOVE|HOOK_FREE so we can reclaim the memory. - Let doshutdownhooks use HOOK_REMOVE so that when some shutdown hook panics (they do that all the #@$%! time these days) we don't loop for ever. Don't HOOK_FREE, it doesn't matter and I don't want to add another possible panic condition for shutdown hooks. - Actually free the pointer we're throwing away in hook_disestablish (I wonder how much memory this has leaked over the years).
Diffstat (limited to 'sys')
-rw-r--r--sys/kern/kern_subr.c27
-rw-r--r--sys/netinet/in.c8
-rw-r--r--sys/sys/systm.h11
3 files changed, 29 insertions, 17 deletions
diff --git a/sys/kern/kern_subr.c b/sys/kern/kern_subr.c
index 6086806b1d3..0340d940069 100644
--- a/sys/kern/kern_subr.c
+++ b/sys/kern/kern_subr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kern_subr.c,v 1.21 2002/03/14 01:27:04 millert Exp $ */
+/* $OpenBSD: kern_subr.c,v 1.22 2002/07/12 13:31:20 art Exp $ */
/* $NetBSD: kern_subr.c,v 1.15 1996/04/09 17:21:56 ragge Exp $ */
/*
@@ -219,9 +219,9 @@ hook_disestablish(head, vhook)
struct hook_desc_head *head;
void *vhook;
{
-#ifdef DIAGNOSTIC
struct hook_desc *hdp;
+#ifdef DIAGNOSTIC
for (hdp = TAILQ_FIRST(head); hdp != NULL;
hdp = TAILQ_NEXT(hdp, hd_list))
if (hdp == vhook)
@@ -229,8 +229,9 @@ hook_disestablish(head, vhook)
if (hdp == NULL)
panic("hook_disestablish: hook not established");
#endif
-
- TAILQ_REMOVE(head, (struct hook_desc *)vhook, hd_list);
+ hdp = vhook;
+ TAILQ_REMOVE(head, hdp, hd_list);
+ free(hdp, M_DEVBUF);
}
/*
@@ -240,14 +241,22 @@ hook_disestablish(head, vhook)
* after crash dump done, etc.
*/
void
-dohooks(head)
- struct hook_desc_head *head;
+dohooks(struct hook_desc_head *head, int flags)
{
struct hook_desc *hdp;
- for (hdp = TAILQ_FIRST(head); hdp != NULL;
- hdp = TAILQ_NEXT(hdp, hd_list))
- (*hdp->hd_fn)(hdp->hd_arg);
+ if ((flags & HOOK_REMOVE) == 0) {
+ TAILQ_FOREACH(hdp, head, hd_list) {
+ (*hdp->hd_fn)(hdp->hd_arg);
+ }
+ } else {
+ while ((hdp = TAILQ_FIRST(head)) != NULL) {
+ TAILQ_REMOVE(head, hdp, hd_list);
+ (*hdp->hd_fn)(hdp->hd_arg);
+ if ((flags & HOOK_FREE) != 0)
+ free(hdp, M_DEVBUF);
+ }
+ }
}
/*
diff --git a/sys/netinet/in.c b/sys/netinet/in.c
index ac9c739454c..142848b69b2 100644
--- a/sys/netinet/in.c
+++ b/sys/netinet/in.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: in.c,v 1.27 2002/06/09 16:26:10 itojun Exp $ */
+/* $OpenBSD: in.c,v 1.28 2002/07/12 13:31:20 art Exp $ */
/* $NetBSD: in.c,v 1.26 1996/02/13 23:41:39 christos Exp $ */
/*
@@ -368,7 +368,7 @@ in_control(so, cmd, data, ifp)
case SIOCSIFADDR:
error = in_ifinit(ifp, ia, satosin(&ifr->ifr_addr), 1);
if (!error)
- dohooks(ifp->if_addrhooks);
+ dohooks(ifp->if_addrhooks, 0);
return error;
case SIOCSIFNETMASK:
@@ -408,7 +408,7 @@ in_control(so, cmd, data, ifp)
(ifra->ifra_broadaddr.sin_family == AF_INET))
ia->ia_broadaddr = ifra->ifra_broadaddr;
if (!error)
- dohooks(ifp->if_addrhooks);
+ dohooks(ifp->if_addrhooks, 0);
return (error);
case SIOCDIFADDR:
@@ -416,7 +416,7 @@ in_control(so, cmd, data, ifp)
TAILQ_REMOVE(&ifp->if_addrlist, (struct ifaddr *)ia, ifa_list);
TAILQ_REMOVE(&in_ifaddr, ia, ia_list);
IFAFREE((&ia->ia_ifa));
- dohooks(ifp->if_addrhooks);
+ dohooks(ifp->if_addrhooks, 0);
break;
#ifdef MROUTING
diff --git a/sys/sys/systm.h b/sys/sys/systm.h
index 08ace60243a..76eea53060f 100644
--- a/sys/sys/systm.h
+++ b/sys/sys/systm.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: systm.h,v 1.51 2002/07/06 19:14:20 nordin Exp $ */
+/* $OpenBSD: systm.h,v 1.52 2002/07/12 13:31:20 art Exp $ */
/* $NetBSD: systm.h,v 1.50 1996/06/09 04:55:09 briggs Exp $ */
/*-
@@ -254,19 +254,22 @@ extern struct hook_desc_head shutdownhook_list, startuphook_list;
void *hook_establish(struct hook_desc_head *, int, void (*)(void *), void *);
void hook_disestablish(struct hook_desc_head *, void *);
-void dohooks(struct hook_desc_head *);
+void dohooks(struct hook_desc_head *, int);
+
+#define HOOK_REMOVE 0x01
+#define HOOK_FREE 0x02
#define startuphook_establish(fn, arg) \
hook_establish(&startuphook_list, 1, (fn), (arg))
#define startuphook_disestablish(vhook) \
hook_disestablish(&startuphook_list, (vhook))
-#define dostartuphooks() dohooks(&startuphook_list)
+#define dostartuphooks() dohooks(&startuphook_list, HOOK_REMOVE|HOOK_FREE)
#define shutdownhook_establish(fn, arg) \
hook_establish(&shutdownhook_list, 0, (fn), (arg))
#define shutdownhook_disestablish(vhook) \
hook_disestablish(&shutdownhook_list, (vhook))
-#define doshutdownhooks() dohooks(&shutdownhook_list)
+#define doshutdownhooks() dohooks(&shutdownhook_list, HOOK_REMOVE)
/*
* Power management hooks.