static void zbx_signal_process_by_type(int proc_type, int proc_num, int flags) { int process_num, found = 0, i; union sigval s; unsigned char process_type; s.ZBX_SIVAL_INT = flags; for (i = 0; i < threads_num; i++) { if (FAIL == get_process_info_by_thread(i + 1, &process_type, &process_num)) break; if (proc_type != process_type) { /* check if we have already checked processes of target type */ if (1 == found) break; continue; } if (0 != proc_num && proc_num != process_num) continue; found = 1; if (-1 != sigqueue(threads[i], SIGUSR1, s)) { zabbix_log(LOG_LEVEL_DEBUG, "the signal was redirected to \"%s\" process" " pid:%d", get_process_type_string(process_type), threads[i]); } else zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: %s", zbx_strerror(errno)); } if (0 == found) { if (0 == proc_num) { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal:" " \"%s\" process does not exist", get_process_type_string(proc_type)); } else { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal:" " \"%s #%d\" process does not exist", get_process_type_string(proc_type), proc_num); } } }
/****************************************************************************** * * * Function: user1_signal_handler * * * * Purpose: handle user signal SIGUSR1 * * * ******************************************************************************/ static void user1_signal_handler(int sig, siginfo_t *siginfo, void *context) { #ifdef HAVE_SIGQUEUE int flags, process_num, found = 0, i; union sigval s; unsigned char process_type; #endif SIG_CHECK_PARAMS(sig, siginfo, context); zabbix_log(LOG_LEVEL_DEBUG, "Got signal [signal:%d(%s),sender_pid:%d,sender_uid:%d,value_int:%d(0x%08x)].", sig, get_signal_name(sig), SIG_CHECKED_FIELD(siginfo, si_pid), SIG_CHECKED_FIELD(siginfo, si_uid), SIG_CHECKED_FIELD(siginfo, si_value.ZBX_SIVAL_INT), SIG_CHECKED_FIELD(siginfo, si_value.ZBX_SIVAL_INT)); #ifdef HAVE_SIGQUEUE flags = SIG_CHECKED_FIELD(siginfo, si_value.ZBX_SIVAL_INT); if (!SIG_PARENT_PROCESS) { common_sigusr_handler(flags); } else if (NULL == threads) { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: shutdown in progress"); } else if (ZBX_RTC_CONFIG_CACHE_RELOAD == ZBX_RTC_GET_MSG(flags)) { extern unsigned char daemon_type; if (0 != (daemon_type & ZBX_DAEMON_TYPE_PROXY_PASSIVE)) { zabbix_log(LOG_LEVEL_WARNING, "forced reloading of the configuration cache" " cannot be performed for a passive proxy"); return; } for (i = 0; i < threads_num; i++) { if (FAIL == get_process_info_by_thread(i + 1, &process_type, &process_num)) continue; if (ZBX_PROCESS_TYPE_CONFSYNCER == process_type) break; } if (i != threads_num) { s.ZBX_SIVAL_INT = flags; if (-1 != sigqueue(threads[i], SIGUSR1, s)) zabbix_log(LOG_LEVEL_DEBUG, "the signal was redirected to the configuration syncer"); else zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: %s", zbx_strerror(errno)); } else zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal to configuration syncer: process not found"); } else if (ZBX_RTC_LOG_LEVEL_INCREASE == ZBX_RTC_GET_MSG(flags) || ZBX_RTC_LOG_LEVEL_DECREASE == ZBX_RTC_GET_MSG(flags)) { s.ZBX_SIVAL_INT = flags; if ((ZBX_RTC_LOG_SCOPE_FLAG | ZBX_RTC_LOG_SCOPE_PID) == ZBX_RTC_GET_SCOPE(flags)) { for (i = 0; i < threads_num; i++) { if (0 != ZBX_RTC_GET_DATA(flags) && threads[i] != ZBX_RTC_GET_DATA(flags)) continue; found = 1; if (-1 != sigqueue(threads[i], SIGUSR1, s)) { zabbix_log(LOG_LEVEL_DEBUG, "the signal was redirected to process pid:%d", threads[i]); } else zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: %s", zbx_strerror(errno)); } if (0 != ZBX_RTC_GET_DATA(flags) && 0 == found) { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: process pid:%d is not a Zabbix child" " process", ZBX_RTC_GET_DATA(flags)); } } else { for (i = 0; i < threads_num; i++) { if (FAIL == get_process_info_by_thread(i + 1, &process_type, &process_num)) break; if (ZBX_RTC_GET_SCOPE(flags) != process_type) { /* check if we have already checked processes of target type */ if (1 == found) break; continue; } if (0 != ZBX_RTC_GET_DATA(flags) && ZBX_RTC_GET_DATA(flags) != process_num) continue; found = 1; if (-1 != sigqueue(threads[i], SIGUSR1, s)) { zabbix_log(LOG_LEVEL_DEBUG, "the signal was redirected to \"%s\" process" " pid:%d", get_process_type_string(process_type), threads[i]); } else zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal: %s", zbx_strerror(errno)); } if (0 == found) { if (0 == ZBX_RTC_GET_DATA(flags)) { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal:" " \"%s\" process does not exist", get_process_type_string(ZBX_RTC_GET_SCOPE(flags))); } else { zabbix_log(LOG_LEVEL_ERR, "cannot redirect signal:" " \"%s #%d\" process does not exist", get_process_type_string(ZBX_RTC_GET_SCOPE(flags)), ZBX_RTC_GET_DATA(flags)); } } } } #endif }
int MAIN_ZABBIX_ENTRY(int flags) { zbx_socket_t listen_sock; char *error = NULL; int i, db_type; if (0 != (flags & ZBX_TASK_FLAG_FOREGROUND)) { printf("Starting Zabbix Server. Zabbix %s (revision %s).\nPress Ctrl+C to exit.\n\n", ZABBIX_VERSION, ZABBIX_REVISION); } if (SUCCEED != zbx_locks_create(&error)) { zbx_error("cannot create locks: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != zabbix_open_log(CONFIG_LOG_TYPE, CONFIG_LOG_LEVEL, CONFIG_LOG_FILE, &error)) { zbx_error("cannot open log: %s", error); zbx_free(error); exit(EXIT_FAILURE); } #ifdef HAVE_NETSNMP # define SNMP_FEATURE_STATUS "YES" #else # define SNMP_FEATURE_STATUS " NO" #endif #ifdef HAVE_OPENIPMI # define IPMI_FEATURE_STATUS "YES" #else # define IPMI_FEATURE_STATUS " NO" #endif #ifdef HAVE_LIBCURL # define LIBCURL_FEATURE_STATUS "YES" #else # define LIBCURL_FEATURE_STATUS " NO" #endif #if defined(HAVE_LIBCURL) && defined(HAVE_LIBXML2) # define VMWARE_FEATURE_STATUS "YES" #else # define VMWARE_FEATURE_STATUS " NO" #endif #ifdef HAVE_SMTP_AUTHENTICATION # define SMTP_AUTH_FEATURE_STATUS "YES" #else # define SMTP_AUTH_FEATURE_STATUS " NO" #endif #ifdef HAVE_JABBER # define JABBER_FEATURE_STATUS "YES" #else # define JABBER_FEATURE_STATUS " NO" #endif #ifdef HAVE_UNIXODBC # define ODBC_FEATURE_STATUS "YES" #else # define ODBC_FEATURE_STATUS " NO" #endif #ifdef HAVE_SSH2 # define SSH2_FEATURE_STATUS "YES" #else # define SSH2_FEATURE_STATUS " NO" #endif #ifdef HAVE_IPV6 # define IPV6_FEATURE_STATUS "YES" #else # define IPV6_FEATURE_STATUS " NO" #endif #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) # define TLS_FEATURE_STATUS "YES" #else # define TLS_FEATURE_STATUS " NO" #endif zabbix_log(LOG_LEVEL_INFORMATION, "Starting Zabbix Server. Zabbix %s (revision %s).", ZABBIX_VERSION, ZABBIX_REVISION); zabbix_log(LOG_LEVEL_INFORMATION, "****** Enabled features ******"); zabbix_log(LOG_LEVEL_INFORMATION, "SNMP monitoring: " SNMP_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "IPMI monitoring: " IPMI_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "Web monitoring: " LIBCURL_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "VMware monitoring: " VMWARE_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "SMTP authentication: " SMTP_AUTH_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "Jabber notifications: " JABBER_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "Ez Texting notifications: " LIBCURL_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "ODBC: " ODBC_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "SSH2 support: " SSH2_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "IPv6 support: " IPV6_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "TLS support: " TLS_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "******************************"); zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", CONFIG_FILE); #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) if (SUCCEED != zbx_coredump_disable()) { zabbix_log(LOG_LEVEL_CRIT, "cannot disable core dump, exiting..."); exit(EXIT_FAILURE); } #endif if (FAIL == zbx_load_modules(CONFIG_LOAD_MODULE_PATH, CONFIG_LOAD_MODULE, CONFIG_TIMEOUT, 1)) { zabbix_log(LOG_LEVEL_CRIT, "loading modules failed, exiting..."); exit(EXIT_FAILURE); } zbx_free_config(); if (SUCCEED != init_database_cache(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize database cache: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != init_configuration_cache(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize configuration cache: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != init_selfmon_collector(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize self-monitoring: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (0 != CONFIG_VMWARE_FORKS && SUCCEED != zbx_vmware_init(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize VMware cache: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != zbx_vc_init(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize history value cache: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != zbx_create_itservices_lock(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot create IT services lock: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (SUCCEED != zbx_history_init(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize history storage: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (FAIL == zbx_export_init(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot initialize export: %s", error); zbx_free(error); exit(EXIT_FAILURE); } if (ZBX_DB_UNKNOWN == (db_type = zbx_db_get_database_type())) { zabbix_log(LOG_LEVEL_CRIT, "cannot use database \"%s\": database is not a Zabbix database", CONFIG_DBNAME); exit(EXIT_FAILURE); } else if (ZBX_DB_SERVER != db_type) { zabbix_log(LOG_LEVEL_CRIT, "cannot use database \"%s\": its \"users\" table is empty (is this the" " Zabbix proxy database?)", CONFIG_DBNAME); exit(EXIT_FAILURE); } if (SUCCEED != DBcheck_version()) exit(EXIT_FAILURE); DBconnect(ZBX_DB_CONNECT_NORMAL); /* make initial configuration sync before worker processes are forked */ DCsync_configuration(ZBX_DBSYNC_INIT); if (SUCCEED != zbx_check_postinit_tasks(&error)) { zabbix_log(LOG_LEVEL_CRIT, "cannot complete post initialization tasks: %s", error); zbx_free(error); exit(EXIT_FAILURE); } /* update maintenance states */ zbx_dc_update_maintenances(); DBclose(); zbx_vc_enable(); threads_num = CONFIG_CONFSYNCER_FORKS + CONFIG_POLLER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_TRAPPER_FORKS + CONFIG_PINGER_FORKS + CONFIG_ALERTER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_TIMER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_HISTSYNCER_FORKS + CONFIG_ESCALATOR_FORKS + CONFIG_IPMIPOLLER_FORKS + CONFIG_JAVAPOLLER_FORKS + CONFIG_SNMPTRAPPER_FORKS + CONFIG_PROXYPOLLER_FORKS + CONFIG_SELFMON_FORKS + CONFIG_VMWARE_FORKS + CONFIG_TASKMANAGER_FORKS + CONFIG_IPMIMANAGER_FORKS + CONFIG_ALERTMANAGER_FORKS + CONFIG_PREPROCMAN_FORKS + CONFIG_PREPROCESSOR_FORKS + CONFIG_LLDMANAGER_FORKS + CONFIG_LLDWORKER_FORKS; threads = (pid_t *)zbx_calloc(threads, threads_num, sizeof(pid_t)); if (0 != CONFIG_TRAPPER_FORKS) { if (FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT)) { zabbix_log(LOG_LEVEL_CRIT, "listener failed: %s", zbx_socket_strerror()); exit(EXIT_FAILURE); } } #if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL) zbx_tls_init_parent(); #endif zabbix_log(LOG_LEVEL_INFORMATION, "server #0 started [main process]"); for (i = 0; i < threads_num; i++) { zbx_thread_args_t thread_args; unsigned char poller_type; if (FAIL == get_process_info_by_thread(i + 1, &thread_args.process_type, &thread_args.process_num)) { THIS_SHOULD_NEVER_HAPPEN; exit(EXIT_FAILURE); } thread_args.server_num = i + 1; thread_args.args = NULL; switch (thread_args.process_type) { case ZBX_PROCESS_TYPE_CONFSYNCER: zbx_thread_start(dbconfig_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_POLLER: poller_type = ZBX_POLLER_TYPE_NORMAL; thread_args.args = &poller_type; zbx_thread_start(poller_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_UNREACHABLE: poller_type = ZBX_POLLER_TYPE_UNREACHABLE; thread_args.args = &poller_type; zbx_thread_start(poller_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_TRAPPER: thread_args.args = &listen_sock; zbx_thread_start(trapper_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_PINGER: zbx_thread_start(pinger_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_ALERTER: zbx_thread_start(alerter_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_HOUSEKEEPER: zbx_thread_start(housekeeper_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_TIMER: zbx_thread_start(timer_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_HTTPPOLLER: zbx_thread_start(httppoller_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_DISCOVERER: zbx_thread_start(discoverer_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_HISTSYNCER: zbx_thread_start(dbsyncer_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_ESCALATOR: zbx_thread_start(escalator_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_JAVAPOLLER: poller_type = ZBX_POLLER_TYPE_JAVA; thread_args.args = &poller_type; zbx_thread_start(poller_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_SNMPTRAPPER: zbx_thread_start(snmptrapper_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_PROXYPOLLER: zbx_thread_start(proxypoller_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_SELFMON: zbx_thread_start(selfmon_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_VMWARE: zbx_thread_start(vmware_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_TASKMANAGER: zbx_thread_start(taskmanager_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_PREPROCMAN: zbx_thread_start(preprocessing_manager_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_PREPROCESSOR: zbx_thread_start(preprocessing_worker_thread, &thread_args, &threads[i]); break; #ifdef HAVE_OPENIPMI case ZBX_PROCESS_TYPE_IPMIMANAGER: zbx_thread_start(ipmi_manager_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_IPMIPOLLER: zbx_thread_start(ipmi_poller_thread, &thread_args, &threads[i]); break; #endif case ZBX_PROCESS_TYPE_ALERTMANAGER: zbx_thread_start(alert_manager_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_LLDMANAGER: zbx_thread_start(lld_manager_thread, &thread_args, &threads[i]); break; case ZBX_PROCESS_TYPE_LLDWORKER: zbx_thread_start(lld_worker_thread, &thread_args, &threads[i]); break; } } if (SUCCEED == zbx_is_export_enabled()) { zbx_history_export_init("main-process", 0); zbx_problems_export_init("main-process", 0); } while (-1 == wait(&i)) /* wait for any child to exit */ { if (EINTR != errno) { zabbix_log(LOG_LEVEL_ERR, "failed to wait on child processes: %s", zbx_strerror(errno)); break; } } /* all exiting child processes should be caught by signal handlers */ THIS_SHOULD_NEVER_HAPPEN; zbx_on_exit(); return SUCCEED; }
int MAIN_ZABBIX_ENTRY() { zbx_sock_t listen_sock; int i, db_type; if (NULL == CONFIG_LOG_FILE || '\0' == *CONFIG_LOG_FILE) zabbix_open_log(LOG_TYPE_SYSLOG, CONFIG_LOG_LEVEL, NULL); else zabbix_open_log(LOG_TYPE_FILE, CONFIG_LOG_LEVEL, CONFIG_LOG_FILE); #ifdef HAVE_NETSNMP # define SNMP_FEATURE_STATUS "YES" #else # define SNMP_FEATURE_STATUS " NO" #endif #ifdef HAVE_OPENIPMI # define IPMI_FEATURE_STATUS "YES" #else # define IPMI_FEATURE_STATUS " NO" #endif #ifdef HAVE_LIBCURL # define LIBCURL_FEATURE_STATUS "YES" #else # define LIBCURL_FEATURE_STATUS " NO" #endif #if defined(HAVE_LIBXML2) && defined(HAVE_LIBCURL) # define VMWARE_FEATURE_STATUS "YES" #else # define VMWARE_FEATURE_STATUS " NO" #endif #ifdef HAVE_UNIXODBC # define ODBC_FEATURE_STATUS "YES" #else # define ODBC_FEATURE_STATUS " NO" #endif #ifdef HAVE_SSH2 # define SSH2_FEATURE_STATUS "YES" #else # define SSH2_FEATURE_STATUS " NO" #endif #ifdef HAVE_IPV6 # define IPV6_FEATURE_STATUS "YES" #else # define IPV6_FEATURE_STATUS " NO" #endif zabbix_log(LOG_LEVEL_INFORMATION, "Starting Zabbix Proxy (%s) [%s]. Zabbix %s (revision %s).", ZBX_PROXYMODE_PASSIVE == CONFIG_PROXYMODE ? "passive" : "active", CONFIG_HOSTNAME, ZABBIX_VERSION, ZABBIX_REVISION); zabbix_log(LOG_LEVEL_INFORMATION, "**** Enabled features ****"); zabbix_log(LOG_LEVEL_INFORMATION, "SNMP monitoring: " SNMP_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "IPMI monitoring: " IPMI_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "WEB monitoring: " LIBCURL_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "VMware monitoring: " VMWARE_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "ODBC: " ODBC_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "SSH2 support: " SSH2_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "IPv6 support: " IPV6_FEATURE_STATUS); zabbix_log(LOG_LEVEL_INFORMATION, "**************************"); zabbix_log(LOG_LEVEL_INFORMATION, "using configuration file: %s", CONFIG_FILE); if (FAIL == load_modules(CONFIG_LOAD_MODULE_PATH, CONFIG_LOAD_MODULE, CONFIG_TIMEOUT, 1)) { zabbix_log(LOG_LEVEL_CRIT, "loading modules failed, exiting..."); exit(EXIT_FAILURE); } zbx_free_config(); init_database_cache(); init_configuration_cache(); init_selfmon_collector(); /* initialize vmware support */ if (0 != CONFIG_VMWARE_FORKS) zbx_vmware_init(); DBinit(); if (ZBX_DB_UNKNOWN == (db_type = zbx_db_get_database_type())) { zabbix_log(LOG_LEVEL_ERR, "cannot use database \"%s\": database is not a Zabbix database", CONFIG_DBNAME); exit(EXIT_FAILURE); } else if (ZBX_DB_PROXY != db_type) { zabbix_log(LOG_LEVEL_ERR, "cannot use database \"%s\": Zabbix proxy cannot work with a" " Zabbix server database", CONFIG_DBNAME); exit(EXIT_FAILURE); } if (SUCCEED != DBcheck_version()) exit(EXIT_FAILURE); DBconnect(ZBX_DB_CONNECT_NORMAL); DCsync_configuration(); DBclose(); threads_num = CONFIG_CONFSYNCER_FORKS + CONFIG_HEARTBEAT_FORKS + CONFIG_DATASENDER_FORKS + CONFIG_POLLER_FORKS + CONFIG_UNREACHABLE_POLLER_FORKS + CONFIG_TRAPPER_FORKS + CONFIG_PINGER_FORKS + CONFIG_HOUSEKEEPER_FORKS + CONFIG_HTTPPOLLER_FORKS + CONFIG_DISCOVERER_FORKS + CONFIG_HISTSYNCER_FORKS + CONFIG_IPMIPOLLER_FORKS + CONFIG_JAVAPOLLER_FORKS + CONFIG_SNMPTRAPPER_FORKS + CONFIG_SELFMON_FORKS + CONFIG_VMWARE_FORKS; threads = zbx_calloc(threads, threads_num, sizeof(pid_t)); if (0 != CONFIG_TRAPPER_FORKS) { if (FAIL == zbx_tcp_listen(&listen_sock, CONFIG_LISTEN_IP, (unsigned short)CONFIG_LISTEN_PORT)) { zabbix_log(LOG_LEVEL_CRIT, "listener failed: %s", zbx_tcp_strerror()); exit(EXIT_FAILURE); } } zabbix_log(LOG_LEVEL_INFORMATION, "proxy #0 started [main process]"); for (i = 0; i < threads_num; i++) { zbx_thread_args_t thread_args; unsigned char poller_type; if (FAIL == get_process_info_by_thread(i + 1, &thread_args.process_type, &thread_args.process_num)) { THIS_SHOULD_NEVER_HAPPEN; exit(EXIT_FAILURE); } thread_args.server_num = i + 1; thread_args.args = NULL; switch (thread_args.process_type) { case ZBX_PROCESS_TYPE_CONFSYNCER: threads[i] = zbx_thread_start(proxyconfig_thread, &thread_args); break; case ZBX_PROCESS_TYPE_HEARTBEAT: threads[i] = zbx_thread_start(heart_thread, &thread_args); break; case ZBX_PROCESS_TYPE_DATASENDER: threads[i] = zbx_thread_start(datasender_thread, &thread_args); break; case ZBX_PROCESS_TYPE_POLLER: poller_type = ZBX_PROCESS_TYPE_POLLER; thread_args.args = &poller_type; threads[i] = zbx_thread_start(poller_thread, &thread_args); break; case ZBX_PROCESS_TYPE_UNREACHABLE: poller_type = ZBX_PROCESS_TYPE_UNREACHABLE; thread_args.args = &poller_type; threads[i] = zbx_thread_start(poller_thread, &thread_args); break; case ZBX_PROCESS_TYPE_TRAPPER: thread_args.args = &listen_sock; threads[i] = zbx_thread_start(trapper_thread, &thread_args); break; case ZBX_PROCESS_TYPE_PINGER: threads[i] = zbx_thread_start(pinger_thread, &thread_args); break; case ZBX_PROCESS_TYPE_HOUSEKEEPER: threads[i] = zbx_thread_start(housekeeper_thread, &thread_args); break; case ZBX_PROCESS_TYPE_HTTPPOLLER: threads[i] = zbx_thread_start(httppoller_thread, &thread_args); break; case ZBX_PROCESS_TYPE_DISCOVERER: threads[i] = zbx_thread_start(discoverer_thread, &thread_args); break; case ZBX_PROCESS_TYPE_HISTSYNCER: threads[i] = zbx_thread_start(dbsyncer_thread, &thread_args); break; case ZBX_PROCESS_TYPE_IPMIPOLLER: poller_type = ZBX_PROCESS_TYPE_IPMIPOLLER; thread_args.args = &poller_type; threads[i] = zbx_thread_start(poller_thread, &thread_args); break; case ZBX_PROCESS_TYPE_JAVAPOLLER: poller_type = ZBX_PROCESS_TYPE_JAVAPOLLER; thread_args.args = &poller_type; threads[i] = zbx_thread_start(poller_thread, &thread_args); break; case ZBX_PROCESS_TYPE_SNMPTRAPPER: threads[i] = zbx_thread_start(snmptrapper_thread, &thread_args); break; case ZBX_PROCESS_TYPE_SELFMON: threads[i] = zbx_thread_start(selfmon_thread, &thread_args); break; case ZBX_PROCESS_TYPE_VMWARE: threads[i] = zbx_thread_start(vmware_thread, &thread_args); break; } } while (-1 == wait(&i)) /* wait for any child to exit */ { if (EINTR != errno) { zabbix_log(LOG_LEVEL_ERR, "failed to wait on child processes: %s", zbx_strerror(errno)); break; } } /* all exiting child processes should be caught by signal handlers */ THIS_SHOULD_NEVER_HAPPEN; zbx_on_exit(); return SUCCEED; }