diff options
| author | Kenichi Handa | 2012-08-16 21:25:17 +0900 |
|---|---|---|
| committer | Kenichi Handa | 2012-08-16 21:25:17 +0900 |
| commit | d75ffb4ed0b2e72a9361a07d16a5c884a9459728 (patch) | |
| tree | 8ac5a6a8ae033fef7fbc7fb7b09a703ef4b0ed5b /src/dbusbind.c | |
| parent | 69c41c4070c86baac11a627e9c3d366420aeb7cc (diff) | |
| parent | 250c8ab9b8f6322959fa3122db83944c30c3894b (diff) | |
| download | emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.tar.gz emacs-d75ffb4ed0b2e72a9361a07d16a5c884a9459728.zip | |
merge trunk
Diffstat (limited to 'src/dbusbind.c')
| -rw-r--r-- | src/dbusbind.c | 144 |
1 files changed, 80 insertions, 64 deletions
diff --git a/src/dbusbind.c b/src/dbusbind.c index 86013d92c07..c1b1310454c 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,11 @@ 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 | && (!NILP (Fstring_equal \ | ||
| 279 | (bus, build_string (session_bus_address))))) \ | ||
| 280 | bus = QCdbus_session_bus; \ | ||
| 275 | } \ | 281 | } \ |
| 276 | \ | 282 | \ |
| 277 | else \ | 283 | else \ |
| @@ -280,8 +286,7 @@ xd_symbol_to_dbus_type (Lisp_Object object) | |||
| 280 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ | 286 | if (!(EQ (bus, QCdbus_system_bus) || EQ (bus, QCdbus_session_bus))) \ |
| 281 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ | 287 | XD_SIGNAL2 (build_string ("Wrong bus name"), bus); \ |
| 282 | /* We do not want to have an autolaunch for the session bus. */ \ | 288 | /* We do not want to have an autolaunch for the session bus. */ \ |
| 283 | if (EQ (bus, QCdbus_session_bus) \ | 289 | 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); \ | 290 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); \ |
| 286 | } \ | 291 | } \ |
| 287 | } while (0) | 292 | } while (0) |
| @@ -981,7 +986,7 @@ static int | |||
| 981 | xd_find_watch_fd (DBusWatch *watch) | 986 | xd_find_watch_fd (DBusWatch *watch) |
| 982 | { | 987 | { |
| 983 | #if HAVE_DBUS_WATCH_GET_UNIX_FD | 988 | #if HAVE_DBUS_WATCH_GET_UNIX_FD |
| 984 | /* TODO: Reverse these on Win32, which prefers the opposite. */ | 989 | /* TODO: Reverse these on w32, which prefers the opposite. */ |
| 985 | int fd = dbus_watch_get_unix_fd (watch); | 990 | int fd = dbus_watch_get_unix_fd (watch); |
| 986 | if (fd == -1) | 991 | if (fd == -1) |
| 987 | fd = dbus_watch_get_socket (watch); | 992 | fd = dbus_watch_get_socket (watch); |
| @@ -1071,19 +1076,19 @@ xd_close_bus (Lisp_Object bus) | |||
| 1071 | /* Retrieve bus address. */ | 1076 | /* Retrieve bus address. */ |
| 1072 | connection = xd_get_connection_address (bus); | 1077 | connection = xd_get_connection_address (bus); |
| 1073 | 1078 | ||
| 1074 | /* Close connection, if there isn't another shared application. */ | ||
| 1075 | if (xd_get_connection_references (connection) == 1) | 1079 | if (xd_get_connection_references (connection) == 1) |
| 1076 | { | 1080 | { |
| 1081 | /* Close connection, if there isn't another shared application. */ | ||
| 1077 | XD_DEBUG_MESSAGE ("Close connection to bus %s", | 1082 | XD_DEBUG_MESSAGE ("Close connection to bus %s", |
| 1078 | XD_OBJECT_TO_STRING (bus)); | 1083 | XD_OBJECT_TO_STRING (bus)); |
| 1079 | dbus_connection_close (connection); | 1084 | dbus_connection_close (connection); |
| 1080 | } | ||
| 1081 | 1085 | ||
| 1082 | /* Decrement reference count. */ | 1086 | xd_registered_buses = Fdelete (val, xd_registered_buses); |
| 1083 | dbus_connection_unref (connection); | 1087 | } |
| 1084 | 1088 | ||
| 1085 | /* Remove bus from list of registered buses. */ | 1089 | else |
| 1086 | xd_registered_buses = Fdelete (val, xd_registered_buses); | 1090 | /* Decrement reference count. */ |
| 1091 | dbus_connection_unref (connection); | ||
| 1087 | 1092 | ||
| 1088 | /* Return. */ | 1093 | /* Return. */ |
| 1089 | return; | 1094 | return; |
| @@ -1124,65 +1129,76 @@ this connection to those buses. */) | |||
| 1124 | /* Close bus if it is already open. */ | 1129 | /* Close bus if it is already open. */ |
| 1125 | xd_close_bus (bus); | 1130 | xd_close_bus (bus); |
| 1126 | 1131 | ||
| 1127 | /* Initialize. */ | 1132 | /* Check, whether we are still connected. */ |
| 1128 | dbus_error_init (&derror); | 1133 | val = Fassoc (bus, xd_registered_buses); |
| 1129 | 1134 | if (!NILP (val)) | |
| 1130 | /* Open the connection. */ | 1135 | { |
| 1131 | if (STRINGP (bus)) | 1136 | connection = xd_get_connection_address (bus); |
| 1132 | if (NILP (private)) | 1137 | dbus_connection_ref (connection); |
| 1133 | connection = dbus_connection_open (SSDATA (bus), &derror); | 1138 | } |
| 1134 | else | ||
| 1135 | connection = dbus_connection_open_private (SSDATA (bus), &derror); | ||
| 1136 | 1139 | ||
| 1137 | else | 1140 | else |
| 1138 | if (NILP (private)) | 1141 | { |
| 1139 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | 1142 | /* Initialize. */ |
| 1140 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | 1143 | 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 | 1144 | ||
| 1153 | /* If it is not the system or session bus, we must register | 1145 | /* Open the connection. */ |
| 1154 | ourselves. Otherwise, we have called dbus_bus_get, which has | 1146 | if (STRINGP (bus)) |
| 1155 | configured us to exit if the connection closes - we undo this | 1147 | if (NILP (private)) |
| 1156 | setting. */ | 1148 | connection = dbus_connection_open (SSDATA (bus), &derror); |
| 1157 | if (STRINGP (bus)) | 1149 | else |
| 1158 | dbus_bus_register (connection, &derror); | 1150 | 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 | 1151 | ||
| 1184 | /* Cleanup. */ | 1152 | else |
| 1185 | dbus_error_free (&derror); | 1153 | if (NILP (private)) |
| 1154 | connection = dbus_bus_get (EQ (bus, QCdbus_system_bus) | ||
| 1155 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1156 | &derror); | ||
| 1157 | else | ||
| 1158 | connection = dbus_bus_get_private (EQ (bus, QCdbus_system_bus) | ||
| 1159 | ? DBUS_BUS_SYSTEM : DBUS_BUS_SESSION, | ||
| 1160 | &derror); | ||
| 1161 | |||
| 1162 | if (dbus_error_is_set (&derror)) | ||
| 1163 | XD_ERROR (derror); | ||
| 1164 | |||
| 1165 | if (connection == NULL) | ||
| 1166 | XD_SIGNAL2 (build_string ("No connection to bus"), bus); | ||
| 1167 | |||
| 1168 | /* If it is not the system or session bus, we must register | ||
| 1169 | ourselves. Otherwise, we have called dbus_bus_get, which has | ||
| 1170 | configured us to exit if the connection closes - we undo this | ||
| 1171 | setting. */ | ||
| 1172 | if (STRINGP (bus)) | ||
| 1173 | dbus_bus_register (connection, &derror); | ||
| 1174 | else | ||
| 1175 | dbus_connection_set_exit_on_disconnect (connection, FALSE); | ||
| 1176 | |||
| 1177 | if (dbus_error_is_set (&derror)) | ||
| 1178 | XD_ERROR (derror); | ||
| 1179 | |||
| 1180 | /* Add the watch functions. We pass also the bus as data, in | ||
| 1181 | order to distinguish between the buses in xd_remove_watch. */ | ||
| 1182 | if (!dbus_connection_set_watch_functions (connection, | ||
| 1183 | xd_add_watch, | ||
| 1184 | xd_remove_watch, | ||
| 1185 | xd_toggle_watch, | ||
| 1186 | SYMBOLP (bus) | ||
| 1187 | ? (void *) XSYMBOL (bus) | ||
| 1188 | : (void *) XSTRING (bus), | ||
| 1189 | NULL)) | ||
| 1190 | XD_SIGNAL1 (build_string ("Cannot add watch functions")); | ||
| 1191 | |||
| 1192 | /* Add bus to list of registered buses. */ | ||
| 1193 | XSETFASTINT (val, (intptr_t) connection); | ||
| 1194 | xd_registered_buses = Fcons (Fcons (bus, val), xd_registered_buses); | ||
| 1195 | |||
| 1196 | /* We do not want to abort. */ | ||
| 1197 | putenv ((char *) "DBUS_FATAL_WARNINGS=0"); | ||
| 1198 | |||
| 1199 | /* Cleanup. */ | ||
| 1200 | dbus_error_free (&derror); | ||
| 1201 | } | ||
| 1186 | 1202 | ||
| 1187 | /* Return reference counter. */ | 1203 | /* Return reference counter. */ |
| 1188 | refcount = xd_get_connection_references (connection); | 1204 | refcount = xd_get_connection_references (connection); |