Пример #1
0
/**
 * main() - entry point
 *
 * Declare VRRP instance, init daemon
 * and launch state machine
 */
int main(int argc, char *argv[])
{
	signal_setup();

	/* Current VRRP instance */
	struct vrrp vrrp;
	struct vrrp_net vnet;

	/* Init VRRP instance */
	vrrp_init(&vrrp);
	vrrp_net_init(&vnet);

	/* cmdline options */
	if (! !vrrp_options(&vrrp, &vnet, argc, argv))
		exit(EXIT_FAILURE);

	/* pidfile init && check */
	if (pidfile_init(vrrp.vrid) != 0)
		exit(EXIT_FAILURE);

	pidfile_check(vrrp.vrid);

	/* logs */
	log_open("uvrrpd", (char const *) loglevel);

	/* open sockets */
	if ((vrrp_net_socket(&vnet) != 0) || (vrrp_net_socket_xmit(&vnet) != 0))
		exit(EXIT_FAILURE);

	/* hook script */
	if (vrrp_exec_init(&vrrp) != 0)
		exit(EXIT_FAILURE);

	/* advertisement pkt */
	if (vrrp_adv_init(&vnet, &vrrp) != 0)
		exit(EXIT_FAILURE);

	/* net topology */
	if (vnet.family == AF_INET) {
		if (vrrp_arp_init(&vnet) != 0)
			exit(EXIT_FAILURE);
	}
	else if (vnet.family == AF_INET6) {
		if (vrrp_na_init(&vnet) != 0)
			exit(EXIT_FAILURE);
	}

	/* daemonize */
	if (background) {
		daemon(0, (log_trigger(NULL) > LOG_INFO));
	}
	else
		chdir("/");


	/* pidfile */
	pidfile(vrrp.vrid);

	/* process */
	set_bit(KEEP_GOING, &reg);
	while (test_bit(KEEP_GOING, &reg) && !vrrp_process(&vrrp, &vnet));

	/* shutdown */
	vrrp_adv_cleanup(&vnet);

	if (vnet.family == AF_INET)
		vrrp_arp_cleanup(&vnet);
	else	/* AF_INET6 */
		vrrp_na_cleanup(&vnet);

	vrrp_cleanup(&vrrp);
	vrrp_exec_cleanup(&vrrp);
	vrrp_net_cleanup(&vnet);

	log_close();
	free(loglevel);
	pidfile_unlink();
	free(pidfile_name);

	return EXIT_SUCCESS;
}
Пример #2
0
void log_open(char const *app, char const *level)
{
	openlog(app ? app : "-", LOG_PERROR | LOG_PID, LOG_DAEMON);
	log_trigger(level);
}