KHMEXP khm_int32 KHMAPI kcdb_identpro_begin_enum(kcdb_enumeration * pe, khm_size * pn_providers) { kcdb_enumeration e; kcdb_identpro_i * p; khm_size i; EnterCriticalSection(&cs_identpro); if (n_id_providers == 0) { LeaveCriticalSection(&cs_identpro); if (pn_providers) *pn_providers = 0; *pe = NULL; return KHM_ERROR_NOT_FOUND; } kcdbint_enum_create(&e); kcdbint_enum_alloc(e, n_id_providers); for (i = 0, p = QTOP(&id_providers); p; p = QNEXT(p)) { #ifdef DEBUG assert(i < n_id_providers); #endif e->objs[i++] = (khm_handle) p; identpro_hold(p); } LeaveCriticalSection(&cs_identpro); *pe = e; if (pn_providers) *pn_providers = e->n; return KHM_ERROR_SUCCESS; }
static void pick_err_event(kherr_context * c) { kherr_event * e; kherr_event * ce = NULL; enum kherr_severity s; s = KHERR_RESERVED_BANK; EnterCriticalSection(&cs_error); e = QTOP(c); while(e) { if(!(e->flags & KHERR_RF_INERT) && s >= e->severity) { ce = e; s = e->severity; } e = QNEXT(e); } if(ce) { c->err_event = ce; c->severity = ce->severity; } else { c->err_event = NULL; c->severity = KHERR_NONE; } c->flags &= ~KHERR_CF_DIRTY; LeaveCriticalSection(&cs_error); }
KHMEXP kherr_event * KHMAPI kherr_get_next_event(kherr_event * e) { kherr_event * ee; if (!IS_KHERR_EVENT(e)) return NULL; EnterCriticalSection(&cs_error); ee = QNEXT(e); LeaveCriticalSection(&cs_error); assert(ee == NULL || IS_KHERR_EVENT(ee)); return ee; }
static kcdb_identpro_i * identpro_find_by_name(const wchar_t * name) { kcdb_identpro_i * p; EnterCriticalSection(&cs_identpro); for (p = QTOP(&id_providers); p; p = QNEXT(p)) { if (!wcscmp(p->name, name)) break; } if (p) identpro_hold(p); LeaveCriticalSection(&cs_identpro); return p; }
static kcdb_identpro_i * identpro_find_by_plugin(kmm_plugin plugin) { kcdb_identpro_i * p; EnterCriticalSection(&cs_identpro); for (p = QTOP(&id_providers); p; p = QNEXT(p)) { if (p->plugin == plugin) break; } if (p) identpro_hold(p); LeaveCriticalSection(&cs_identpro); return p; }
KHMEXP void KHMAPI kherr_clear_error_i(kherr_context * c) { kherr_event * e; if (IS_KHERR_CTX(c)) { EnterCriticalSection(&cs_error); e = QTOP(c); while(e) { assert(IS_KHERR_EVENT(e)); e->flags |= KHERR_RF_INERT; e = QNEXT(e); } c->severity = KHERR_NONE; c->err_event = NULL; c->flags &= ~KHERR_CF_DIRTY; LeaveCriticalSection(&cs_error); } }
static void Iowait(void) { int maxfd; fd_set readfds; QUEUE *q; /* accept input on any descriptor */ FD_ZERO(&readfds); FD_SET(master, &readfds); maxfd = master; for (q = QFIRST(tpclients); q != &tpclients; q = QNEXT(q)) { struct tpclient * c = OFFSET(q, struct tpclient, global); if (c->fd > maxfd) maxfd = c->fd; FD_SET(c->fd, &readfds); } debug(3, "entering select to fd %d", maxfd); /* wait for something to do */ if (select(maxfd + 1, &readfds, 0, 0, 0) == -1) { error("select: %m"); return; } /* new client connection */ if (FD_ISSET(master, &readfds)) { debug(1, "new connection"); int i = accept(master, 0, 0); if (i == -1) error("accept: %m"); else svr_next_command(new_client(i)); } q = QFIRST(tpclients); while (q != &tpclients) { struct tpclient * c = OFFSET(q, struct tpclient, global); q = QNEXT(q); if (FD_ISSET(c->fd, &readfds)) { long bufsize = c->input ? tptypes(c->input, 0, 0) : 0; int used = c->used; if (used >= bufsize) // something unexpected. could be EOF { char check_eof[100]; int len = read(c->fd, &check_eof, sizeof check_eof); if (len > 0) { error("Iowait: read %d unexpected bytes from fd %d", len, c->fd); dump(c->fd, "unexpected", check_eof, len); } del_client(c); } else if ((used = read(c->fd, c->input + used, bufsize - used)) == -1) { error("Iowait: read: %m"); del_client(c); } else if (used == 0) { debug(1, "eof on %d", c->fd); del_client(c); } else if ((c->used = c->used + used) == bufsize) { void (*handle)(struct tpclient *, char *) = c->handler; char *buf = c->input; char *handler_name = c->handler_name; c->handler_name = 0; c->handler = 0; c->input = 0; c->used = 0; debug(1, "%d bytes read from %d. calling handler %s at 0x%x", bufsize, c->fd, handler_name, handle); if (DEBUG > 2) dump(c->fd, "read", buf, bufsize); handle(c, buf); debug(2, "back from handler %s at 0x%x", handler_name, handle); } else debug(2, "%d bytes read from %d. waiting for %d more...", used, c->fd, bufsize - c->used); } if (q != &tpclients) debug(2, "-------"); } }
static kcdb_identpro_i * identpro_create_with_plugin(kmm_plugin plugin, khm_handle sub) { kmm_plugin_info pi; kcdb_identpro_i * p; size_t len; ZeroMemory(&pi, sizeof(pi)); if (KHM_FAILED(kmm_get_plugin_info_i(plugin, &pi))) return NULL; if (pi.reg.type != KHM_PITYPE_IDENT) { kmm_release_plugin_info_i(&pi); #ifdef DEBUG assert(FALSE); #endif return NULL; } if (FAILED(StringCbLength(pi.reg.name, KMM_MAXCB_NAME, &len))) return NULL; len += sizeof(wchar_t); /* we need to check if the plug-in is already there, both in the current and the deleted lists */ EnterCriticalSection(&cs_identpro); for (p = QTOP(&id_providers); p; p = QNEXT(p)) { if (p->plugin == plugin) break; } if (p == NULL) for (p = deleted_id_providers; p; p = LNEXT(p)) { if (p->plugin == plugin || !wcscmp(p->name, pi.reg.name)) break; } if (p) identpro_hold(p); if (p == NULL) { p = PMALLOC(sizeof(*p)); ZeroMemory(p, sizeof(*p)); p->magic = KCDB_IDENTPRO_MAGIC; p->name = PMALLOC(len); StringCbCopy(p->name, len, pi.reg.name); p->sub = sub; p->plugin = plugin; kmm_hold_plugin(plugin); p->refcount = 1; /* initially held */ QPUT(&id_providers, p); n_id_providers++; kcdbint_identpro_post_message(KCDB_OP_INSERT, p); } else if (p->flags & KCDB_IDENTPRO_FLAG_DELETED) { LDELETE(&deleted_id_providers, p); p->flags &= ~KCDB_IDENTPRO_FLAG_DELETED; if (p->plugin != plugin) { /* can happen if the plug-in was reloaded */ if (p->plugin) kmm_release_plugin_info_i(p->plugin); p->plugin = plugin; kmm_hold_plugin(plugin); } if (p->sub) { kmq_delete_subscription(p->sub); } p->sub = sub; QPUT(&id_providers, p); n_id_providers++; } identpro_check_and_set_default_provider(); LeaveCriticalSection(&cs_identpro); kmm_release_plugin_info_i(&pi); return p; }