예제 #1
0
static void
destroy(void)
{
	g_message("Exiting");
	as_save_cache();
	as_cleanup();
	http_client_finish();
	file_cleanup();
	g_timer_destroy(timer);
	g_source_remove(save_source_id);
	if (prev != NULL)
		mpd_song_free(prev);
}
예제 #2
0
int main(int argc, char **argv)
{
    daemonize_close_stdin();

    parse_cmdline(argc, argv);

    if (!file_read_config())
        g_error("cannot read configuration file\n");

    log_init(file_config.log, file_config.verbose);

    daemonize_init(file_config.daemon_user, file_config.pidfile);

    if (!file_config.no_daemon)
        daemonize_detach();

    daemonize_write_pidfile();
    daemonize_set_user();

#ifndef NDEBUG
    if (!file_config.no_daemon)
#endif
        daemonize_close_stdout_stderr();

    main_loop = g_main_loop_new(NULL, FALSE);

    lmc_connect(file_config.host, file_config.port);
    http_client_init();
    as_init(file_config.scrobblers);

    setup_signals();

    timer = g_timer_new();

    /* set up timeouts */

    save_source_id = g_timeout_add_seconds(file_config.journal_interval,
                                           timer_save_journal, NULL);

    /* run the main loop */

    g_main_loop_run(main_loop);

    /* cleanup */

    g_message("shutting down\n");

    g_source_remove(save_source_id);
    g_main_loop_unref(main_loop);

    g_timer_destroy(timer);

    as_save_cache();
    as_cleanup();
    http_client_finish();
    lmc_disconnect();
    file_cleanup();
    log_deinit();

    daemonize_finish();

    return 0;
}