--- libaitsched/src/hooks.c 2011/10/04 13:29:00 1.2.2.1 +++ libaitsched/src/hooks.c 2011/10/04 13:50:05 1.2.2.2 @@ -3,7 +3,7 @@ * by Michael Pounov * * $Author: misho $ -* $Id: hooks.c,v 1.2.2.1 2011/10/04 13:29:00 misho Exp $ +* $Id: hooks.c,v 1.2.2.2 2011/10/04 13:50:05 misho Exp $ * ************************************************************************** The ELWIX and AITNET software is distributed under the following @@ -184,6 +184,8 @@ sched_hook_read(void *task, void *arg __unused) if (kevent(t->task_root->root_kq, chg, 1, NULL, 0, &timeout) == -1) { if (t->task_root->root_hooks.hook_exec.exception) t->task_root->root_hooks.hook_exec.exception(t->task_root, NULL); + else + LOGERR; return (void*) -1; } @@ -222,6 +224,8 @@ sched_hook_write(void *task, void *arg __unused) if (kevent(t->task_root->root_kq, chg, 1, NULL, 0, &timeout) == -1) { if (t->task_root->root_hooks.hook_exec.exception) t->task_root->root_hooks.hook_exec.exception(t->task_root, NULL); + else + LOGERR; return (void*) -1; } @@ -310,9 +314,11 @@ retry: } else /* wait INFTIM */ timeout = NULL; if ((en = kevent(r->root_kq, NULL, 0, res, KQ_EVENTS, timeout)) == -1) { - if (r->root_hooks.hook_exec.exception) + if (r->root_hooks.hook_exec.exception) { if (r->root_hooks.hook_exec.exception(r, NULL)) return NULL; /* exit from scheduler */ + } else + LOGERR; #ifdef NDEBUG /* kevent no exit by error, if non-debug version */ goto retry; @@ -378,10 +384,13 @@ retry: } break; } - if (kevent(r->root_kq, evt, 1, NULL, 0, &nw) == -1) - if (r->root_hooks.hook_exec.exception) + if (kevent(r->root_kq, evt, 1, NULL, 0, &nw) == -1) { + if (r->root_hooks.hook_exec.exception) { if (r->root_hooks.hook_exec.exception(r, NULL)) return NULL; /* exit from scheduler */ + } else + LOGERR; + } } /* timer update & put in ready queue */ @@ -422,7 +431,7 @@ retry: /* * sched_hook_exception() - Default EXCEPTION hook * @root = root task - * @arg = may be EV_EOF + * @arg = custom handling: if arg == EV_EOF or other value; default: arg == NULL log errno * return: <0 errors and 0 ok */ void * @@ -433,15 +442,18 @@ sched_hook_exception(void *root, void *arg) if (!r || !ROOT_DATA(r) || !ROOT_DATLEN(r)) return NULL; + /* custom exception handling ... */ if (arg) { if (arg == (void*) EV_EOF) return NULL; - return (void*) -1; /* raise error */ - } else - LOGERR; + return (void*) -1; /* raise scheduler error!!! */ + } - if (errno == EINTR) - return (void*) -1; /* raise error */ + /* if error hook exists */ + if (r->root_hooks.hook_root.error) + return (r->root_hooks.hook_root.error(root, (void*) errno)); + /* default case! */ + LOGERR; return NULL; }