static void on_channel_closed (CockpitChannel *channel, const gchar *problem, gpointer user_data) { g_hash_table_remove (channels, cockpit_channel_get_id (channel)); }
static void on_channel_closed (CockpitChannel *local, const gchar *problem, gpointer user_data) { CockpitRouter *self = COCKPIT_ROUTER (user_data); const gchar *channel; GQueue *fenced; GList *l; channel = cockpit_channel_get_id (local); g_hash_table_remove (self->channels, channel); g_hash_table_remove (self->groups, channel); /* * If this was the last channel in the fence group then resume all other channels * as there's no barrier preventing them from functioning. */ if (!g_hash_table_remove (self->fences, channel) || g_hash_table_size (self->fences) != 0) return; fenced = self->fenced; self->fenced = NULL; if (!fenced) return; for (l = fenced->head; l != NULL; l = g_list_next (l)) cockpit_transport_thaw (self->transport, l->data); g_queue_free_full (fenced, g_free); }
static void create_channel (CockpitRouter *self, const gchar *channel, JsonObject *options, GType type) { CockpitChannel *local; local = g_object_new (type, "transport", self->transport, "id", channel, "options", options, NULL); /* This owns the local channel */ g_hash_table_replace (self->channels, (gpointer)cockpit_channel_get_id (local), local); g_signal_connect (local, "closed", G_CALLBACK (on_channel_closed), self); }
static void process_kill (CockpitRouter *self, JsonObject *options) { GHashTableIter iter; const gchar *group = NULL; const gchar *host = NULL; GList *list, *l; if (!cockpit_json_get_string (options, "group", NULL, &group)) { g_warning ("received invalid \"group\" field in kill command"); return; } else if (!cockpit_json_get_string (options, "host", NULL, &host)) { g_warning ("received invalid \"host\" field in kill command"); return; } /* Killing on other hosts is handled elsewhere */ if (host && g_strcmp0 (host, self->init_host) != 0) return; list = NULL; if (group) { gpointer id, channel_group; g_hash_table_iter_init (&iter, self->groups); while (g_hash_table_iter_next (&iter, &id, &channel_group)) { CockpitChannel *channel; if (!g_str_equal (group, channel_group)) continue; channel = g_hash_table_lookup (self->channels, id); if (channel) list = g_list_prepend (list, g_object_ref (channel)); } } else { gpointer id, channel; g_hash_table_iter_init (&iter, self->channels); while (g_hash_table_iter_next (&iter, &id, &channel)) list = g_list_prepend (list, g_object_ref (channel)); } for (l = list; l != NULL; l = g_list_next (l)) { CockpitChannel *channel = l->data; g_debug ("killing channel: %s", cockpit_channel_get_id (channel)); cockpit_channel_close (channel, "terminated"); g_object_unref (channel); } g_list_free (list); }