summaryrefslogtreecommitdiff
path: root/omapip/dispatch.c
diff options
context:
space:
mode:
authorShawn Routhier <sar@isc.org>2013-10-30 13:52:36 -0700
committerShawn Routhier <sar@isc.org>2013-10-30 13:52:36 -0700
commit47e8308dea6ee44ce19edf4fdf3331fa41a986f7 (patch)
treec2801fff3fff0639b504de72675ea62b0d1cab65 /omapip/dispatch.c
parent58cb5d861d6f412475722381723dc788c314c39f (diff)
downloadisc-dhcp-47e8308dea6ee44ce19edf4fdf3331fa41a986f7.tar.gz
[master]
[32692] Signal handlers added: sigint (ctrl-c) and sigterm (default kill)
Diffstat (limited to 'omapip/dispatch.c')
-rw-r--r--omapip/dispatch.c60
1 files changed, 53 insertions, 7 deletions
diff --git a/omapip/dispatch.c b/omapip/dispatch.c
index e6aae453..dcef3248 100644
--- a/omapip/dispatch.c
+++ b/omapip/dispatch.c
@@ -3,7 +3,7 @@
I/O dispatcher. */
/*
- * Copyright (c) 2004,2007-2009 by Internet Systems Consortium, Inc. ("ISC")
+ * Copyright (c) 2004,2007-2009,2013 by Internet Systems Consortium, Inc. ("ISC")
* Copyright (c) 1999-2003 by Internet Software Consortium
*
* Permission to use, copy, modify, and distribute this software for any
@@ -901,19 +901,65 @@ isc_result_t omapi_waiter_signal_handler (omapi_object_t *h,
return ISC_R_NOTFOUND;
}
+/** @brief calls a given function on every object
+ *
+ * @param func function to be called
+ * @param p parameter to be passed to each function instance
+ *
+ * @return result (ISC_R_SUCCESS if successful, error code otherwise)
+ */
isc_result_t omapi_io_state_foreach (isc_result_t (*func) (omapi_object_t *,
void *),
void *p)
{
- omapi_io_object_t *io;
+ omapi_io_object_t *io = NULL;
isc_result_t status;
+ omapi_io_object_t *next = NULL;
- for (io = omapi_io_states.next; io; io = io -> next) {
- if (io -> inner) {
- status = (*func) (io -> inner, p);
- if (status != ISC_R_SUCCESS)
- return status;
+ /*
+ * This just calls func on every inner object on the list. It would
+ * be much simpler in general case, but one of the operations could be
+ * release of the objects. Therefore we need to ref count the io and
+ * io->next pointers.
+ */
+
+ if (omapi_io_states.next) {
+ omapi_object_reference((omapi_object_t**)&io,
+ (omapi_object_t*)omapi_io_states.next,
+ MDL);
+ }
+
+ while(io) {
+ /* If there's a next object, save it */
+ if (io->next) {
+ omapi_object_reference((omapi_object_t**)&next,
+ (omapi_object_t*)io->next, MDL);
+ }
+ if (io->inner) {
+ status = (*func) (io->inner, p);
+ if (status != ISC_R_SUCCESS) {
+ /* Something went wrong. Let's stop using io & next pointer
+ * and bail out */
+ omapi_object_dereference((omapi_object_t**)&io, MDL);
+ if (next) {
+ omapi_object_dereference((omapi_object_t**)&next, MDL);
+ }
+ return status;
}
+ }
+ /* Update the io pointer and free the next pointer */
+ omapi_object_dereference((omapi_object_t**)&io, MDL);
+ if (next) {
+ omapi_object_reference((omapi_object_t**)&io,
+ (omapi_object_t*)next,
+ MDL);
+ omapi_object_dereference((omapi_object_t**)&next, MDL);
+ }
}
+
+ /*
+ * The only way to get here is when next is NULL. There's no need
+ * to dereference it.
+ */
return ISC_R_SUCCESS;
}