예제 #1
0
void	main_trapper_loop(zbx_sock_t *s)
{
	const char	*__function_name = "main_trapper_loop";

	zabbix_log(LOG_LEVEL_DEBUG, "In %s()", __function_name);

	zbx_setproctitle("%s [connecting to the database]", get_process_type_string(process_type));

	DBconnect(ZBX_DB_CONNECT_NORMAL);

	for (;;)
	{
		zbx_setproctitle("%s [waiting for connection]", get_process_type_string(process_type));

		update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);

		if (SUCCEED == zbx_tcp_accept(s))
		{
			update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);

			zbx_setproctitle("%s [processing data]", get_process_type_string(process_type));

			process_trapper_child(s);

			zbx_tcp_unaccept(s);
		}
		else
			zabbix_log(LOG_LEVEL_WARNING, "Trapper failed to accept connection");
	}
}
예제 #2
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_sleep_loop                                                   *
 *                                                                            *
 * Purpose: sleeping process                                                  *
 *                                                                            *
 * Parameters: sleeptime - [IN] required sleeptime, in seconds                *
 *                                                                            *
 * Return value:                                                              *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 * Comments:                                                                  *
 *                                                                            *
 ******************************************************************************/
void	zbx_sleep_loop(int sleeptime)
{
#ifdef HAVE_FUNCTION_SETPROCTITLE
	extern unsigned char	process_type;
	const char		*process_type_string;
#endif	/* HAVE_FUNCTION_SETPROCTITLE */

	if (sleeptime <= 0)
		return;

	zabbix_log(LOG_LEVEL_DEBUG, "sleeping for %d seconds", sleeptime);

	update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);

#ifdef HAVE_FUNCTION_SETPROCTITLE
	process_type_string = get_process_type_string(process_type);

	do
	{
		zbx_setproctitle("%s [sleeping for %d seconds]", process_type_string, sleeptime);
		sleep(1);
	}
	while (--sleeptime > 0);
#else
	sleep(sleeptime);
#endif	/* HAVE_FUNCTION_SETPROCTITLE */

	update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
}
예제 #3
0
/******************************************************************************
 *                                                                            *
 * Function: zbx_sleep_loop                                                   *
 *                                                                            *
 * Purpose: sleeping process                                                  *
 *                                                                            *
 * Parameters: sleeptime - [IN] required sleeptime, in seconds                *
 *                                                                            *
 * Author: Alexander Vladishev                                                *
 *                                                                            *
 ******************************************************************************/
void	zbx_sleep_loop(int sleeptime)
{
#ifdef HAVE_FUNCTION_SETPROCTITLE
	extern unsigned char	process_type;
	const char		*process_type_string;
#endif

	if (0 >= sleeptime)
		return;

	sleep_remains = sleeptime;

	zabbix_log(LOG_LEVEL_DEBUG, "sleeping for %d seconds", sleep_remains);

	update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);

#ifdef HAVE_FUNCTION_SETPROCTITLE
	process_type_string = get_process_type_string(process_type);
#endif

	do
	{
#ifdef HAVE_FUNCTION_SETPROCTITLE
		zbx_setproctitle("%s [sleeping for %d seconds]", process_type_string, sleep_remains);
#endif
		sleep(1);
	}
	while (0 < --sleep_remains);

	update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);
}
예제 #4
0
ZBX_THREAD_ENTRY(trapper_thread, args)
{
	double		sec = 0.0;
	zbx_socket_t	s;

	process_type = ((zbx_thread_args_t *)args)->process_type;
	server_num = ((zbx_thread_args_t *)args)->server_num;
	process_num = ((zbx_thread_args_t *)args)->process_num;

	zabbix_log(LOG_LEVEL_INFORMATION, "%s #%d started [%s #%d]", get_program_type_string(program_type),
			server_num, get_process_type_string(process_type), process_num);

	memcpy(&s, (zbx_socket_t *)((zbx_thread_args_t *)args)->args, sizeof(zbx_socket_t));

#if defined(HAVE_POLARSSL) || defined(HAVE_GNUTLS) || defined(HAVE_OPENSSL)
	zbx_tls_init_child();
	find_psk_in_cache = DCget_psk_by_identity;
#endif
	zbx_setproctitle("%s #%d [connecting to the database]", get_process_type_string(process_type), process_num);

	DBconnect(ZBX_DB_CONNECT_NORMAL);

	for (;;)
	{
		zbx_handle_log();

		zbx_setproctitle("%s #%d [processed data in " ZBX_FS_DBL " sec, waiting for connection]",
				get_process_type_string(process_type), process_num, sec);

		update_selfmon_counter(ZBX_PROCESS_STATE_IDLE);

		/* Trapper has to accept all types of connections it can accept with the specified configuration. */
		/* Only after receiving data it is known who has sent them and one can decide to accept or discard */
		/* the data. */
		if (SUCCEED == zbx_tcp_accept(&s, ZBX_TCP_SEC_TLS_CERT | ZBX_TCP_SEC_TLS_PSK | ZBX_TCP_SEC_UNENCRYPTED))
		{
			zbx_timespec_t	ts;

			/* get connection timestamp */
			zbx_timespec(&ts);

			update_selfmon_counter(ZBX_PROCESS_STATE_BUSY);

			zbx_setproctitle("%s #%d [processing data]", get_process_type_string(process_type),
					process_num);

			sec = zbx_time();
			process_trapper_child(&s, &ts);
			sec = zbx_time() - sec;

			zbx_tcp_unaccept(&s);
		}
		else if (EINTR != zbx_socket_last_error())
		{
			zabbix_log(LOG_LEVEL_WARNING, "failed to accept an incoming connection: %s",
					zbx_socket_strerror());
		}
	}
}