diff options
| author | Michael Albinus | 2012-07-27 12:46:58 +0200 |
|---|---|---|
| committer | Michael Albinus | 2012-07-27 12:46:58 +0200 |
| commit | e518bc71e8ae11ad81573d6dbf66317a047c4ba7 (patch) | |
| tree | 6f72431b9cd1afbfa4e0eb492d4eb13462e5bdf7 /src/dbusbind.c | |
| parent | bcfbc9de654b0718d46349ca8ada284dba3dc761 (diff) | |
| download | emacs-e518bc71e8ae11ad81573d6dbf66317a047c4ba7.tar.gz emacs-e518bc71e8ae11ad81573d6dbf66317a047c4ba7.zip | |
* dbusbind.c (XD_DBUS_VALIDATE_BUS_ADDRESS): Canonicalize session
bus address.
(xd_close_bus, Fdbus_init_bus): Handle reference counter properly.
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 141 |
1 files changed, 78 insertions, 63 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index 86013d92c07..06f47643bbf 100644 --- a/src/dbusbind.c +++ b/src/dbusbind.c | |||
| @@ -261,6 +261,7 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 261 | 261 | ||
| 262 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ | 262 | #define XD_DBUS_VALIDATE_BUS_ADDRESS(bus) \ |
| 263 | do { \ | 263 | do { \ |
| 264 | char const *session_bus_address = getenv ("DBUS_SESSION_BUS_ADDRESS"); \ | ||
| 264 | if (STRINGP (bus)) \ | 265 | if (STRINGP (bus)) \ |
| 265 | { \ | 266 | { \ |
| 266 | DBusAddressEntry **entries; \ | 267 | DBusAddressEntry **entries; \ |
| @@ -272,6 +273,10 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 272 | /* Cleanup. */ \ | 273 | /* Cleanup. */ \ |
| 273 | dbus_error_free (&derror); \ | 274 | dbus_error_free (&derror); \ |
| 274 | dbus_address_entries_free (entries); \ | 275 | dbus_address_entries_free (entries); \ |
| 276 | /* Canonicalize session bus address. */ \ | ||
| 277 | if (session_bus_address != NULL \ | ||
| 278 | && Fstring_equal (bus, build_string (session_bus_address))) \ | ||
| 279 | bus = QCdbus_session_bus; \ | ||
| 275 | } \ | 280 | } \ |
| 276 | \ | 281 | \ |
| 277 | else \ | 282 | else \ |
| @@ -280,8 +285,7 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 280 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ | 285 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ |
| 281 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ | 286 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ |
| 282 | /* We do not want to have an autolaunch for the session bus. */ \ | 287 | /* We do not want to have an autolaunch for the session bus. */ \ |
| 283 | if (EQ (bus, QCdbus_session_bus) \ | 288 | if (EQ (bus, QCdbus_session_bus) && session_bus_address == NULL) \ |
| 284 | && getenv ("DBUS_SESSION_BUS_ADDRESS") == NULL) \ | ||
| 285 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ | 289 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ |
| 286 | } \ | 290 | } \ |
| 287 | } while (0) | 291 | } while (0) |
| @@ -1071,19 +1075,19 @@ xd_close_bus (Lisp_Object bus) | |||
| 1071 | /* Retrieve bus address. */ | 1075 | /* Retrieve bus address. */ |
| 1072 | connection = xd_get_connection_address (bus); | 1076 | connection = xd_get_connection_address (bus); |
| 1073 | 1077 | ||
| 1074 | /* Close connection, if there isn't another shared application. */ | ||
| 1075 | if (xd_get_connection_references (connection) == 1) | 1078 | if (xd_get_connection_references (connection) == 1) |
| 1076 | { | 1079 | { |
| 1080 | /* Close connection, if there isn't another shared application. */ | ||
| 1077 | XD_DEBUG_MESSAGE ("Close connection to bus %s", | 1081 | XD_DEBUG_MESSAGE ("Close connection to bus %s", |
| 1078 | XD_OBJECT_TO_STRING (bus)); | 1082 | XD_OBJECT_TO_STRING (bus)); |
| 1079 | dbus_connection_close (connection); | 1083 | dbus_connection_close (connection); |
| 1080 | } | ||
| 1081 | 1084 | ||
| 1082 | /* Decrement reference count. */ | 1085 | xd_registered_buses = Fdelete (val, xd_registered_buses); |
| 1083 | dbus_connection_unref (connection); | 1086 | } |
| 1084 | 1087 | ||
| 1085 | /* Remove bus from list of registered buses. */ | 1088 | else |
| 1086 | xd_registered_buses = Fdelete (val, xd_registered_buses); | 1089 | /* Decrement reference count. */ |
| 1090 | dbus_connection_unref (connection); | ||
| 1087 | 1091 | ||
| 1088 | /* Return. */ | 1092 | /* Return. */ |
| 1089 | return; | 1093 | return; |
| @@ -1124,65 +1128,76 @@ this connection to those buses. */) | |||
| 1124 | /* Close bus if it is already open. */ | 1128 | /* Close bus if it is already open. */ |
| 1125 | xd_close_bus (bus); | 1129 | xd_close_bus (bus); |
| 1126 | 1130 | ||
| 1127 | /* Initialize. */ | 1131 | /* Check, whether we are still connected. */ |
| 1128 | dbus_error_init (&derror); | 1132 | val = Fassoc (bus, xd_registered_buses); |
| 1129 | 1133 | if (!NILP (val)) | |
| 1130 | /* Open the connection. */ | 1134 | { |
| 1131 | if (STRINGP (bus)) | 1135 | connection = xd_get_connection_address (bus); |
| 1132 | if (NILP (private)) | 1136 | dbus_connection_ref (connection); |
| 1133 | connection = dbus_connection_open (SSDATA (bus), &derror); | 1137 | } |
| 1134 | else | ||
| 1135 | connection = dbus_connection_open_private (SSDATA (bus), &derror); | ||
| 1136 | 1138 | ||
| 1137 | else | 1139 | else |
| 1138 | if (NILP (private)) | 1140 | { |
| 1139 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | 1141 | /* Initialize. */ |
| 1140 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | 1142 | dbus_error_init (&derror); |
| 1141 | &derror); | ||
| 1142 | else | ||
| 1143 | connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus) | ||
| 1144 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1145 | &derror); | ||
| 1146 | |||
| 1147 | if (dbus_error_is_set (&derror)) | ||
| 1148 | XD_ERROR (derror); | ||
| 1149 | |||
| 1150 | if (connection == NULL) | ||
| 1151 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | ||
| 1152 | 1143 | ||
| 1153 | /* If it is not the system or session bus, we must register | 1144 | /* Open the connection. */ |
| 1154 | ourselves. Otherwise, we have called dbus_bus_get, which has | 1145 | if (STRINGP (bus)) |
| 1155 | configured us to exit if the connection closes - we undo this | 1146 | if (NILP (private)) |
| 1156 | setting. */ | 1147 | connection = dbus_connection_open (SSDATA (bus), &derror); |
| 1157 | if (STRINGP (bus)) | 1148 | else |
| 1158 | dbus_bus_register (connection, &derror); | 1149 | connection = dbus_connection_open_private (SSDATA (bus), &derror); |
| 1159 | else | ||
| 1160 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 1161 | |||
| 1162 | if (dbus_error_is_set (&derror)) | ||
| 1163 | XD_ERROR (derror); | ||
| 1164 | |||
| 1165 | /* Add the watch functions. We pass also the bus as data, in order | ||
| 1166 | to distinguish between the buses in xd_remove_watch. */ | ||
| 1167 | if (!dbus_connection_set_watch_functions (connection, | ||
| 1168 | xd_add_watch, | ||
| 1169 | xd_remove_watch, | ||
| 1170 | xd_toggle_watch, | ||
| 1171 | SYMBOLP (bus) | ||
| 1172 | ? (void *) XSYMBOL (bus) | ||
| 1173 | : (void *) XSTRING (bus), | ||
| 1174 | NULL)) | ||
| 1175 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | ||
| 1176 | |||
| 1177 | /* Add bus to list of registered buses. */ | ||
| 1178 | XSETFASTINT (val, (intptr_t) connection); | ||
| 1179 | xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); | ||
| 1180 | |||
| 1181 | /* We do not want to abort. */ | ||
| 1182 | putenv ((char *) "DBUS_FATAL_WARNINGS=0"); | ||
| 1183 | 1150 | ||
| 1184 | /* Cleanup. */ | 1151 | else |
| 1185 | dbus_error_free (&derror); | 1152 | if (NILP (private)) |
| 1153 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | ||
| 1154 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1155 | &derror); | ||
| 1156 | else | ||
| 1157 | connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus) | ||
| 1158 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1159 | &derror); | ||
| 1160 | |||
| 1161 | if (dbus_error_is_set (&derror)) | ||
| 1162 | XD_ERROR (derror); | ||
| 1163 | |||
| 1164 | if (connection == NULL) | ||
| 1165 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | ||
| 1166 | |||
| 1167 | /* If it is not the system or session bus, we must register | ||
| 1168 | ourselves. Otherwise, we have called dbus_bus_get, which has | ||
| 1169 | configured us to exit if the connection closes - we undo this | ||
| 1170 | setting. */ | ||
| 1171 | if (STRINGP (bus)) | ||
| 1172 | dbus_bus_register (connection, &derror); | ||
| 1173 | else | ||
| 1174 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 1175 | |||
| 1176 | if (dbus_error_is_set (&derror)) | ||
| 1177 | XD_ERROR (derror); | ||
| 1178 | |||
| 1179 | /* Add the watch functions. We pass also the bus as data, in | ||
| 1180 | order to distinguish between the buses in xd_remove_watch. */ | ||
| 1181 | if (!dbus_connection_set_watch_functions (connection, | ||
| 1182 | xd_add_watch, | ||
| 1183 | xd_remove_watch, | ||
| 1184 | xd_toggle_watch, | ||
| 1185 | SYMBOLP (bus) | ||
| 1186 | ? (void *) XSYMBOL (bus) | ||
| 1187 | : (void *) XSTRING (bus), | ||
| 1188 | NULL)) | ||
| 1189 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | ||
| 1190 | |||
| 1191 | /* Add bus to list of registered buses. */ | ||
| 1192 | XSETFASTINT (val, (intptr_t) connection); | ||
| 1193 | xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); | ||
| 1194 | |||
| 1195 | /* We do not want to abort. */ | ||
| 1196 | putenv ((char *) "DBUS_FATAL_WARNINGS=0"); | ||
| 1197 | |||
| 1198 | /* Cleanup. */ | ||
| 1199 | dbus_error_free (&derror); | ||
| 1200 | } | ||
| 1186 | 1201 | ||
| 1187 | /* Return reference counter. */ | 1202 | /* Return reference counter. */ |
| 1188 | refcount = xd_get_connection_references (connection); | 1203 | refcount = xd_get_connection_references (connection); |