/** ========================================================================= */ static void * create(struct osm_opensm *osm) { struct timespec ts; plugin_data_t *plugin_data = NULL; pthread_attr_t th_attr; int rc = 0; if (!(plugin_data = malloc(sizeof(*plugin_data)))) return (NULL); plugin_data->osmlog = &(osm->log); if (!construct_plugin_data(plugin_data)) { plugin_log(plugin_data->osmlog, OSM_LOG_ERROR, "Failed to read %s\n", DATABASE_CONF); free(plugin_data); return (NULL); } if (pthread_attr_init(&(th_attr))) { free_plugin_data(plugin_data); return (NULL); } pthread_mutex_lock(&(plugin_data->sig_lock)); if (pthread_create(&(plugin_data->thread), &(th_attr), db_write_thread, (void *)plugin_data)) { plugin_log(plugin_data->osmlog, OSM_LOG_INFO, "Failed to create DB write thread\n"); pthread_attr_destroy(&(th_attr)); free_plugin_data(plugin_data); return (NULL); } pthread_attr_destroy(&(th_attr)); clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += 2; /* give 2 sec to start up */ rc = pthread_cond_timedwait(&(plugin_data->signal), &(plugin_data->sig_lock), &ts); pthread_mutex_unlock(&(plugin_data->sig_lock)); if (rc == ETIMEDOUT) { plugin_log(plugin_data->osmlog, OSM_LOG_ERROR, "DB write thread failed to initialize\n"); pthread_join(plugin_data->thread, NULL); free_plugin_data(plugin_data); return (NULL); } plugin_log(plugin_data->osmlog, OSM_LOG_INFO, "DB write thread started\n"); return ((void *)plugin_data); }
static void plainprpl_close(PurpleConnection *gc) { purple_debug_info("plainprpl", "plainprpl_close\n"); PurpleAccount *account; PurpleBuddy *buddy; plain_plugin_state *pstate; plain_buddy_state *bstate; const char *on_logout; /* notify other plainprpl accounts */ account = purple_connection_get_account(gc); pstate = purple_connection_get_protocol_data(gc); /* Notifiy all buddies that we are gone */ GSList *iter = pstate->all_buddies; while (iter) { buddy = iter->data; bstate = purple_buddy_get_protocol_data(buddy); PurplePresence *presence = purple_buddy_get_presence(buddy); PurpleStatus *status = purple_presence_get_active_status(presence); PurpleStatusType *status_type = purple_status_get_type(status); PurpleStatusPrimitive status_primitive = purple_status_type_get_primitive(status_type); if (bstate && status_primitive == PURPLE_STATUS_AVAILABLE) { send_msg(pstate, bstate, "/bye"); } iter = iter->next; } //remove timers purple_timeout_remove(pstate->receive_timer); on_logout = purple_account_get_string(account, "on_logout", NULL); exec_process(on_logout, NULL, NULL, gc, NULL); free_plugin_data(pstate); }