1999-09-02 00:32:56 +00:00
|
|
|
/* dispatch.c
|
|
|
|
|
|
|
|
I/O dispatcher. */
|
|
|
|
|
|
|
|
/*
|
2008-01-24 02:43:06 +00:00
|
|
|
* Copyright (c) 2004,2007-2008 by Internet Systems Consortium, Inc. ("ISC")
|
2005-03-17 20:15:29 +00:00
|
|
|
* Copyright (c) 1999-2003 by Internet Software Consortium
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose with or without fee is hereby granted, provided that the above
|
|
|
|
* copyright notice and this permission notice appear in all copies.
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
|
|
|
|
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
|
|
|
|
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
|
|
|
|
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
1999-09-02 00:32:56 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* Internet Systems Consortium, Inc.
|
|
|
|
* 950 Charter Street
|
|
|
|
* Redwood City, CA 94063
|
|
|
|
* <info@isc.org>
|
|
|
|
* http://www.isc.org/
|
2000-03-17 04:00:32 +00:00
|
|
|
*
|
2005-03-17 20:15:29 +00:00
|
|
|
* This software has been written for Internet Systems Consortium
|
2000-03-17 04:00:32 +00:00
|
|
|
* by Ted Lemon in cooperation with Vixie Enterprises and Nominum, Inc.
|
2005-03-17 20:15:29 +00:00
|
|
|
* To learn more about Internet Systems Consortium, see
|
2000-03-17 04:00:32 +00:00
|
|
|
* ``http://www.isc.org/''. To learn more about Vixie Enterprises,
|
|
|
|
* see ``http://www.vix.com''. To learn more about Nominum, Inc., see
|
|
|
|
* ``http://www.nominum.com''.
|
1999-09-02 00:32:56 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-19 18:47:15 +00:00
|
|
|
#include "dhcpd.h"
|
|
|
|
|
1999-10-08 03:43:15 +00:00
|
|
|
#include <omapip/omapip_p.h>
|
2007-07-13 06:43:43 +00:00
|
|
|
#include <sys/time.h>
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
static omapi_io_object_t omapi_io_states;
|
2008-01-03 00:30:14 +00:00
|
|
|
struct timeval cur_tv;
|
1999-09-02 00:32:56 +00:00
|
|
|
|
2008-01-21 19:53:21 +00:00
|
|
|
struct eventqueue *rw_queue_empty;
|
|
|
|
|
2000-05-16 23:03:49 +00:00
|
|
|
OMAPI_OBJECT_ALLOC (omapi_io,
|
|
|
|
omapi_io_object_t, omapi_type_io_object)
|
|
|
|
OMAPI_OBJECT_ALLOC (omapi_waiter,
|
|
|
|
omapi_waiter_object_t, omapi_type_waiter)
|
|
|
|
|
2008-01-21 19:53:21 +00:00
|
|
|
void
|
|
|
|
register_eventhandler(struct eventqueue **queue, void (*handler)(void *))
|
|
|
|
{
|
|
|
|
struct eventqueue *t, *q;
|
|
|
|
|
|
|
|
/* traverse to end of list */
|
|
|
|
t = NULL;
|
|
|
|
for (q = *queue ; q ; q = q->next) {
|
|
|
|
if (q->handler == handler)
|
|
|
|
return; /* handler already registered */
|
|
|
|
t = q;
|
|
|
|
}
|
|
|
|
|
|
|
|
q = ((struct eventqueue *)dmalloc(sizeof(struct eventqueue), MDL));
|
|
|
|
if (!q)
|
|
|
|
log_fatal("register_eventhandler: no memory!");
|
|
|
|
memset(q, 0, sizeof *q);
|
|
|
|
if (t)
|
|
|
|
t->next = q;
|
|
|
|
else
|
|
|
|
*queue = q;
|
|
|
|
q->handler = handler;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
unregister_eventhandler(struct eventqueue **queue, void (*handler)(void *))
|
|
|
|
{
|
|
|
|
struct eventqueue *t, *q;
|
|
|
|
|
|
|
|
/* traverse to end of list */
|
|
|
|
t= NULL;
|
|
|
|
for (q = *queue ; q ; q = q->next) {
|
|
|
|
if (q->handler == handler) {
|
|
|
|
if (t)
|
|
|
|
t->next = q->next;
|
|
|
|
else
|
|
|
|
*queue = q->next;
|
|
|
|
dfree(q, MDL); /* Don't access q after this!*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
t = q;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
trigger_event(struct eventqueue **queue)
|
|
|
|
{
|
|
|
|
struct eventqueue *q;
|
|
|
|
|
|
|
|
for (q=*queue ; q ; q=q->next) {
|
|
|
|
if (q->handler)
|
|
|
|
(*q->handler)(NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-02 00:32:56 +00:00
|
|
|
/* Register an I/O handle so that we can do asynchronous I/O on it. */
|
|
|
|
|
|
|
|
isc_result_t omapi_register_io_object (omapi_object_t *h,
|
|
|
|
int (*readfd) (omapi_object_t *),
|
|
|
|
int (*writefd) (omapi_object_t *),
|
|
|
|
isc_result_t (*reader)
|
|
|
|
(omapi_object_t *),
|
|
|
|
isc_result_t (*writer)
|
|
|
|
(omapi_object_t *),
|
|
|
|
isc_result_t (*reaper)
|
|
|
|
(omapi_object_t *))
|
|
|
|
{
|
|
|
|
isc_result_t status;
|
|
|
|
omapi_io_object_t *obj, *p;
|
|
|
|
|
|
|
|
/* omapi_io_states is a static object. If its reference count
|
|
|
|
is zero, this is the first I/O handle to be registered, so
|
|
|
|
we need to initialize it. Because there is no inner or outer
|
|
|
|
pointer on this object, and we're setting its refcnt to 1, it
|
|
|
|
will never be freed. */
|
|
|
|
if (!omapi_io_states.refcnt) {
|
|
|
|
omapi_io_states.refcnt = 1;
|
|
|
|
omapi_io_states.type = omapi_type_io_object;
|
|
|
|
}
|
|
|
|
|
2000-05-16 23:03:49 +00:00
|
|
|
obj = (omapi_io_object_t *)0;
|
|
|
|
status = omapi_io_allocate (&obj, MDL);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-02 00:32:56 +00:00
|
|
|
|
2000-01-26 14:56:18 +00:00
|
|
|
status = omapi_object_reference (&obj -> inner, h, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_dereference (&obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
2000-01-26 14:56:18 +00:00
|
|
|
status = omapi_object_reference (&h -> outer,
|
|
|
|
(omapi_object_t *)obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_dereference (&obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Find the last I/O state, if there are any. */
|
|
|
|
for (p = omapi_io_states.next;
|
|
|
|
p && p -> next; p = p -> next)
|
|
|
|
;
|
|
|
|
if (p)
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_reference (&p -> next, obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
else
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_reference (&omapi_io_states.next, obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
obj -> readfd = readfd;
|
|
|
|
obj -> writefd = writefd;
|
|
|
|
obj -> reader = reader;
|
|
|
|
obj -> writer = writer;
|
|
|
|
obj -> reaper = reaper;
|
2008-03-18 18:28:14 +00:00
|
|
|
|
|
|
|
omapi_io_dereference(&obj, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2000-05-03 06:15:31 +00:00
|
|
|
isc_result_t omapi_unregister_io_object (omapi_object_t *h)
|
|
|
|
{
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_object_t *p, *obj, *last, *ph;
|
2000-05-03 06:15:31 +00:00
|
|
|
|
2000-05-16 23:03:49 +00:00
|
|
|
if (!h -> outer || h -> outer -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
2000-05-03 06:15:31 +00:00
|
|
|
obj = (omapi_io_object_t *)h -> outer;
|
2000-05-16 23:03:49 +00:00
|
|
|
ph = (omapi_io_object_t *)0;
|
|
|
|
omapi_io_reference (&ph, obj, MDL);
|
2000-05-03 06:15:31 +00:00
|
|
|
|
|
|
|
/* remove from the list of I/O states */
|
2000-07-10 17:03:38 +00:00
|
|
|
last = &omapi_io_states;
|
2000-05-03 06:15:31 +00:00
|
|
|
for (p = omapi_io_states.next; p; p = p -> next) {
|
2000-05-16 23:03:49 +00:00
|
|
|
if (p == obj) {
|
|
|
|
omapi_io_dereference (&last -> next, MDL);
|
|
|
|
omapi_io_reference (&last -> next, p -> next, MDL);
|
2000-05-03 06:15:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
last = p;
|
|
|
|
}
|
|
|
|
if (obj -> next)
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_dereference (&obj -> next, MDL);
|
|
|
|
|
2000-05-03 06:15:31 +00:00
|
|
|
if (obj -> outer) {
|
|
|
|
if (obj -> outer -> inner == (omapi_object_t *)obj)
|
|
|
|
omapi_object_dereference (&obj -> outer -> inner,
|
|
|
|
MDL);
|
|
|
|
omapi_object_dereference (&obj -> outer, MDL);
|
|
|
|
}
|
|
|
|
omapi_object_dereference (&obj -> inner, MDL);
|
|
|
|
omapi_object_dereference (&h -> outer, MDL);
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_io_dereference (&ph, MDL);
|
2000-05-03 06:15:31 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-02 00:32:56 +00:00
|
|
|
isc_result_t omapi_dispatch (struct timeval *t)
|
|
|
|
{
|
|
|
|
return omapi_wait_for_completion ((omapi_object_t *)&omapi_io_states,
|
|
|
|
t);
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_wait_for_completion (omapi_object_t *object,
|
|
|
|
struct timeval *t)
|
|
|
|
{
|
|
|
|
isc_result_t status;
|
|
|
|
omapi_waiter_object_t *waiter;
|
|
|
|
omapi_object_t *inner;
|
|
|
|
|
|
|
|
if (object) {
|
2000-05-16 23:03:49 +00:00
|
|
|
waiter = (omapi_waiter_object_t *)0;
|
|
|
|
status = omapi_waiter_allocate (&waiter, MDL);
|
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
/* Paste the waiter object onto the inner object we're
|
|
|
|
waiting on. */
|
|
|
|
for (inner = object; inner -> inner; inner = inner -> inner)
|
|
|
|
;
|
|
|
|
|
2000-01-26 14:56:18 +00:00
|
|
|
status = omapi_object_reference (&waiter -> outer, inner, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_waiter_dereference (&waiter, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
status = omapi_object_reference (&inner -> inner,
|
|
|
|
(omapi_object_t *)waiter,
|
2000-01-26 14:56:18 +00:00
|
|
|
MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS) {
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_waiter_dereference (&waiter, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
return status;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
waiter = (omapi_waiter_object_t *)0;
|
|
|
|
|
|
|
|
do {
|
1999-10-08 03:43:15 +00:00
|
|
|
status = omapi_one_dispatch ((omapi_object_t *)waiter, t);
|
1999-09-02 00:32:56 +00:00
|
|
|
if (status != ISC_R_SUCCESS)
|
|
|
|
return status;
|
|
|
|
} while (!waiter || !waiter -> ready);
|
|
|
|
|
1999-09-09 21:08:28 +00:00
|
|
|
if (waiter -> outer) {
|
|
|
|
if (waiter -> outer -> inner) {
|
|
|
|
omapi_object_dereference (&waiter -> outer -> inner,
|
2000-01-26 14:56:18 +00:00
|
|
|
MDL);
|
1999-09-09 21:08:28 +00:00
|
|
|
if (waiter -> inner)
|
|
|
|
omapi_object_reference
|
|
|
|
(&waiter -> outer -> inner,
|
2000-01-26 14:56:18 +00:00
|
|
|
waiter -> inner, MDL);
|
1999-09-09 21:08:28 +00:00
|
|
|
}
|
2000-01-26 14:56:18 +00:00
|
|
|
omapi_object_dereference (&waiter -> outer, MDL);
|
1999-09-09 21:08:28 +00:00
|
|
|
}
|
|
|
|
if (waiter -> inner)
|
2000-01-26 14:56:18 +00:00
|
|
|
omapi_object_dereference (&waiter -> inner, MDL);
|
1999-09-09 21:08:28 +00:00
|
|
|
|
2000-08-03 21:00:41 +00:00
|
|
|
status = waiter -> waitstatus;
|
2000-05-16 23:03:49 +00:00
|
|
|
omapi_waiter_dereference (&waiter, MDL);
|
2001-05-02 07:00:30 +00:00
|
|
|
return status;
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
1999-10-08 03:43:15 +00:00
|
|
|
isc_result_t omapi_one_dispatch (omapi_object_t *wo,
|
1999-09-02 00:32:56 +00:00
|
|
|
struct timeval *t)
|
|
|
|
{
|
2008-01-21 19:53:21 +00:00
|
|
|
fd_set r, w, x, rr, ww, xx;
|
1999-09-02 00:32:56 +00:00
|
|
|
int max = 0;
|
|
|
|
int count;
|
|
|
|
int desc;
|
|
|
|
struct timeval now, to;
|
2008-03-18 18:28:14 +00:00
|
|
|
omapi_io_object_t *io, *prev, *next;
|
1999-10-08 03:43:15 +00:00
|
|
|
omapi_waiter_object_t *waiter;
|
2000-05-03 06:15:31 +00:00
|
|
|
omapi_object_t *tmp = (omapi_object_t *)0;
|
1999-10-08 03:43:15 +00:00
|
|
|
|
|
|
|
if (!wo || wo -> type != omapi_type_waiter)
|
|
|
|
waiter = (omapi_waiter_object_t *)0;
|
|
|
|
else
|
|
|
|
waiter = (omapi_waiter_object_t *)wo;
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
FD_ZERO (&x);
|
|
|
|
|
|
|
|
/* First, see if the timeout has expired, and if so return. */
|
|
|
|
if (t) {
|
|
|
|
gettimeofday (&now, (struct timezone *)0);
|
2008-01-03 00:30:14 +00:00
|
|
|
cur_tv.tv_sec = now.tv_sec;
|
|
|
|
cur_tv.tv_usec = now.tv_usec;
|
1999-09-02 00:32:56 +00:00
|
|
|
if (now.tv_sec > t -> tv_sec ||
|
|
|
|
(now.tv_sec == t -> tv_sec && now.tv_usec >= t -> tv_usec))
|
|
|
|
return ISC_R_TIMEDOUT;
|
|
|
|
|
|
|
|
/* We didn't time out, so figure out how long until
|
|
|
|
we do. */
|
|
|
|
to.tv_sec = t -> tv_sec - now.tv_sec;
|
|
|
|
to.tv_usec = t -> tv_usec - now.tv_usec;
|
|
|
|
if (to.tv_usec < 0) {
|
|
|
|
to.tv_usec += 1000000;
|
|
|
|
to.tv_sec--;
|
|
|
|
}
|
2000-11-01 23:59:57 +00:00
|
|
|
|
|
|
|
/* It is possible for the timeout to get set larger than
|
|
|
|
the largest time select() is willing to accept.
|
|
|
|
Restricting the timeout to a maximum of one day should
|
|
|
|
work around this. -DPN. (Ref: Bug #416) */
|
|
|
|
if (to.tv_sec > (60 * 60 * 24))
|
|
|
|
to.tv_sec = 60 * 60 * 24;
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* If the object we're waiting on has reached completion,
|
|
|
|
return now. */
|
|
|
|
if (waiter && waiter -> ready)
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
|
2000-06-20 20:30:27 +00:00
|
|
|
again:
|
1999-09-02 00:32:56 +00:00
|
|
|
/* If we have no I/O state, we can't proceed. */
|
|
|
|
if (!(io = omapi_io_states.next))
|
|
|
|
return ISC_R_NOMORE;
|
|
|
|
|
|
|
|
/* Set up the read and write masks. */
|
|
|
|
FD_ZERO (&r);
|
|
|
|
FD_ZERO (&w);
|
|
|
|
|
|
|
|
for (; io; io = io -> next) {
|
|
|
|
/* Check for a read socket. If we shouldn't be
|
|
|
|
trying to read for this I/O object, either there
|
|
|
|
won't be a readfd function, or it'll return -1. */
|
2000-06-06 23:47:27 +00:00
|
|
|
if (io -> readfd && io -> inner &&
|
1999-09-02 00:32:56 +00:00
|
|
|
(desc = (*(io -> readfd)) (io -> inner)) >= 0) {
|
|
|
|
FD_SET (desc, &r);
|
|
|
|
if (desc > max)
|
|
|
|
max = desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Same deal for write fdets. */
|
2000-06-06 23:47:27 +00:00
|
|
|
if (io -> writefd && io -> inner &&
|
1999-09-02 00:32:56 +00:00
|
|
|
(desc = (*(io -> writefd)) (io -> inner)) >= 0) {
|
|
|
|
FD_SET (desc, &w);
|
|
|
|
if (desc > max)
|
|
|
|
max = desc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-01-21 19:53:21 +00:00
|
|
|
/* poll if all reader are dry */
|
|
|
|
now.tv_sec = 0;
|
|
|
|
now.tv_usec = 0;
|
|
|
|
rr=r;
|
|
|
|
ww=w;
|
|
|
|
xx=x;
|
|
|
|
|
|
|
|
/* poll once */
|
|
|
|
count = select(max + 1, &r, &w, &x, &now);
|
|
|
|
if (!count) {
|
|
|
|
/* We are dry now */
|
|
|
|
trigger_event(&rw_queue_empty);
|
|
|
|
/* Wait for a packet or a timeout... XXX */
|
|
|
|
count = select(max + 1, &rr, &ww, &xx, t ? &to : NULL);
|
|
|
|
}
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
/* Get the current time... */
|
2008-01-03 00:30:14 +00:00
|
|
|
gettimeofday (&cur_tv, (struct timezone *)0);
|
1999-09-02 00:32:56 +00:00
|
|
|
|
2000-06-20 20:30:27 +00:00
|
|
|
/* We probably have a bad file descriptor. Figure out which one.
|
|
|
|
When we find it, call the reaper function on it, which will
|
|
|
|
maybe make it go away, and then try again. */
|
|
|
|
if (count < 0) {
|
|
|
|
struct timeval t0;
|
2001-04-20 19:23:45 +00:00
|
|
|
omapi_io_object_t *prev = (omapi_io_object_t *)0;
|
|
|
|
io = (omapi_io_object_t *)0;
|
|
|
|
if (omapi_io_states.next)
|
|
|
|
omapi_io_reference (&io, omapi_io_states.next, MDL);
|
2000-06-20 20:30:27 +00:00
|
|
|
|
2001-04-20 19:23:45 +00:00
|
|
|
while (io) {
|
2000-06-20 20:30:27 +00:00
|
|
|
omapi_object_t *obj;
|
|
|
|
FD_ZERO (&r);
|
|
|
|
FD_ZERO (&w);
|
|
|
|
t0.tv_sec = t0.tv_usec = 0;
|
|
|
|
|
|
|
|
if (io -> readfd && io -> inner &&
|
|
|
|
(desc = (*(io -> readfd)) (io -> inner)) >= 0) {
|
|
|
|
FD_SET (desc, &r);
|
|
|
|
count = select (desc + 1, &r, &w, &x, &t0);
|
|
|
|
bogon:
|
|
|
|
if (count < 0) {
|
|
|
|
log_error ("Bad descriptor %d.", desc);
|
|
|
|
for (obj = (omapi_object_t *)io;
|
|
|
|
obj -> outer;
|
|
|
|
obj = obj -> outer)
|
|
|
|
;
|
2000-09-12 21:53:15 +00:00
|
|
|
for (; obj; obj = obj -> inner) {
|
|
|
|
omapi_value_t *ov;
|
|
|
|
int len;
|
|
|
|
const char *s;
|
|
|
|
ov = (omapi_value_t *)0;
|
|
|
|
omapi_get_value_str (obj,
|
|
|
|
(omapi_object_t *)0,
|
|
|
|
"name", &ov);
|
|
|
|
if (ov && ov -> value &&
|
|
|
|
(ov -> value -> type ==
|
|
|
|
omapi_datatype_string)) {
|
|
|
|
s = (char *)
|
|
|
|
ov -> value -> u.buffer.value;
|
|
|
|
len = ov -> value -> u.buffer.len;
|
|
|
|
} else {
|
|
|
|
s = "";
|
|
|
|
len = 0;
|
|
|
|
}
|
|
|
|
log_error ("Object %lx %s%s%.*s",
|
|
|
|
(unsigned long)obj,
|
|
|
|
obj -> type -> name,
|
|
|
|
len ? " " : "",
|
|
|
|
len, s);
|
|
|
|
if (len)
|
|
|
|
omapi_value_dereference (&ov, MDL);
|
|
|
|
}
|
2005-03-17 20:15:29 +00:00
|
|
|
(*(io -> reaper)) (io -> inner);
|
2001-04-20 19:23:45 +00:00
|
|
|
if (prev) {
|
|
|
|
omapi_io_dereference (&prev -> next, MDL);
|
|
|
|
if (io -> next)
|
|
|
|
omapi_io_reference (&prev -> next,
|
|
|
|
io -> next, MDL);
|
|
|
|
} else {
|
|
|
|
omapi_io_dereference
|
|
|
|
(&omapi_io_states.next, MDL);
|
|
|
|
if (io -> next)
|
|
|
|
omapi_io_reference
|
|
|
|
(&omapi_io_states.next,
|
|
|
|
io -> next, MDL);
|
|
|
|
}
|
|
|
|
omapi_io_dereference (&io, MDL);
|
2000-06-20 20:30:27 +00:00
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FD_ZERO (&r);
|
|
|
|
FD_ZERO (&w);
|
|
|
|
t0.tv_sec = t0.tv_usec = 0;
|
|
|
|
|
|
|
|
/* Same deal for write fdets. */
|
|
|
|
if (io -> writefd && io -> inner &&
|
|
|
|
(desc = (*(io -> writefd)) (io -> inner)) >= 0) {
|
|
|
|
FD_SET (desc, &w);
|
|
|
|
count = select (desc + 1, &r, &w, &x, &t0);
|
|
|
|
if (count < 0)
|
|
|
|
goto bogon;
|
|
|
|
}
|
2001-04-20 19:23:45 +00:00
|
|
|
if (prev)
|
|
|
|
omapi_io_dereference (&prev, MDL);
|
|
|
|
omapi_io_reference (&prev, io, MDL);
|
|
|
|
omapi_io_dereference (&io, MDL);
|
|
|
|
if (prev -> next)
|
|
|
|
omapi_io_reference (&io, prev -> next, MDL);
|
2000-06-20 20:30:27 +00:00
|
|
|
}
|
2001-04-20 19:23:45 +00:00
|
|
|
if (prev)
|
|
|
|
omapi_io_dereference (&prev, MDL);
|
|
|
|
|
2000-06-20 20:30:27 +00:00
|
|
|
}
|
1999-09-02 00:32:56 +00:00
|
|
|
|
|
|
|
for (io = omapi_io_states.next; io; io = io -> next) {
|
2000-06-06 23:47:27 +00:00
|
|
|
if (!io -> inner)
|
|
|
|
continue;
|
2000-05-03 06:15:31 +00:00
|
|
|
omapi_object_reference (&tmp, io -> inner, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
/* Check for a read descriptor, and if there is one,
|
|
|
|
see if we got input on that socket. */
|
|
|
|
if (io -> readfd &&
|
2000-05-03 06:15:31 +00:00
|
|
|
(desc = (*(io -> readfd)) (tmp)) >= 0) {
|
1999-09-02 00:32:56 +00:00
|
|
|
if (FD_ISSET (desc, &r))
|
2005-03-17 20:15:29 +00:00
|
|
|
((*(io -> reader)) (tmp));
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Same deal for write descriptors. */
|
|
|
|
if (io -> writefd &&
|
2000-05-03 06:15:31 +00:00
|
|
|
(desc = (*(io -> writefd)) (tmp)) >= 0)
|
1999-09-02 00:32:56 +00:00
|
|
|
{
|
|
|
|
if (FD_ISSET (desc, &w))
|
2005-03-17 20:15:29 +00:00
|
|
|
((*(io -> writer)) (tmp));
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
2000-05-03 06:15:31 +00:00
|
|
|
omapi_object_dereference (&tmp, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Now check for I/O handles that are no longer valid,
|
|
|
|
and remove them from the list. */
|
2008-03-18 18:28:14 +00:00
|
|
|
prev = NULL;
|
|
|
|
io = NULL;
|
|
|
|
if (omapi_io_states.next != NULL) {
|
|
|
|
omapi_io_reference(&io, omapi_io_states.next, MDL);
|
|
|
|
}
|
|
|
|
while (io != NULL) {
|
|
|
|
if ((io->inner == NULL) ||
|
|
|
|
((io->reaper != NULL) &&
|
|
|
|
((io->reaper)(io->inner) != ISC_R_SUCCESS)))
|
|
|
|
{
|
|
|
|
|
|
|
|
omapi_io_object_t *tmp = NULL;
|
|
|
|
/* Save a reference to the next
|
|
|
|
pointer, if there is one. */
|
|
|
|
if (io->next != NULL) {
|
|
|
|
omapi_io_reference(&tmp, io->next, MDL);
|
|
|
|
omapi_io_dereference(&io->next, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
2008-03-18 18:28:14 +00:00
|
|
|
if (prev != NULL) {
|
|
|
|
omapi_io_dereference(&prev->next, MDL);
|
|
|
|
if (tmp != NULL)
|
|
|
|
omapi_io_reference(&prev->next,
|
|
|
|
tmp, MDL);
|
|
|
|
} else {
|
|
|
|
omapi_io_dereference(&omapi_io_states.next,
|
|
|
|
MDL);
|
|
|
|
if (tmp != NULL)
|
|
|
|
omapi_io_reference
|
|
|
|
(&omapi_io_states.next,
|
|
|
|
tmp, MDL);
|
|
|
|
else
|
|
|
|
omapi_signal_in(
|
|
|
|
(omapi_object_t *)
|
|
|
|
&omapi_io_states,
|
|
|
|
"ready");
|
|
|
|
}
|
|
|
|
if (tmp != NULL)
|
|
|
|
omapi_io_dereference(&tmp, MDL);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (prev != NULL) {
|
|
|
|
omapi_io_dereference(&prev, MDL);
|
|
|
|
}
|
|
|
|
omapi_io_reference(&prev, io, MDL);
|
|
|
|
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
2008-03-18 18:28:14 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Equivalent to:
|
|
|
|
* io = io->next
|
|
|
|
* But using our reference counting voodoo.
|
|
|
|
*/
|
|
|
|
next = NULL;
|
|
|
|
if (io->next != NULL) {
|
|
|
|
omapi_io_reference(&next, io->next, MDL);
|
|
|
|
}
|
|
|
|
omapi_io_dereference(&io, MDL);
|
|
|
|
if (next != NULL) {
|
|
|
|
omapi_io_reference(&io, next, MDL);
|
|
|
|
omapi_io_dereference(&next, MDL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (prev != NULL) {
|
|
|
|
omapi_io_dereference(&prev, MDL);
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_io_set_value (omapi_object_t *h,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_typed_data_t *value)
|
|
|
|
{
|
|
|
|
if (h -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
if (h -> inner && h -> inner -> type -> set_value)
|
|
|
|
return (*(h -> inner -> type -> set_value))
|
|
|
|
(h -> inner, id, name, value);
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_io_get_value (omapi_object_t *h,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_data_string_t *name,
|
|
|
|
omapi_value_t **value)
|
|
|
|
{
|
|
|
|
if (h -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
if (h -> inner && h -> inner -> type -> get_value)
|
|
|
|
return (*(h -> inner -> type -> get_value))
|
|
|
|
(h -> inner, id, name, value);
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
2005-03-17 20:15:29 +00:00
|
|
|
/* omapi_io_destroy (object, MDL);
|
|
|
|
*
|
2007-11-30 21:51:43 +00:00
|
|
|
* Find the requested IO [object] and remove it from the list of io
|
2005-03-17 20:15:29 +00:00
|
|
|
* states, causing the cleanup functions to destroy it. Note that we must
|
|
|
|
* hold a reference on the object while moving its ->next reference and
|
|
|
|
* removing the reference in the chain to the target object...otherwise it
|
|
|
|
* may be cleaned up from under us.
|
|
|
|
*/
|
2000-01-26 14:56:18 +00:00
|
|
|
isc_result_t omapi_io_destroy (omapi_object_t *h, const char *file, int line)
|
1999-09-02 00:32:56 +00:00
|
|
|
{
|
2005-03-17 20:15:29 +00:00
|
|
|
omapi_io_object_t *obj = NULL, *p, *last = NULL, **holder;
|
2000-02-15 20:40:36 +00:00
|
|
|
|
1999-09-02 00:32:56 +00:00
|
|
|
if (h -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
2000-02-15 20:40:36 +00:00
|
|
|
|
2000-05-03 06:15:31 +00:00
|
|
|
/* remove from the list of I/O states */
|
|
|
|
for (p = omapi_io_states.next; p; p = p -> next) {
|
2005-03-17 20:15:29 +00:00
|
|
|
if (p == (omapi_io_object_t *)h) {
|
|
|
|
omapi_io_reference (&obj, p, MDL);
|
|
|
|
|
|
|
|
if (last)
|
|
|
|
holder = &last -> next;
|
|
|
|
else
|
|
|
|
holder = &omapi_io_states.next;
|
|
|
|
|
|
|
|
omapi_io_dereference (holder, MDL);
|
|
|
|
|
|
|
|
if (obj -> next) {
|
|
|
|
omapi_io_reference (holder, obj -> next, MDL);
|
|
|
|
omapi_io_dereference (&obj -> next, MDL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return omapi_io_dereference (&obj, MDL);
|
2000-02-15 20:40:36 +00:00
|
|
|
}
|
2000-05-03 06:15:31 +00:00
|
|
|
last = p;
|
2000-02-15 20:40:36 +00:00
|
|
|
}
|
2005-03-17 20:15:29 +00:00
|
|
|
|
|
|
|
return ISC_R_NOTFOUND;
|
1999-09-02 00:32:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_io_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-02 00:32:56 +00:00
|
|
|
{
|
|
|
|
if (h -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
if (h -> inner && h -> inner -> type -> signal_handler)
|
|
|
|
return (*(h -> inner -> type -> signal_handler)) (h -> inner,
|
|
|
|
name, ap);
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_io_stuff_values (omapi_object_t *c,
|
|
|
|
omapi_object_t *id,
|
|
|
|
omapi_object_t *i)
|
|
|
|
{
|
|
|
|
if (i -> type != omapi_type_io_object)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
if (i -> inner && i -> inner -> type -> stuff_values)
|
|
|
|
return (*(i -> inner -> type -> stuff_values)) (c, id,
|
|
|
|
i -> inner);
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
isc_result_t omapi_waiter_signal_handler (omapi_object_t *h,
|
1999-10-07 06:36:35 +00:00
|
|
|
const char *name, va_list ap)
|
1999-09-02 00:32:56 +00:00
|
|
|
{
|
|
|
|
omapi_waiter_object_t *waiter;
|
|
|
|
|
|
|
|
if (h -> type != omapi_type_waiter)
|
|
|
|
return ISC_R_INVALIDARG;
|
|
|
|
|
|
|
|
if (!strcmp (name, "ready")) {
|
|
|
|
waiter = (omapi_waiter_object_t *)h;
|
|
|
|
waiter -> ready = 1;
|
2000-08-03 21:00:41 +00:00
|
|
|
waiter -> waitstatus = ISC_R_SUCCESS;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!strcmp (name, "status")) {
|
|
|
|
waiter = (omapi_waiter_object_t *)h;
|
|
|
|
waiter -> ready = 1;
|
|
|
|
waiter -> waitstatus = va_arg (ap, isc_result_t);
|
1999-09-02 00:32:56 +00:00
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2001-06-27 00:31:20 +00:00
|
|
|
if (!strcmp (name, "disconnect")) {
|
|
|
|
waiter = (omapi_waiter_object_t *)h;
|
|
|
|
waiter -> ready = 1;
|
|
|
|
waiter -> waitstatus = ISC_R_CONNRESET;
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|
|
|
|
|
1999-09-02 00:32:56 +00:00
|
|
|
if (h -> inner && h -> inner -> type -> signal_handler)
|
|
|
|
return (*(h -> inner -> type -> signal_handler)) (h -> inner,
|
|
|
|
name, ap);
|
|
|
|
return ISC_R_NOTFOUND;
|
|
|
|
}
|
|
|
|
|
2001-06-27 00:31:20 +00:00
|
|
|
isc_result_t omapi_io_state_foreach (isc_result_t (*func) (omapi_object_t *,
|
|
|
|
void *),
|
|
|
|
void *p)
|
|
|
|
{
|
|
|
|
omapi_io_object_t *io;
|
|
|
|
isc_result_t status;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ISC_R_SUCCESS;
|
|
|
|
}
|