int ZKAgent::Init(ArdbServer* serv) { m_server = serv; ArdbServerConfig& cfg = serv->m_cfg; if (cfg.zookeeper_servers.empty()) { WARN_LOG("No zookeeper servers specified, zookeeper agent would not start."); return 0; } ZooLogLevel z_log_loevel; if (DEBUG_ENABLED()) { z_log_loevel = ZOO_LOG_LEVEL_DEBUG; } else if (INFO_ENABLED()) { z_log_loevel = ZOO_LOG_LEVEL_INFO; } else if (WARN_ENABLED()) { z_log_loevel = ZOO_LOG_LEVEL_WARN; } else if (ERROR_ENABLED()) { z_log_loevel = ZOO_LOG_LEVEL_ERROR; } else { z_log_loevel = ZOO_LOG_LEVEL_DEBUG; } zoo_set_debug_level(z_log_loevel); zoo_set_log_stream(ArdbLogger::GetLogStream()); std::string zkidfile = cfg.home + "/.zkcid"; FILE* idfile = fopen(zkidfile.c_str(), "r"); if (idfile != NULL) { if (fread(&m_zk_clientid, sizeof(m_zk_clientid), 1, idfile) != 1) { memset(&m_zk_clientid, 0, sizeof(m_zk_clientid)); } fclose(idfile); } Reconnect(); return 0; }
GHashTable * meta0_info_list_map_by_prefix(GSList * mL, GError ** err) { GSList *l; GHashTable *mH; (void) err; mH = g_hash_table_new_full(func_hash_prefix, func_equal_prefix, NULL, func_free_meta0); for (l = mL; l; l = l->next) { register int i, max; meta0_info_t dummy, *arg, *m0i; if (!l->data) continue; arg = (meta0_info_t *) l->data; dummy.prefixes_size = 2; dummy.prefixes = g_try_malloc(dummy.prefixes_size); g_memmove(&(dummy.addr), &(arg->addr), sizeof(addr_info_t)); for (i = 1, max = arg->prefixes_size - 1; i < max; i += 2) { g_memmove(dummy.prefixes, arg->prefixes + i - 1, 2); m0i = g_hash_table_lookup(mH, &dummy); if (m0i) { /*prefix already present, we do nothing else a debug */ if (DEBUG_ENABLED()) { char str_addr[128]; addr_info_to_string(&(dummy.addr), str_addr, sizeof(str_addr)); DEBUG("double prefix found %02X%02X -> %s", dummy.prefixes[0], dummy.prefixes[1], str_addr); } } else { /*prefix absent */ m0i = meta0_info_copy(&dummy); g_hash_table_insert(mH, m0i, m0i); } } g_free(dummy.prefixes); } return mH; }
/* * Select on the list of fds. * Returns: -1 = error * 0 = timeout or nothing to select * >0 = number of signaled fds */ int _gpgme_io_select(struct io_select_fd_s *fds, size_t nfds, int nonblock) { fd_set readfds; fd_set writefds; unsigned int i; int any, max_fd, n, count; struct timeval timeout = { 1, 0 }; /* Use a 1s timeout. */ void *dbg_help = NULL; FD_ZERO(&readfds); FD_ZERO(&writefds); max_fd = 0; if(nonblock) timeout.tv_sec = 0; DEBUG_BEGIN(dbg_help, 3, "gpgme:select on [ "); any = 0; for(i = 0; i < nfds; i++) { if(fds[i].fd == -1) continue; if(fds[i].frozen) DEBUG_ADD1(dbg_help, "f%d ", fds[i].fd); else if(fds[i].for_read) { assert(!FD_ISSET(fds[i].fd, &readfds)); FD_SET(fds[i].fd, &readfds); if(fds[i].fd > max_fd) max_fd = fds[i].fd; DEBUG_ADD1(dbg_help, "r%d ", fds[i].fd); any = 1; } else if(fds[i].for_write) { assert(!FD_ISSET(fds[i].fd, &writefds)); FD_SET(fds[i].fd, &writefds); if(fds[i].fd > max_fd) max_fd = fds[i].fd; DEBUG_ADD1(dbg_help, "w%d ", fds[i].fd); any = 1; } fds[i].signaled = 0; } DEBUG_END(dbg_help, "]"); if(!any) return 0; do { count = _gpgme_ath_select(max_fd + 1, &readfds, &writefds, NULL, &timeout); } while(count < 0 && errno == EINTR); if(count < 0) { int saved_errno = errno; DEBUG1("_gpgme_io_select failed: %s\n", strerror(errno)); errno = saved_errno; return -1; /* error */ } DEBUG_BEGIN(dbg_help, 3, "select OK [ "); if(DEBUG_ENABLED(dbg_help)) { for(i = 0; i <= max_fd; i++) { if(FD_ISSET(i, &readfds)) DEBUG_ADD1(dbg_help, "r%d ", i); if(FD_ISSET(i, &writefds)) DEBUG_ADD1(dbg_help, "w%d ", i); } DEBUG_END(dbg_help, "]"); } /* n is used to optimize it a little bit. */ for(n = count, i = 0; i < nfds && n; i++) { if(fds[i].fd == -1) ; else if(fds[i].for_read) { if(FD_ISSET(fds[i].fd, &readfds)) { fds[i].signaled = 1; n--; } } else if(fds[i].for_write) { if(FD_ISSET(fds[i].fd, &writefds)) { fds[i].signaled = 1; n--; } } } return count; }