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; const char *type; guint name_owner_id; DaemonData *data; data = g_new0 (DaemonData, 1); data->mountable_name = g_strdup (mountable_name); data->max_job_threads = max_job_threads; data->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 *); } va_end (var_args); loop = g_main_loop_new (NULL, FALSE); name_owner_id = 0; /* We want to own *some* name on the org.gtk.vfs.* namespace so that filtering for us works from a sandbox */ if (data->mountable_name == NULL) data->mountable_name = g_strdup_printf ("org.gtk.vfs.mountpoint_%d", getpid ()); name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, data->mountable_name, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, on_name_acquired, on_name_lost, data, NULL); g_main_loop_run (loop); g_clear_object (&data->daemon); g_free (data->mountable_name); g_free (data); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); if (loop != NULL) g_main_loop_unref (loop); if (process_result) exit (process_result); }
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); }