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); }
int main (int argc, char *argv[]) { GVfsDaemon *daemon; gboolean replace; gboolean no_fuse; gboolean show_version; GError *error; guint name_owner_id; GBusNameOwnerFlags flags; GOptionContext *context; const GOptionEntry options[] = { { "replace", 'r', 0, G_OPTION_ARG_NONE, &replace, N_("Replace old daemon."), NULL }, { "no-fuse", 0, 0, G_OPTION_ARG_NONE, &no_fuse, N_("Don't start fuse."), NULL }, { "version", 0, 0, G_OPTION_ARG_NONE, &show_version, N_("Show program version."), NULL}, { NULL } }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, GVFS_LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #ifdef SIGPIPE signal (SIGPIPE, SIG_IGN); #endif g_set_application_name (_("GVFS Daemon")); context = g_option_context_new (""); g_option_context_set_summary (context, _("Main daemon for GVFS")); g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE); replace = FALSE; no_fuse = FALSE; show_version = FALSE; if (g_getenv ("GVFS_DISABLE_FUSE") != NULL) no_fuse = TRUE; error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { /* Translators: the first %s is the application name, */ /* the second %s is the error message */ g_printerr (_("%s: %s"), g_get_application_name(), error->message); g_printerr ("\n"); g_printerr (_("Try \"%s --help\" for more information."), g_get_prgname ()); g_printerr ("\n"); g_error_free (error); g_option_context_free (context); return 1; } g_option_context_free (context); if (show_version) { g_print (PACKAGE_STRING "\n"); return 0; } loop = g_main_loop_new (NULL, FALSE); daemon = g_vfs_daemon_new (TRUE, replace); if (daemon == NULL) return 1; g_signal_connect (daemon, "shutdown", G_CALLBACK (daemon_shutdown), loop); flags = G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; if (replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, G_VFS_DBUS_DAEMON_NAME, flags, on_bus_acquired, on_name_acquired, on_name_lost, GUINT_TO_POINTER (no_fuse), NULL); g_main_loop_run (loop); mount_finalize (); g_clear_object (&daemon); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); if (loop != NULL) g_main_loop_unref (loop); return 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); }