static void mpd_report_error(void) { const gchar *error = mpd_connection_get_error_message(mpd.conn); g_warning("MPD error: %s", error); irc_say("MPD error: %s", error); if (mpd_connection_clear_error(mpd.conn)) { g_warning("Unable to recover, reconnecting"); mpd_disconnect(); mpd_schedule_reconnect(); } }
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(); }