void sockets_run(void) { fd_set rset; struct timeval tv; int nready; tv.tv_sec = 1; tv.tv_usec = 0; for ( ; ; ) { rset = allset; if ((nready = select(getmaxfd() + 1, &rset, NULL, NULL, &tv)) < 0) { if (errno == EINTR) continue; misc_debug(0, "select: %s\n", strerror(errno)); continue; } if (FD_ISSET(mgmtfd, &rset)) { accept_mgmt_client(mgmtfd); nready--; } if (nready > 0 && FD_ISSET(pcapfd, &rset)) { peekpcap(100, packet_handler); nready--; } if (nready > 0 && is_mgmt_active()) { if (FD_ISSET(get_mgmt_fd(), &rset)) { process_mgmt_request(); nready--; } } } }
/*ARGSUSED*/ static void door_server(void *cookie, char *argp, size_t arg_size, door_desc_t *dp, uint_t n_desc) { request_t req; xmlDocPtr x_doc; xmlChar *resp_buf = NULL; int ret, size = 0; pthread_t tid; thr_elem_t *thr; ucred_t *uc = NULL; if (ISNS_MGMT_REQUEST_RECEIVED_ENABLED()) { ISNS_MGMT_REQUEST_RECEIVED(); } if (door_ucred(&uc) != 0) { isnslog(LOG_DEBUG, "door_server", "door_ucred failed. errno: %d\n", errno); ret = build_result_message(&resp_buf, ERR_DOOR_UCRED_FAILED, &size); if (ret == ISNS_RSP_SUCCESSFUL) { (void) door_return((char *)resp_buf, size + 1, NULL, 0); /* Not reached */ } else { ret = ERR_DOOR_UCRED_FAILED; (void) door_return((void *)&ret, sizeof (ret), NULL, 0); /* Not reached */ } } isnslog(LOG_DEBUG, "door_server", "entered with request:\n %s\n", argp); if ((x_doc = xmlParseMemory(argp, arg_size)) != NULL) { isnslog(LOG_DEBUG, "door_server", "ParseMemory succeeded"); if ((ret = process_mgmt_request(x_doc, &req, uc)) == 0) { ret = build_mgmt_response(&resp_buf, req, &size); } else { ret = build_result_message(&resp_buf, ret, &size); } xmlFreeDoc(x_doc); cleanup_request(req); } else { ret = build_result_message(&resp_buf, ERR_XML_PARSE_MEMORY_FAILED, &size); } /* free the ucred */ ucred_free(uc); if (resp_buf) { tid = pthread_self(); if ((thr = match_entry(tid)) == NULL) { (void) add_entry(tid, resp_buf); } else { isnslog(LOG_DEBUG, "door_server", "free the previouly returned buffer %x on this thread\n", thr->doc); xmlFree(thr->doc); isnslog(LOG_DEBUG, "door_server", "store the currently allocated buffer %x on this thread\n", resp_buf); thr->doc = resp_buf; } isnslog(LOG_DEBUG, "door_server", "exiting with response:\n %s\n", (const char *)resp_buf); if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) { ISNS_MGMT_REQUEST_RESPONDED(); } (void) door_return((char *)resp_buf, size + 1, NULL, 0); /* Not reached */ } isnslog(LOG_DEBUG, "door_server", "exiting only with error code %d\n", ret); if (ISNS_MGMT_REQUEST_RESPONDED_ENABLED()) { ISNS_MGMT_REQUEST_RESPONDED(); } (void) door_return((void *)&ret, sizeof (ret), NULL, 0); }