[gnome-terminal] client: legacy: Fall back to default server on failure



commit 909b845a45b1432a4fae0d65921ff3c3ae080dba
Author: Christian Persch <chpe src gnome org>
Date:   Sat Nov 11 23:37:00 2017 +0100

    client: legacy: Fall back to default server on failure
    
    When the server specified by the environment doesn't exist,
    fall back to the default.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=83203#c78

 src/terminal.c |   28 +++++++++++++++++++++++++++-
 1 files changed, 27 insertions(+), 1 deletions(-)
---
diff --git a/src/terminal.c b/src/terminal.c
index 04f3ac9..0c8e2d1 100644
--- a/src/terminal.c
+++ b/src/terminal.c
@@ -196,6 +196,7 @@ handle_exec_error (const char *service_name,
 
 static gboolean
 factory_proxy_new_for_service_name (const char *service_name,
+                                    gboolean ping_server,
                                     TerminalFactory **factory_ptr,
                                     char **service_name_ptr,
                                     GError **error)
@@ -221,6 +222,26 @@ factory_proxy_new_for_service_name (const char *service_name,
     return FALSE;
   }
 
+  if (ping_server) {
+    /* If we try to use the environment specified server, we need to make
+     * sure it actually exists so we can later fall back to the default name.
+     * There doesn't appear to a way to fail proxy creation above if the
+     * unique name doesn't exist; so we do it this way.
+     */
+    gs_unref_variant GVariant *v = g_dbus_proxy_call_sync (G_DBUS_PROXY (factory),
+                                                           "org.freedesktop.DBus.Peer.Ping",
+                                                           g_variant_new ("()"),
+                                                           G_DBUS_CALL_FLAGS_NONE,
+                                                           1000 /* 1s */,
+                                                           NULL /* cancelleable */,
+                                                           &err);
+    if (v == NULL) {
+      g_propagate_error (error, err);
+      err = NULL;
+      return FALSE;
+    }
+  }
+
   gs_transfer_out_value (factory_ptr, &factory);
   *service_name_ptr = g_strdup (service_name);
   return TRUE;
@@ -246,6 +267,7 @@ factory_proxy_new (TerminalOptions *options,
       options->server_unique_name != NULL) {
     gs_free_error GError *err = NULL;
     if (factory_proxy_new_for_service_name (options->server_unique_name,
+                                            TRUE,
                                             factory_ptr,
                                             service_name_ptr,
                                             &err)) {
@@ -253,7 +275,10 @@ factory_proxy_new (TerminalOptions *options,
       return TRUE;
     }
 
-    g_print ("code %d msg %s\n", err->code, err->message);
+    terminal_printerr ("Failed to use specified server: %s\n",
+                       err->message);
+    terminal_printerr ("Falling back to default server.\n");
+
     /* Fall back to the default */
     service_name = NULL;
   }
@@ -261,6 +286,7 @@ factory_proxy_new (TerminalOptions *options,
   *parent_screen_object_path_ptr = NULL;
 
   return factory_proxy_new_for_service_name (service_name,
+                                             FALSE,
                                              factory_ptr,
                                              service_name_ptr,
                                              error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]