~ubuntu-branches/ubuntu/gutsy/network-manager/gutsy-updates

« back to all changes in this revision

Viewing changes to debian/patches/41y_queue_if_dbus_name_is_taken_on_startup.patch

  • Committer: Bazaar Package Importer
  • Author(s): Alexander Sack
  • Date: 2007-10-02 13:32:50 UTC
  • Revision ID: james.westby@ubuntu.com-20071002133250-usdtscqpe0ejck5e
Tags: 0.6.5-0ubuntu15
* debian/patches/41z_lp138217_use_timeout_to_schedule_activation.patch,series:
  don't use idle_source to schedule activation, but rest a bit by using a
  timeout_source with 250ms delay (LP: #138217).
* debian/network-manager.postinst: sleep 2 seconds after ifblacklist_migrate.sh
  (LP: #146757).
* debian/patches/41w_lp145683_cancel_scan_in_supplicant_cleanup.patch,series: first part
  for lp145683 - cancel pending scans on terminate (LP: #145683).
* debian/patches/41wa_lp145683_wpa_ctrl_check_select_result_for_error.patch,series:
  second part to fix lp145683; test select result for errors (in case of
  TERMINATE) (LP: #145683).
* debian/patches/41y_queue_if_dbus_name_is_taken_on_startup.patch,series: make
  restart of network manager more failsafe and even allow to take over name
  ownership. When ownership is taken over (dbus signal |NameLost| received), we
  shutdown cleanly by sending |X| through |nm_shutdown_pipe| (LP: #85113).
* debian/patches/41x_lp145653_reraise_fatal_signals.patch: re-raise fatal
  signals (LP: #145653).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
---
 
2
 src/NetworkManagerDbus.c |   55 ++++++++++++++++++++++++++++++++---------------
 
3
 1 file changed, 38 insertions(+), 17 deletions(-)
 
4
 
 
5
Index: network-manager.debian/src/NetworkManagerDbus.c
 
6
===================================================================
 
7
--- network-manager.debian.orig/src/NetworkManagerDbus.c
 
8
+++ network-manager.debian/src/NetworkManagerDbus.c
 
9
@@ -525,16 +525,22 @@
 
10
        {
 
11
                nm_hal_deinit (data);
 
12
                dbus_connection_unref (data->dbus_connection);
 
13
                data->dbus_connection = NULL;
 
14
                nm_dhcp_manager_dispose (data->dhcp_manager);
 
15
                g_thread_create ((GThreadFunc) nm_dbus_reinit, (gpointer) data, FALSE, NULL);
 
16
                handled = TRUE;
 
17
        }
 
18
+       else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameLost"))
 
19
+       {
 
20
+         g_warning("NetworkManagerDBus Lost the primary service name ownership ... shutting down!");
 
21
+         write (nm_get_sigterm_pipe (), "X", 1);
 
22
+         handled = TRUE;
 
23
+       }
 
24
        else if (dbus_message_is_signal (message, DBUS_INTERFACE_DBUS, "NameOwnerChanged"))
 
25
        {
 
26
                char    *service;
 
27
                char            *old_owner;
 
28
                char            *new_owner;
 
29
 
 
30
                if (dbus_message_get_args (message, &error, DBUS_TYPE_STRING, &service, DBUS_TYPE_STRING, &old_owner,
 
31
                                                                        DBUS_TYPE_STRING, &new_owner, DBUS_TYPE_INVALID))
 
32
@@ -802,17 +808,17 @@
 
33
 DBusConnection *nm_dbus_init (NMData *data)
 
34
 {
 
35
        DBusError                               error;
 
36
        DBusConnection *                connection;
 
37
        DBusObjectPathVTable    nm_vtable = {NULL, &nm_dbus_nm_message_handler, NULL, NULL, NULL, NULL};
 
38
        DBusObjectPathVTable    devices_vtable = {NULL, &nm_dbus_devices_message_handler, NULL, NULL, NULL, NULL};
 
39
        DBusObjectPathVTable    vpn_vtable = {NULL, &nm_dbus_vpn_message_handler, NULL, NULL, NULL, NULL};
 
40
        char *                          owner;
 
41
-       int                                     flags, ret;
 
42
+       int                                     flags, ret, i;
 
43
 
 
44
        dbus_connection_set_change_sigpipe (TRUE);
 
45
 
 
46
        dbus_error_init (&error);
 
47
        connection = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
 
48
        if ((connection == NULL) || dbus_error_is_set (&error))
 
49
        {
 
50
                nm_warning ("nm_dbus_init() could not get the system bus.  Make sure the message bus daemon is running!");
 
51
@@ -854,35 +860,50 @@
 
52
        {
 
53
                char *match = get_nmi_match_string (owner);
 
54
 
 
55
                dbus_bus_add_match (connection, match, NULL);
 
56
                g_free (match);
 
57
                g_free (owner);
 
58
        }
 
59
 
 
60
-       dbus_error_init (&error);
 
61
+       for (i=0; i < 10; i++) {
 
62
+               dbus_error_init (&error);
 
63
 #if (DBUS_VERSION_MAJOR == 0) && (DBUS_VERSION_MINOR < 60)
 
64
-       flags = DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT;
 
65
+               if(i == 9)
 
66
+                       flags = DBUS_NAME_FLAG_REPLACE_EXISTING;
 
67
+               else
 
68
+                       flags = 0;
 
69
 #else
 
70
-       flags = DBUS_NAME_FLAG_DO_NOT_QUEUE;
 
71
+               flags = DBUS_NAME_FLAG_ALLOW_REPLACEMENT | DBUS_NAME_FLAG_DO_NOT_QUEUE;
 
72
+               if(i == 9)
 
73
+                       flags |= DBUS_NAME_FLAG_REPLACE_EXISTING; // we want to QUEUE in case the previous NetworkManager didn't yet terminate.
 
74
 #endif
 
75
-       ret = dbus_bus_request_name (connection, NM_DBUS_SERVICE, flags, &error);
 
76
-       if (dbus_error_is_set (&error))
 
77
-       {
 
78
-               nm_warning ("nm_dbus_init() could not acquire the NetworkManager service.\n  Message: '%s'", error.message);
 
79
-               connection = NULL;
 
80
-               goto out;
 
81
-       }
 
82
-       else if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
 
83
-       {
 
84
-               nm_warning ("nm_dbus_init() could not acquire the NetworkManager service as it is already taken (ret=%d). Is the daemon already running?",
 
85
-                                 ret);
 
86
-               connection = NULL;
 
87
-               goto out;
 
88
+               ret = dbus_bus_request_name (connection, NM_DBUS_SERVICE, flags, &error);
 
89
+               if (dbus_error_is_set (&error))
 
90
+               {
 
91
+                       nm_warning ("nm_dbus_init() could not acquire the NetworkManager service.\n  Message: '%s'", error.message);
 
92
+                       connection = NULL;
 
93
+                       goto out;
 
94
+               }
 
95
+               else if (ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER && ret != DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
 
96
+               {
 
97
+                       nm_info ("nm_dbus_init() could not acquire the NetworkManager service as PRIMARY_OWNER (ret=%d). This happens if NetworkManager daemon is already/still running?",
 
98
+                                         ret);
 
99
+                       if (dbus_error_is_set (&error))
 
100
+                               dbus_error_free (&error);
 
101
+                       if (i == 9) {
 
102
+                               connection = NULL;
 
103
+                               goto out;
 
104
+                       }
 
105
+                       // sleep 200 ms
 
106
+                       g_usleep (G_USEC_PER_SEC);
 
107
+               } else {
 
108
+                 break;
 
109
+               }
 
110
        }
 
111
 
 
112
 out:
 
113
        if (dbus_error_is_set (&error))
 
114
                dbus_error_free (&error);
 
115
 
 
116
        return (connection);
 
117
 }