ZBX_THREAD_ENTRY(listener_thread, pSock) { int ret, local_request_failed = 0; zbx_sock_t s; assert(pSock); zbx_setproctitle("listener waiting for connection"); zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd listener started"); memcpy(&s, ((zbx_sock_t *)pSock), sizeof(zbx_sock_t)); while(ZBX_IS_RUNNING) { if( SUCCEED == (ret = zbx_tcp_accept(&s)) ) { local_request_failed = 0; /* Reset consecutive errors counter */ zbx_setproctitle("processing request"); zabbix_log(LOG_LEVEL_DEBUG, "Processing request."); if( SUCCEED == (ret = zbx_tcp_check_security(&s, CONFIG_HOSTS_ALLOWED, 0)) ) { process_listener(&s); } zbx_tcp_unaccept(&s); } zbx_setproctitle("listener waiting for connection"); if( SUCCEED == ret ) continue; zabbix_log(LOG_LEVEL_DEBUG, "Listener error: %s", zbx_tcp_strerror()); if (local_request_failed++ > 1000) { zabbix_log( LOG_LEVEL_WARNING, "Too many consecutive errors on accept() call."); local_request_failed = 0; } if(ZBX_IS_RUNNING) zbx_sleep(1); } zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd listener stopped"); ZBX_DO_EXIT(); zbx_tread_exit(0); }
ZBX_THREAD_ENTRY(active_checks_thread, args) { ZBX_THREAD_ACTIVECHK_ARGS activechk_args; #if defined(ZABBIX_DAEMON) struct sigaction phan; #endif /* ZABBIX_DAEMON */ int nextcheck = 0, nextrefresh = 0, nextsend = 0; char *p = NULL; #if defined(ZABBIX_DAEMON) phan.sa_handler = child_signal_handler; sigemptyset(&phan.sa_mask); phan.sa_flags = 0; sigaction(SIGALRM, &phan, NULL); #endif /* ZABBIX_DAEMON */ activechk_args.host = strdup(((ZBX_THREAD_ACTIVECHK_ARGS *)args)->host); activechk_args.port = ((ZBX_THREAD_ACTIVECHK_ARGS *)args)->port; assert(activechk_args.host); p = strchr(activechk_args.host,','); if(p) *p = '\0'; zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check started [%s:%u]", activechk_args.host, activechk_args.port); init_active_metrics(); while(ZBX_IS_RUNNING) { if(time(NULL) >= nextsend) { send_buffer(activechk_args.host, activechk_args.port); nextsend = (int)time(NULL) + 1; } if(time(NULL) >= nextrefresh) { zbx_setproctitle("poller [getting list of active checks]"); if(FAIL == refresh_active_checks(activechk_args.host, activechk_args.port)) { nextrefresh = (int)time(NULL) + 60; } else { nextrefresh = (int)time(NULL) + CONFIG_REFRESH_ACTIVE_CHECKS; } } if(time(NULL) >= nextcheck) { zbx_setproctitle("poller [processing active checks]"); process_active_checks(activechk_args.host, activechk_args.port); nextcheck = get_min_nextcheck(); if(FAIL == nextcheck) nextcheck = (int)time(NULL) + 60; } else { zabbix_log(LOG_LEVEL_DEBUG, "Sleeping for %d seconds", 1 ); zbx_setproctitle("poller [sleeping for %d seconds]", 1); zbx_sleep(1); } } zbx_free(activechk_args.host); free_active_metrics(); zabbix_log( LOG_LEVEL_INFORMATION, "zabbix_agentd active check stopped"); ZBX_DO_EXIT(); zbx_tread_exit(0); }