Пример #1
0
G_MODULE_EXPORT gboolean
hud_enter_cb(
    GtkWidget *widget,
    GdkEventCrossing *event,
    signal_user_data_t *ud)
{
    if (hud_timeout_id != 0)
    {
        GMainContext *mc;
        GSource *source;

        mc = g_main_context_default();
        source = g_main_context_find_source_by_id(mc, hud_timeout_id);
        if (source != NULL)
            g_source_destroy(source);
    }
    widget = GHB_WIDGET(ud->builder, "preview_hud");
    if (!gtk_widget_get_visible(widget))
    {
        gtk_widget_show(widget);
    }
    hud_timeout_id = 0;
    in_hud = TRUE;
    return FALSE;
}
Пример #2
0
static void
_gck_call_base_finalize (GckCallClass *klass)
{
	GMainContext *context;
	GSource *src;

	if (klass->thread_pool) {
		g_assert (g_thread_pool_unprocessed (klass->thread_pool) == 0);
		g_thread_pool_free (klass->thread_pool, FALSE, TRUE);
		klass->thread_pool = NULL;
	}

	if (klass->completed_id) {
		context = g_main_context_default ();
		g_return_if_fail (context);

		src = g_main_context_find_source_by_id (context, klass->completed_id);
		g_assert (src);
		g_source_destroy (src);
		klass->completed_id = 0;
	}

	if (klass->completed_queue) {
		g_assert (g_async_queue_length (klass->completed_queue));
		g_async_queue_unref (klass->completed_queue);
		klass->completed_queue = NULL;
	}
}
Пример #3
0
static void Finish( gpointer dlg ) {
    int timer_id;
    timer_id = (intptr_t) g_object_get_data(G_OBJECT(dlg),"timer");
    g_source_destroy(g_main_context_find_source_by_id(g_main_context_default(),
	    timer_id));
    gtk_widget_destroy(dlg);
}
Пример #4
0
G_MODULE_EXPORT gboolean
preview_motion_cb(
    GtkWidget *widget,
    GdkEventMotion *event,
    signal_user_data_t *ud)
{
    if (hud_timeout_id != 0)
    {
        GMainContext *mc;
        GSource *source;

        mc = g_main_context_default();
        source = g_main_context_find_source_by_id(mc, hud_timeout_id);
        if (source != NULL)
            g_source_destroy(source);
    }
    widget = GHB_WIDGET(ud->builder, "preview_hud");
    if (!gtk_widget_get_visible(widget))
    {
        gtk_widget_show(widget);
    }
    if (!in_hud)
    {
        hud_timeout_id = g_timeout_add_seconds(4, (GSourceFunc)hud_timeout, ud);
    }
    return FALSE;
}
Пример #5
0
static void 
gw_spellcheck_remove_signals (GwSpellcheck *spellcheck)
{
    //Declarations
    GwSpellcheckPrivate *priv;
    LwPreferences *preferences;
    GtkEntry *entry;
    GSource *source;
    int i;

    priv = spellcheck->priv;
    preferences = gw_application_get_preferences (priv->application);
    entry = priv->entry;

    if (priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY] != 0)
    {
      lw_preferences_remove_change_listener_by_schema (
          preferences, 
          LW_SCHEMA_BASE, 
          priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY]
      );
      priv->signalid[GW_SPELLCHECK_SIGNALID_DICTIONARY] = 0;
    }

    if (priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV] != 0)
    {
      lw_preferences_remove_change_listener_by_schema (
          preferences, 
          LW_SCHEMA_BASE, 
          priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV]
      );
      priv->signalid[GW_SPELLCHECK_SIGNALID_RK_CONV] = 0;
    }

    for (i = 0; i < TOTAL_GW_SPELLCHECK_SIGNALIDS && entry != NULL; i++)
    {
      if (priv->signalid[i] > 0)
      {
        g_signal_handler_disconnect (G_OBJECT (entry), priv->signalid[i]);
        priv->signalid[i] = 0;
      }
    }

    for (i = 0; i < TOTAL_GW_SPELLCHECK_TIMEOUTIDS; i++)
    {
      if (g_main_current_source () != NULL &&
          !g_source_is_destroyed (g_main_current_source ()) &&
          priv->timeoutid[i] > 0
         )
      {
        source = g_main_context_find_source_by_id (NULL, priv->timeoutid[i]);
        if (source != NULL)
        {
          g_source_destroy (source);
        }
      }
      priv->timeoutid[i] = 0;
    }
}
Пример #6
0
void
g_timeout2_set_interval(guint source_id, guint32 interval)
{
	GSource *source = g_main_context_find_source_by_id(g_main_context_default(), source_id);
	GTimeoutSource *timeout_source = (GTimeoutSource *)source;

	timeout_source->interval = interval;	
}
Пример #7
0
static void
gw_kanjipadwindow_finalize (GObject *object)
{
    GwKanjipadWindow *window;
    GwKanjipadWindowPrivate *priv;
    GSource *source;
    GError *error;
    GList *link;

    window = GW_KANJIPADWINDOW (object);
    priv = window->priv;
    error = NULL;

    for (link = priv->strokes; link != NULL; link = link->next)
      gw_kanjipadwindow_free_drawingarea_stroke (link->data);
    if (priv->strokes != NULL) g_list_free (priv->strokes); priv->strokes = NULL;
    if (priv->strokes != NULL) g_list_free (priv->curstroke); priv->curstroke = NULL;

    if (priv->ksurface != NULL) cairo_surface_destroy (priv->ksurface); priv->ksurface = NULL;
    if (priv->surface != NULL) cairo_surface_destroy (priv->surface); priv->surface = NULL;

    if (g_main_current_source () != NULL &&
        !g_source_is_destroyed (g_main_current_source ()) &&
        priv->iowatchid > 0
       )
    {
      source = g_main_context_find_source_by_id (NULL, priv->iowatchid);
      if (source != NULL)
      {
        g_source_destroy (source);
      }
    }
    priv->iowatchid = 0;

    if (error == NULL) 
    {
      g_io_channel_shutdown (priv->from_engine, FALSE, &error);
      g_io_channel_unref (priv->from_engine);
      priv->from_engine = NULL;
    }

    if (error == NULL)
    {
      g_io_channel_shutdown (priv->to_engine, FALSE, &error);
      g_io_channel_unref (priv->to_engine);
      priv->to_engine = NULL;
    }

    g_spawn_close_pid (priv->engine_pid);

    if (error != NULL)
    {
      fprintf(stderr, "Errored: %s\n", error->message);
      exit(EXIT_FAILURE);
    }

    G_OBJECT_CLASS (gw_kanjipadwindow_parent_class)->finalize (object);
}
Пример #8
0
void
G_main_setdescription_id(guint id, const char * description)
{
	GSource* source = g_main_context_find_source_by_id(NULL,id);
	
	if (source) {
		G_main_setdescription(source, description);
	}
}
Пример #9
0
void
G_main_setmaxdispatchtime_id(guint id, unsigned long dispatchms)
{
	GSource* source = g_main_context_find_source_by_id(NULL,id);
	
	if (source) {
		G_main_setmaxdispatchtime(source, dispatchms);
	}
}
/*!
 * \brief Detruit une instance CalculateUI
 */
void calculate_ui_destroy (PtrCalculateUI *calculate_ui)
{
	assert (*calculate_ui != NULL );
	
	GSource *timeout = g_main_context_find_source_by_id (NULL, (*calculate_ui) -> timeout_refresh_id);
	g_source_destroy (timeout);
	calculate_worker_destroy (&((*calculate_ui) -> calculate_worker));
	free (*calculate_ui);
	*calculate_ui = NULL;
}
Пример #11
0
/* Unrefs and resets the given timer and destroys its event source.
 * \param L The Lua VM state.
 * \param timer The timer structure.
 */
static void
luaH_timer_destroy(lua_State *L, ltimer_t *timer) {
    GSource *source = g_main_context_find_source_by_id(NULL, timer->timer_id);
    if (source != NULL) {
        g_source_destroy(source);
    }
    luaH_object_unref(L, timer->ref); // now the timer may be garbage collected
    timer->ref = NULL;
    timer->timer_id = TIMER_STOPPED;
}
Пример #12
0
void gw_destroy_source(guint & event_id)
// This is a combined wrapper for convenience.
{
  if (event_id) {
    GSource *source = g_main_context_find_source_by_id(NULL, event_id);
    if (source)
      g_source_destroy(source);
  }
  event_id = 0;
}
Пример #13
0
static void
luaH_timer_destroy(lua_State *L, ltimer_t *timer) {
    GSource *source = g_main_context_find_source_by_id(NULL, timer->id);
    if (source != NULL)
        g_source_destroy(source);

    /* allow timer to be garbage collected */
    luaH_object_unref(L, timer->ref);
    timer->ref = NULL;

    timer->id = TIMER_STOPPED;
}
Пример #14
0
gboolean
kms_loop_remove (KmsLoop * self, guint source_id)
{
  GSource *source;

  source = g_main_context_find_source_by_id (self->priv->context, source_id);

  if (source == NULL) {
    return FALSE;
  }

  g_source_destroy (source);
  return TRUE;
}
Пример #15
0
static gboolean
remove (GCutEventLoop *loop, guint tag)
{
    GCutGLibEventLoopPrivate *priv;
    GSource *source;
    GMainContext *context;

    priv = GCUT_GLIB_EVENT_LOOP_GET_PRIVATE(loop);
    context = g_main_loop_get_context(priv->loop);
    source = g_main_context_find_source_by_id(context, tag);
    if (source)
        g_source_destroy(source);

    return source != NULL;
}
Пример #16
0
gboolean
i_source_remove (guint tag, GMainContext* context)
{
    GSource* source;

    g_return_val_if_fail(tag > 0, FALSE);

    source = g_main_context_find_source_by_id(context, tag);

    if (source != NULL)
    {
        g_source_destroy(source);
    }

    return (source != NULL);
}
Пример #17
0
void
Gmain_timeout_remove(guint tag)
{
	GSource* source = g_main_context_find_source_by_id(NULL,tag);
	struct GTimeoutAppend* append = GTIMEOUT(source);
	
	if (source == NULL){
		cl_log(LOG_ERR, "Attempt to remove timeout (%u)"
		" with NULL source",	tag);
	}else{
		g_assert(IS_TIMEOUTSRC(append));
		g_source_remove(tag);
	}
	
	return;
}
Пример #18
0
GSource *qio_channel_add_watch_source(QIOChannel *ioc,
                                      GIOCondition condition,
                                      QIOChannelFunc func,
                                      gpointer user_data,
                                      GDestroyNotify notify,
                                      GMainContext *context)
{
    GSource *source;
    guint id;

    id = qio_channel_add_watch_full(ioc, condition, func,
                                    user_data, notify, context);
    source = g_main_context_find_source_by_id(context, id);
    g_source_ref(source);
    return source;
}
Пример #19
0
G_MODULE_EXPORT gboolean
preview_leave_cb(
    GtkWidget *widget,
    GdkEventCrossing *event,
    signal_user_data_t *ud)
{
    if (hud_timeout_id != 0)
    {
        GMainContext *mc;
        GSource *source;

        mc = g_main_context_default();
        source = g_main_context_find_source_by_id(mc, hud_timeout_id);
        if (source != NULL)
            g_source_destroy(source);
    }
    hud_timeout_id = g_timeout_add(300, (GSourceFunc)hud_timeout, ud);
    return FALSE;
}
Пример #20
0
static void
log_db_parser_deinit(LogParser *s, GlobalConfig *cfg)
{
  LogDBParser *self = (LogDBParser *) s;

  if (self->initialized)
    {
      if (self->timer_tick_id)
        {
          GSource *source = g_main_context_find_source_by_id(NULL, self->timer_tick_id);

          g_source_destroy(source);
          self->timer_tick_id = 0;
        }

      cfg_persist_config_add(cfg, log_db_parser_format_persist_name(self), self->db, (GDestroyNotify) pattern_db_free, FALSE);
      self->db = NULL;
      self->initialized = FALSE;
    }
}
Пример #21
0
static void
thunar_uca_provider_finalize (GObject *object)
{
  ThunarUcaProvider *uca_provider = THUNAR_UCA_PROVIDER (object);
  GSource           *source;

  /* give up maintaince of any pending child watch */
  if (G_UNLIKELY (uca_provider->child_watch_id >= 0))
    {
      /* reset the callback function to g_spawn_close_pid() so the plugin can be
       * safely unloaded and the child will still not become a zombie afterwards.
       * This also resets the child_watch_id and child_watch_path properties.
       */
      source = g_main_context_find_source_by_id (NULL, uca_provider->child_watch_id);
      g_source_set_callback (source, (GSourceFunc) g_spawn_close_pid, NULL, NULL);
    }

  /* drop our reference on the model */
  g_object_unref (G_OBJECT (uca_provider->model));

  (*G_OBJECT_CLASS (thunar_uca_provider_parent_class)->finalize) (object);
}
Пример #22
0
static void
set_property (GObject *object, guint prop_id, const GValue *value,
	GParamSpec *pspec)
{
	SummerFeedPrivate *priv;
	priv = SUMMER_FEED (object)->priv;

	switch (prop_id) {
	case PROP_CACHE_DIR:
		if (priv->cache_dir)
			g_free (priv->cache_dir);
		priv->cache_dir = g_value_dup_string (value);
		break;
	case PROP_FREQUENCY:
		priv->frequency = g_value_get_int (value);
		if (priv->timeout > 0) { // Is there a timeout running?
			GMainContext *context = g_main_context_default ();
			GSource *source = g_main_context_find_source_by_id (
				context,
				priv->timeout);
			g_source_destroy (source);
			priv->timeout = g_timeout_add_seconds (
				priv->frequency,
				(GSourceFunc) download_timeout,
				object);
		}

		break;
	case PROP_URL:
		if (priv->url)
			g_free (priv->url);
		priv->url = g_value_dup_string (value);
		break;
	default:
		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
		break;
	}
}
Пример #23
0
static gboolean
keyboard_repeat (gpointer data)
{
  ClutterSeatEvdev *seat = data;
  GSource *source;

  /* There might be events queued in libinput that could cancel the
     repeat timer. */
  _clutter_device_manager_evdev_dispatch (seat->manager_evdev);
  if (!seat->repeat_timer)
    return G_SOURCE_REMOVE;

  g_return_val_if_fail (seat->repeat_device != NULL, G_SOURCE_REMOVE);
  source = g_main_context_find_source_by_id (NULL, seat->repeat_timer);

  clutter_seat_evdev_notify_key (seat,
                                 seat->repeat_device,
                                 g_source_get_time (source),
                                 seat->repeat_key,
                                 AUTOREPEAT_VALUE,
                                 FALSE);

  return G_SOURCE_CONTINUE;
}
Пример #24
0
int moloch_http_curl_close_callback(void *snameV, curl_socket_t fd)
{
    MolochHttpServerName_t    *sname = snameV;
    MolochHttpServer_t        *server = sname->server;

    if (! BIT_ISSET(fd, connectionsSet)) {
        long ev = (long)g_hash_table_lookup(server->fd2ev, (void *)(long)fd);
        LOG("Couldn't connect %s (%d, %ld) ", sname->name, fd, ev);
        close(fd);
        GSource *source = g_main_context_find_source_by_id (NULL, ev);
        if (source)
            g_source_destroy (source);
        g_hash_table_remove(server->fd2ev, (void *)(long)fd);
        return 0;
    }

    struct sockaddr_storage localAddressStorage, remoteAddressStorage;

    socklen_t addressLength = sizeof(localAddressStorage);
    int rc = getsockname(fd, (struct sockaddr*)&localAddressStorage, &addressLength);
    if (rc != 0)
        return 0;

    addressLength = sizeof(remoteAddressStorage);
    rc = getpeername(fd, (struct sockaddr*)&remoteAddressStorage, &addressLength);
    if (rc != 0)
        return 0;

    char sessionId[MOLOCH_SESSIONID_LEN];
    int  localPort, remotePort;
    char remoteIp[INET6_ADDRSTRLEN+2];
    if (localAddressStorage.ss_family == AF_INET) {
        struct sockaddr_in *localAddress = (struct sockaddr_in *)&localAddressStorage;
        struct sockaddr_in *remoteAddress = (struct sockaddr_in *)&remoteAddressStorage;
        moloch_session_id(sessionId, localAddress->sin_addr.s_addr, localAddress->sin_port,
                          remoteAddress->sin_addr.s_addr, remoteAddress->sin_port);
        localPort = ntohs(localAddress->sin_port);
        remotePort = ntohs(remoteAddress->sin_port);
        inet_ntop(AF_INET, &remoteAddress->sin_addr, remoteIp, sizeof(remoteIp));
    } else {
        struct sockaddr_in6 *localAddress = (struct sockaddr_in6 *)&localAddressStorage;
        struct sockaddr_in6 *remoteAddress = (struct sockaddr_in6 *)&remoteAddressStorage;
        moloch_session_id6(sessionId, localAddress->sin6_addr.s6_addr, localAddress->sin6_port,
                          remoteAddress->sin6_addr.s6_addr, remoteAddress->sin6_port);
        localPort = ntohs(localAddress->sin6_port);
        remotePort = ntohs(remoteAddress->sin6_port);
        inet_ntop(AF_INET6, &remoteAddress->sin6_addr, remoteIp+1, sizeof(remoteIp)-2);
        remoteIp[0] = '[';
        strcat(remoteIp, "]");
    }


    MolochHttpConn_t *conn;
    BIT_CLR(fd, connectionsSet);

    MOLOCH_LOCK(connections);
    HASH_FIND(h_, connections, sessionId, conn);
    if (conn) {
        HASH_REMOVE(h_, connections, conn);
        MOLOCH_TYPE_FREE(MolochHttpConn_t, conn);
    }
    MOLOCH_UNLOCK(connections);

    server->connections--;

    if (config.logHTTPConnections) {
        LOG("Close %d/%d - %s   %d->%s:%d fd:%d removed: %s",
                server->outstanding,
                server->connections,
                sname->name,
                localPort,
                remoteIp,
                remotePort,
                fd,
                conn?"true":"false");
    }

    close (fd);
    return 0;
}
Пример #25
0
event_handle_t *
event_register(
    event_id_t data,
    event_type_t type,
    event_fn_t fn,
    void *arg)
{
    event_handle_t *handle;
    GIOCondition cond;

    /* sanity-checking */
    if ((type == EV_READFD) || (type == EV_WRITEFD)) {
	/* make sure we aren't given a high fd that will overflow a fd_set */
	if (data >= (int)FD_SETSIZE) {
	    error(_("event_register: Invalid file descriptor %jd"), data);
	    /*NOTREACHED*/
	}
    } else if (type == EV_TIME) {
	if (data <= 0) {
	    error(_("event_register: interval for EV_TIME must be greater than 0; got %jd"), data);
	}
    }

    handle = g_new0(event_handle_t, 1);
    handle->fn = fn;
    handle->arg = arg;
    handle->type = type;
    handle->data = data;
    handle->is_dead = FALSE;

    event_debug(1, _("event: register: %p->data=%jd, type=%s\n"),
		    handle, handle->data, event_type2str(handle->type));

    /* add to the list of events */
    all_events = g_slist_prepend(all_events, (gpointer)handle);

    /* and set up the GSource for this event */
    switch (type) {
	case EV_READFD:
	case EV_WRITEFD:
	    /* create a new source */
	    if (type == EV_READFD) {
		cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
	    } else {
		cond = G_IO_OUT | G_IO_ERR;
	    }

	    handle->source = new_fdsource(data, cond);

	    /* attach it to the default GMainLoop */
	    g_source_attach(handle->source, NULL);
	    handle->source_id = g_source_get_id(handle->source);

	    /* And set its callbacks */
	    g_source_set_callback(handle->source, event_handle_callback,
				  (gpointer)handle, NULL);

	    /* drop our reference to it, so when it's detached, it will be
	     * destroyed. */
	    g_source_unref(handle->source);
	    break;

	case EV_TIME:
	    /* Glib provides a nice shortcut for timeouts.  The *1000 converts
	     * seconds to milliseconds. */
	    handle->source_id = g_timeout_add(data * 1000, event_handle_callback,
					      (gpointer)handle);

	    /* But it doesn't give us the source directly.. */
	    handle->source = g_main_context_find_source_by_id(NULL, handle->source_id);
	    /* EV_TIME must always be handled after EV_READ */
	    g_source_set_priority(handle->source, 10);
	    break;

	case EV_WAIT:
	    /* nothing to do -- these are handled independently of GMainLoop */
	    break;

	default:
	    error(_("Unknown event type %s"), event_type2str(type));
    }

    return handle;
}
Пример #26
0
void
event_activate(
    event_handle_t *handle)
{
    GIOCondition cond;
    assert(handle != NULL);

    g_static_mutex_lock(&event_mutex);

    /* add to the list of events */
    all_events = g_slist_prepend(all_events, (gpointer)handle);

    /* and set up the GSource for this event */
    switch (handle->type) {
	case EV_READFD:
	case EV_WRITEFD:
	    /* create a new source */
	    if (handle->type == EV_READFD) {
		cond = G_IO_IN | G_IO_HUP | G_IO_ERR;
	    } else {
		cond = G_IO_OUT | G_IO_ERR;
	    }

	    handle->source = new_fdsource(handle->data, cond);

	    /* attach it to the default GMainLoop */
	    g_source_attach(handle->source, NULL);
	    handle->source_id = g_source_get_id(handle->source);

	    /* And set its callbacks */
	    g_source_set_callback(handle->source, event_handle_callback,
				  (gpointer)handle, NULL);

	    /* drop our reference to it, so when it's detached, it will be
	     * destroyed. */
	    g_source_unref(handle->source);
	    break;

	case EV_TIME:
	    /* Glib provides a nice shortcut for timeouts.  The *1000 converts
	     * seconds to milliseconds. */
	    handle->source_id = g_timeout_add(handle->data * 1000, event_handle_callback,
					      (gpointer)handle);

	    /* But it doesn't give us the source directly.. */
	    handle->source = g_main_context_find_source_by_id(NULL, handle->source_id);
	    /* EV_TIME must always be handled after EV_READ */
	    g_source_set_priority(handle->source, 10);
	    break;

	case EV_WAIT:
	    /* nothing to do -- these are handled independently of GMainLoop */
	    break;

	default:
	    error(_("Unknown event type %s"), event_type2str(handle->type));
    }

    g_static_mutex_unlock(&event_mutex);
    return;
}
Пример #27
0
static void
thunar_uca_provider_activated (ThunarUcaProvider *uca_provider,
                               GtkAction         *action)
{
  GtkTreeRowReference *row;
  ThunarUcaContext    *uca_context;
  GtkTreePath         *path;
  GtkTreeIter          iter;
  GtkWidget           *dialog;
  GtkWidget           *window;
  gboolean             succeed;
  GSource             *source;
  GError              *error = NULL;
  GList               *files;
  gchar              **argv;
  gchar               *working_directory = NULL;
  gchar               *filename;
  gchar               *label;
  gchar               *uri;
  gint                 argc;
  gint                 pid;

  g_return_if_fail (THUNAR_UCA_IS_PROVIDER (uca_provider));
  g_return_if_fail (GTK_IS_ACTION (action));

  /* check if the row reference is still valid */
  row = g_object_get_qdata (G_OBJECT (action), thunar_uca_row_quark);
  if (G_UNLIKELY (!gtk_tree_row_reference_valid (row)))
    return;

  /* determine the iterator for the item */
  path = gtk_tree_row_reference_get_path (row);
  gtk_tree_model_get_iter (GTK_TREE_MODEL (uca_provider->model), &iter, path);
  gtk_tree_path_free (path);

  /* determine the files and the window for the action */
  uca_context = g_object_get_qdata (G_OBJECT (action), thunar_uca_context_quark);
  window = thunar_uca_context_get_window (uca_context);
  files = thunar_uca_context_get_files (uca_context);

  /* determine the argc/argv for the item */
  succeed = thunar_uca_model_parse_argv (uca_provider->model, &iter, files, &argc, &argv, &error);
  if (G_LIKELY (succeed))
    {
      /* determine the working from the first file */
      if (G_LIKELY (files != NULL))
        {
          /* determine the filename of the first selected file */
          uri = thunarx_file_info_get_uri (files->data);
          filename = g_filename_from_uri (uri, NULL, NULL);
          if (G_LIKELY (filename != NULL))
            {
              /* if this is a folder action, we just use the filename as working directory */
              if (g_object_get_qdata (G_OBJECT (action), thunar_uca_folder_quark) != NULL)
                {
                  working_directory = filename;
                  filename = NULL;
                }
              else
                {
                  working_directory = g_path_get_dirname (filename);
                }
            }
          g_free (filename);
          g_free (uri);
        }

      /* spawn the command on the window's screen */
      succeed = gdk_spawn_on_screen (gtk_widget_get_screen (GTK_WIDGET (window)), working_directory,
                                     argv, NULL, G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH,
                                     NULL, NULL, &pid, &error);

      /* check if we succeed */
      if (G_LIKELY (succeed))
        {
          /* check if we already have a child watch */
          if (G_UNLIKELY (uca_provider->child_watch_id >= 0))
            {
              /* reset the callback function to g_spawn_close_pid() so the plugin can be
               * safely unloaded and the child will still not become a zombie afterwards.
               */
              source = g_main_context_find_source_by_id (NULL, uca_provider->child_watch_id);
              g_source_set_callback (source, (GSourceFunc) g_spawn_close_pid, NULL, NULL);
            }

          /* schedule the new child watch */
          uca_provider->child_watch_id = g_child_watch_add_full (G_PRIORITY_LOW, pid, thunar_uca_provider_child_watch,
                                                                 uca_provider, thunar_uca_provider_child_watch_destroy);

          /* take over ownership of the working directory as child watch path */
          uca_provider->child_watch_path = working_directory;
          working_directory = NULL;
        }

      /* cleanup */
      g_free (working_directory);
      g_strfreev (argv);
    }

  /* present error message to the user */
  if (G_UNLIKELY (!succeed))
    {
      g_object_get (G_OBJECT (action), "label", &label, NULL);
      dialog = gtk_message_dialog_new ((GtkWindow *) window,
                                       GTK_DIALOG_DESTROY_WITH_PARENT
                                       | GTK_DIALOG_MODAL,
                                       GTK_MESSAGE_ERROR,
                                       GTK_BUTTONS_CLOSE,
                                       _("Failed to launch action \"%s\"."), label);
      gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s.", error->message);
      gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);
      g_error_free (error);
      g_free (label);
    }
}
Пример #28
0
void
kiro_server_realloc (KiroServer *self, void *mem, size_t size) {

    if (!self)
        return;

    g_debug ("Starting realloc");

    struct kiro_rdma_mem rdma_mem;
    rdma_mem.mem = mem;
    rdma_mem.size = size;

    KiroServerPrivate *priv = KIRO_SERVER_GET_PRIVATE (self);


    G_LOCK (connection_handling);
    G_LOCK (rdma_handling);

    priv->mem = mem;
    priv->mem_size = size;
    if (!priv->clients) {
        g_debug ("No clients to reconnect. Done.");
        G_UNLOCK (rdma_handling);
        G_UNLOCK (connection_handling);
        return;
    }
    g_list_foreach (priv->clients, request_client_realloc, &rdma_mem);

    // Swap the two lists. See Note above.
    GList *tmp = priv->clients;
    priv->clients = realloc_list;
    realloc_list = tmp;
    G_UNLOCK (rdma_handling);

    guint timeout = g_timeout_add_seconds (2, client_realloc_timeout, NULL);

    timeout_done = FALSE;
    while (!timeout_done) {
        if (!realloc_list) {
            g_debug ("All clients have ACKed");
            break; // all clients ACKed
        }
    }

    GSource *timeout_source = g_main_context_find_source_by_id (NULL, timeout);
    if (timeout_source) {
        g_source_destroy (timeout_source);
    }

    G_LOCK (realloc_timeout);
    GList *current = g_list_first (realloc_list);
    while (current) {
        struct kiro_client_connection *cc = (struct kiro_client_connection *)current->data;
        g_debug ("Client %i did not ACK the REALLOC request in time.", cc->id);
        GList *client = g_list_find (priv->clients, current->data);
        if (client) {
            priv->clients = g_list_delete_link (priv->clients, client);
        }
        disconnect_client (current->data, NULL);
        current = g_list_next (current);
    }

    if (realloc_list) {
        g_list_free (realloc_list);
        realloc_list = NULL;
    }
    G_UNLOCK (realloc_timeout);


    g_debug ("Realloc procedure done!");
    G_UNLOCK (connection_handling);
}
Пример #29
0
// --- wait for USR1 signal to arrive and invoke ladi handler via mainloop
void PosixSignals::signal_helper_thread() {
    pthr = pthread_self();
    const char *signame;
    guint source_id_usr1 = 0;
    pthread_sigmask(SIG_BLOCK, &waitset, NULL);
    bool seen = false;
    while (true) {
	int sig;
        int ret = sigwait(&waitset, &sig);
	if (exit) {
	    break;
	}
        if (ret != 0) {
            assert(errno == EINTR);
	    continue;
	}
	switch (sig) {
	case SIGUSR1:
	    if (gtk_level() < 1) {
		gx_print_info(_("system startup"),
					 _("signal usr1 skipped"));
		break;
	    }
	    // do not add a new call if another one is already pending
	    if (source_id_usr1 == 0 ||
		g_main_context_find_source_by_id(NULL, source_id_usr1) == NULL) {
		const Glib::RefPtr<Glib::IdleSource> idle_source = Glib::IdleSource::create();
		idle_source->connect(
		    sigc::bind_return<bool>(
			sigc::mem_fun(*this, &PosixSignals::gx_ladi_handler),false));
		idle_source->attach();
		source_id_usr1 = idle_source->get_id();
	    }
	    break;
	case SIGCHLD:
	    Glib::signal_idle().connect_once(
		sigc::ptr_fun(gx_child_process::gx_sigchld_handler));
	    break;
	case SIGINT:
	case SIGQUIT:
	case SIGTERM:
	case SIGHUP:
	    switch (sig) {
	    case SIGINT:
		signame = _("ctrl-c");
		break;
	    case SIGQUIT:
		signame = "SIGQUIT";
		break;
	    case SIGTERM:
		signame = "SIGTERM";
		break;
	    case SIGHUP:
		signame = "SIGHUP";
		break;
	    }
	    if (!seen && gtk_level() == 1) {
		printf("\nquit (%s)\n", signame);
		Glib::signal_idle().connect_once(sigc::mem_fun(*this, &PosixSignals::quit_slot));
	    } else {
		GxExit::get_instance().exit_program(
		    (boost::format("\nQUIT (%1%)\n") % signame).str());
	    }
	    seen = true;
	    break;
	default:
	    assert(false);
        }
    }
}