示例#1
0
int main(int argc, char *argv[])
{
	struct sigaction sa;

	g_type_init();

	notify_info.argv = argv;

	init_preferences(argc, argv);

	/* Fork when wanted */
	if (prefs.fork)
		daemonize();

	log_init();

	g_log_set_default_handler(notify_log, NULL);

	loop = g_main_loop_new(NULL, FALSE);

	g_message(PACKAGE_STRING " started");

	/* Fire up listening sockets */
	if (!start_listener()) {
		cleanup();
		exit(EXIT_FAILURE);
	}

	/* Connect to IRC */
	irc_connect(NULL);

	/* Signal handler */
	ns_open_signal_pipe();
	sa.sa_handler = ns_sighandler;
	sigfillset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);
	sigaction(SIGHUP, &sa, NULL);

	g_main_loop_run(loop);

	cleanup();
}
示例#2
0
文件: scmpc.c 项目: theVDude/scmpc
int main(int argc, char *argv[])
{
	pid_t pid;
	struct sigaction sa;

	if (init_preferences(argc, argv) == FALSE)
		g_error("Config file parsing failed");

	/* Open the log file before forking, so that if there is an error, the
	 * user will get some idea what is going on */
	open_log(prefs.log_file);

	g_log_set_default_handler(scmpc_log, NULL);

	/* Check if scmpc is already running */
	if ((pid = scmpc_is_running()) > 0) {
		clear_preferences();
		g_error("Daemon is already running with PID: %ld", (long)pid);
	}

	/* Daemonise if wanted */
	if (prefs.fork)
		daemonise();

	/* Signal handler */
	open_signal_pipe();
	sa.sa_handler = sighandler;
	sigfillset(&sa.sa_mask);
	sa.sa_flags = SA_RESTART;
	sigaction(SIGINT, &sa, NULL);
	sigaction(SIGTERM, &sa, NULL);
	sigaction(SIGQUIT, &sa, NULL);

	if (as_connection_init() == FALSE) {
		scmpc_cleanup();
		exit(EXIT_FAILURE);
	}
	as_authenticate();

	queue_init();
	queue_load();

	// submit the loaded queue
	as_check_submit();

	mpd.song_pos = g_timer_new();
	mpd.idle_source = 0;
	if (!mpd_connect()) {
		mpd_disconnect();
		mpd_schedule_reconnect();
	}

	// set up main loop events
	loop = g_main_loop_new(NULL, FALSE);

	// save queue
	if (prefs.cache_interval > 0) {
		cache_save_source = g_timeout_add_seconds(prefs.cache_interval * 60,
				queue_save, NULL);
	}

	g_main_loop_run(loop);

	scmpc_cleanup();
}