예제 #1
0
파일: daemon-main.c 프로젝트: GNOME/gvfs
static void
on_name_lost (GDBusConnection *connection,
              const gchar     *name,
              gpointer         user_data)
{
  DaemonData *data = user_data;
  gchar *s;
  
  if (connection == NULL)
    {
      g_printerr ("A connection to the bus can't be made\n");
      process_result = 1;
    }
  else
    {
      if (already_acquired)
        {
          g_printerr ("Got NameLost, some other instance replaced us\n");
        }
      else
        {
          s = g_strdup_printf (_("mountpoint for %s already running"), data->mountable_name);
          send_spawned (FALSE, s, G_IO_ERROR_ALREADY_MOUNTED, spawned_failed_cb, data);
          g_free (s);
          return;
        }
    }
  g_main_loop_quit (loop);
}
예제 #2
0
파일: daemon-main.c 프로젝트: GNOME/gvfs
static void
on_name_acquired (GDBusConnection *connection,
                  const gchar     *name,
                  gpointer         user_data)
{
  DaemonData *data = user_data;

  already_acquired = TRUE;
  
  data->daemon = g_vfs_daemon_new (FALSE, FALSE);
  if (data->daemon == NULL)
    {
      send_spawned (FALSE, _("error starting mount daemon"), G_IO_ERROR_FAILED, spawned_failed_cb, data);
      return;
    }

  g_vfs_daemon_set_max_threads (data->daemon, data->max_job_threads);
  g_signal_connect (data->daemon, "shutdown",
		    G_CALLBACK (daemon_shutdown), loop);

  send_spawned (TRUE, NULL, 0, spawned_succeeded_cb, data);
}
예제 #3
0
파일: daemon-main.c 프로젝트: Andais/gvfs
void
daemon_main (int argc,
	     char *argv[],
	     int max_job_threads,
	     const char *default_type,
	     const char *mountable_name,
	     const char *first_type_name,
	     ...)
{
  va_list var_args;
  DBusConnection *connection;
  GMainLoop *loop;
  GVfsDaemon *daemon;
  DBusError derror;
  GMountSpec *mount_spec;
  GMountSource *mount_source;
  GError *error;
  int res;
  const char *type;

  dbus_error_init (&derror);
  connection = dbus_bus_get (DBUS_BUS_SESSION, &derror);
  if (connection == NULL)
    {
      g_printerr (_("Error connecting to D-Bus: %s"), derror.message);
      g_printerr ("\n");
      dbus_error_free (&derror);
      exit (1);
    }
  
  mount_spec = daemon_parse_args (argc, argv, default_type);

  va_start (var_args, first_type_name);

  type = first_type_name;

  while (type != NULL)
    {
      GType backend_type = va_arg (var_args, GType);
      
      g_vfs_register_backend (backend_type, type);

      type = va_arg (var_args, char *);
    }

  error = NULL;
  if (mountable_name)
    {
      
      res = dbus_bus_request_name (connection,
				   mountable_name,
				   0, &derror);

      if (res != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
	{
	  if (res == -1)
	    _g_error_from_dbus (&derror, &error);
	  else
	    g_set_error (&error, G_IO_ERROR, G_IO_ERROR_FAILED,
			 _("mountpoint for %s already running"), mountable_name);

	  send_spawned (connection, FALSE, error->message);
	  g_error_free (error);
	  exit (1);
	}
    }
  
  daemon = g_vfs_daemon_new (FALSE, FALSE);
  if (daemon == NULL)
    {
      send_spawned (connection, FALSE, _("error starting mount daemon"));
      exit (1);
    }

  g_vfs_daemon_set_max_threads (daemon, max_job_threads);  
  
  send_spawned (connection, TRUE, NULL);
	  
  if (mount_spec)
    {
      mount_source = g_mount_source_new_dummy ();
      g_vfs_daemon_initiate_mount (daemon, mount_spec, mount_source, FALSE, NULL);
      g_mount_spec_unref (mount_spec);
      g_object_unref (mount_source);
    }
  
  loop = g_main_loop_new (NULL, FALSE);

  g_main_loop_run (loop);
}