plugin->priv->is_plugind_up = FALSE;
}
- if (plugin->priv->unref_in_down_cb) {
- plugin->priv->unref_in_down_cb = FALSE;
- g_object_unref (plugin);
- }
-}
-
-static gboolean
-_on_child_status_cb (
- GIOChannel *channel,
- GIOCondition condition,
- gpointer data)
-{
- GSignondPluginRemote *plugin = GSIGNOND_PLUGIN_REMOTE (data);
- DBG ("Plugind(%p) with pid (%d) status cb", plugin, plugin->priv->cpid);
-
- if (plugin->priv->main_loop && g_main_loop_is_running (
- plugin->priv->main_loop)) {
- g_main_loop_quit (plugin->priv->main_loop);
- }
-
- if (g_io_channel_get_flags (channel) & G_IO_FLAG_IS_READABLE) {
- gchar string[1];
- GError *error = NULL;
- gsize bytes_read = 0;
- GIOStatus status = g_io_channel_read_chars (channel, string, 1,
- &bytes_read, &error);
- if (status == G_IO_STATUS_NORMAL && error == NULL) {
- if (*string == '1') {
- DBG ("Plugind is UP and READY");
- plugin->priv->is_plugind_up = TRUE;
- } else if (*string == '0') {
- DBG ("Plugind is DOWN");
- plugin->priv->is_plugind_up = FALSE;
- }
- }
- if (error) {
- g_error_free (error);
- }
- }
-
- return FALSE;
}
static gboolean
}
static void
-_run_main_loop_with_ready_watch (
- GSignondPluginRemote *self,
- gint fd,
- guint timeout)
-{
- GIOChannel *ready_watch = NULL;
- GSource *up_source = NULL;
-
- GMainContext *context = g_main_context_new ();
- _create_main_loop_with_timeout (self, context, timeout);
-
- ready_watch = g_io_channel_unix_new (fd);
- up_source = g_io_create_watch (ready_watch, G_IO_IN | G_IO_HUP);
- g_source_set_callback (up_source, (GSourceFunc)_on_child_status_cb, self,
- NULL);
- g_source_attach (up_source, context);
- g_source_unref (up_source);
-
- _run_main_loop (self);
-
- g_io_channel_unref (ready_watch);
-}
-
-static void
gsignond_plugin_remote_set_property (
GObject *object,
guint property_id,
{
GSignondPluginRemote *self = GSIGNOND_PLUGIN_REMOTE (object);
- self->priv->unref_in_down_cb = FALSE;
-
if (self->priv->main_loop) {
if (g_main_loop_is_running (self->priv->main_loop)) {
g_main_loop_quit (self->priv->main_loop);
self->priv->main_loop = NULL;
self->priv->is_plugind_up = FALSE;
- self->priv->unref_in_down_cb = FALSE;
}
static void
plugin->priv->child_watch_id = g_child_watch_add (cpid,
(GChildWatchFunc)_on_child_down_cb, plugin);
plugin->priv->cpid = cpid;
-
- _run_main_loop_with_ready_watch (plugin, cout_fd, 1000);
- if (!plugin->priv->is_plugind_up) {
- DBG ("Plugind (%s) with pid %d process failed to start up", plugin_type,
- cpid);
- /* moved unref'ng into the cb to avoid zombies */
- plugin->priv->unref_in_down_cb = TRUE;
- return NULL;
- }
+ plugin->priv->is_plugind_up = TRUE;
/* Create dbus connection */
stream = gsignond_pipe_stream_new (cout_fd, cin_fd, TRUE);
GMainLoop *main_loop = NULL;
GOptionContext *opt_context = NULL;
gchar **plugin_args = NULL;
- gint up_signal = -1;
gint in_fd = 0, out_fd = 1;
GOptionEntry opt_entries[] = {
{G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &plugin_args,
}
if (!plugin_args || !plugin_args[0] || !plugin_args[1]) {
WARN ("plugin path or plugin type missing");
- if (write (out_fd, "0", sizeof(char)) == -1)
- WARN ("Unable to write down notification to stdout");
- if (in_fd != 0) close (in_fd);
- if (out_fd != 1) close (out_fd);
if (plugin_args) g_strfreev(plugin_args);
return -1;
}
out_fd);
g_strfreev(plugin_args);
if (_daemon == NULL) {
- if (write (out_fd, "0", sizeof(char)) == -1)
- WARN ("Unable to write down notification to stdout");
- if (in_fd != 0) close (in_fd);
- if (out_fd != 1) close (out_fd);
return -1;
}
g_object_weak_ref (G_OBJECT (_daemon), _on_daemon_closed, main_loop);
_install_sighandlers (main_loop);
- /* Notification for gsignond that plugind is up and ready */
- up_signal = write (out_fd, "1", sizeof(char));
-
- if (up_signal == -1) {
- g_main_loop_unref (main_loop);
- g_object_unref (_daemon);
- return -1;
- }
-
DBG ("Entering main event loop");
g_main_loop_run (main_loop);