void exit_handler() { g_debug("Entering exit handler..."); plugins_close(); session_logout(); g_message("Exiting."); }
int logout(int argc, char **argv) { session_logout(); return 0; }
int main(int argc, char *argv[]) { int timeout = 0; sp_error error; int notify_cmdline = 0; int notify_events = 0; struct timespec ts; (void)argc; (void)argv; pthread_mutex_init(&g_notify_mutex, NULL); pthread_cond_init(&g_notify_cond, NULL); session_init(); cmd_init(cmd_notify); do { clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += timeout / 1000; ts.tv_nsec += (timeout % 1000) * 1E6; if (ts.tv_nsec > 1E9) { ts.tv_sec++; ts.tv_nsec -= 1E9; } pthread_mutex_lock(&g_notify_mutex); pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts); notify_cmdline = g_notify_cmdline; notify_events = g_notify_events; g_notify_cmdline = 0; g_notify_events = 0; pthread_mutex_unlock(&g_notify_mutex); if (notify_cmdline) { cmd_process(); } if (notify_events) { do { error = sp_session_process_events(g_session, &timeout); if (error != SP_ERROR_OK) fprintf(stderr, "error processing events: %s\n", sp_error_message(error)); } while (timeout == 0); } } while (!is_program_finished()); session_logout(); while (session_is_logged_in()) { clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 1; pthread_mutex_lock(&g_notify_mutex); pthread_cond_timedwait(&g_notify_cond, &g_notify_mutex, &ts); notify_events = g_notify_events; g_notify_events = 0; pthread_mutex_unlock(&g_notify_mutex); if (notify_events) { do { error = sp_session_process_events(g_session, &timeout); if (error != SP_ERROR_OK) fprintf(stderr, "error processing events: %s\n", sp_error_message(error)); } while (timeout == 0); } } session_release(); cmd_destroy(); pthread_mutex_destroy(&g_notify_mutex); pthread_cond_destroy(&g_notify_cond); return 0; }