/** * wpa_dbus_get_object_properties - Put object's properties into dictionary * @iface: dbus priv struct * @path: path to DBus object which properties will be obtained * @interface: interface name which properties will be obtained * @iter: DBus message iter at which to append property dictionary. * * Iterates over all properties registered with object and execute getters * of those, which are readable and which interface matches interface * specified as argument. Obtained properties values are stored in * dict_iter dictionary. */ dbus_bool_t wpa_dbus_get_object_properties(struct wpas_dbus_priv *iface, const char *path, const char *interface, DBusMessageIter *iter) { struct wpa_dbus_object_desc *obj_desc = NULL; DBusMessageIter dict_iter; DBusError error; dbus_connection_get_object_path_data(iface->con, path, (void **) &obj_desc); if (!obj_desc) { wpa_printf(MSG_ERROR, "dbus: %s: could not obtain object's " "private data: %s", __func__, path); return FALSE; } if (!wpa_dbus_dict_open_write(iter, &dict_iter)) { wpa_printf(MSG_ERROR, "dbus: %s: failed to open message dict", __func__); return FALSE; } dbus_error_init(&error); if (!fill_dict_with_properties(&dict_iter, obj_desc->properties, interface, obj_desc->user_data, &error)) { wpa_printf(MSG_ERROR, "dbus: %s: failed to get object" " properties: (%s) %s", __func__, dbus_error_is_set(&error) ? error.name : "none", dbus_error_is_set(&error) ? error.message : "none"); dbus_error_free(&error); return FALSE; } return wpa_dbus_dict_close_write(iter, &dict_iter); }
static void object_path_unref(DBusConnection *connection, const char *path) { struct generic_data *data = NULL; if (dbus_connection_get_object_path_data(connection, path, (void *) &data) == FALSE) return; if (data == NULL) return; data->refcount--; if (data->refcount > 0) return; remove_interface(data, DBUS_INTERFACE_INTROSPECTABLE); remove_interface(data, DBUS_INTERFACE_PROPERTIES); remove_interface(data, DBUS_INTERFACE_OBJECT_MANAGER); invalidate_parent_data(data->conn, data->path); dbus_connection_unregister_object_path(data->conn, data->path); }
static DBusHandlerResult handle_echo (DBusConnection *connection, DBusMessage *message) { DBusError error; DBusMessage *reply; DBusMessageIter iter; int i; EchoData *d; _dbus_verbose ("sending reply to Echo method\n"); if (!dbus_connection_get_object_path_data (connection, echo_path, (void **)&d)) die ("No memory"); dbus_error_init (&error); reply = dbus_message_new_method_return (message); if (reply == NULL) die ("No memory\n"); dbus_message_iter_init_append (reply, &iter); for (i = 0; i < d->argc; ++i) if (!dbus_message_iter_append_basic (&iter, DBUS_TYPE_STRING, &(d->argv[i]))) die ("No memory\n"); if (!dbus_connection_send (connection, reply, NULL)) die ("No memory\n"); fprintf (stderr, "Shell echo service echoed the command line\n"); dbus_message_unref (reply); return DBUS_HANDLER_RESULT_HANDLED; }
dbusrecv_hdl_st *dbusrecv_init(char *myname, callbk_filter_func filter_func) { dbusrecv_hdl_st *p_dbusrecv_hdl = NULL; int result = 0; int retval = 0; if (NULL == myname) { printf("dbusrev_init: invalid parameters, myname couldn't be NULL!\n"); return NULL; } if (NULL == filter_func) { printf("dbusrev_init: invalid parameters, filter_func couldn't be NULL!\n"); return NULL; } p_dbusrecv_hdl = DBUS_MALLOC(sizeof(dbusrecv_hdl_st)); if (NULL == p_dbusrecv_hdl) { printf("dbusrev_init: malloc failed, p_dbusrecv_hdl!\n"); return NULL; } p_dbusrecv_hdl->dbusrecv_cfg.myname = (char *)malloc(strlen(myname) + 1); memset(p_dbusrecv_hdl->dbusrecv_cfg.myname, 0x0, strlen(myname) + 1); memcpy(p_dbusrecv_hdl->dbusrecv_cfg.myname, myname, strlen(myname)); p_dbusrecv_hdl->filter_func = filter_func; dbus_error_init (&p_dbusrecv_hdl->error); p_dbusrecv_hdl->connection = dbus_bus_get (DBUS_BUS_SYSTEM, &p_dbusrecv_hdl->error); if (NULL == p_dbusrecv_hdl->connection) { printf("%s: Failed to open connection to activating message bus: %s\n", __FILE__, p_dbusrecv_hdl->error.message); retval = -1; goto ERROR; } p_dbusrecv_hdl->dbusloop = _dbus_loop_new (); if (NULL == p_dbusrecv_hdl->dbusloop) { printf("%s: No memory, p_dbusrecv_hdl->dbusloop\n", __FILE__); retval = -1; goto ERROR; } if (!test_connection_setup (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection)) { printf("%s: No memory, test_connection_setup\n", __FILE__); retval = -1; goto ERROR; } /* match options: type interface; member; sender; destination; path; */ #if 0 memset(rules, 0x0, sizeof(rules)); sprintf(rules, "type='signal', interface='%s'", p_dbusrecv_hdl->dbusrecv_cfg.interface); dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: add match(%s) failed\n", __FILE__, rules); retval = -1; goto ERROR; } memset(rules, 0x0, sizeof(rules)); sprintf(rules, "type='signal', interface='org.actiontec.Test'"); dbus_bus_add_match (p_dbusrecv_hdl->connection, rules, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: add match(%s) failed\n", __FILE__, rules); retval = -1; goto ERROR; } #endif if (!dbus_connection_add_filter(p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, (void *)p_dbusrecv_hdl, NULL)) { printf("%s: No memory, dbus_connection_add_filter\n", __FILE__); retval = -1; goto ERROR; } p_dbusrecv_hdl->is_addfilter = 1; if (!dbus_connection_register_object_path (p_dbusrecv_hdl->connection, DBUS_DEFAULT_PATH, &dbusrecv_vtable, (void *)p_dbusrecv_hdl)) //(void*) 0xdeadbeef)) { printf("%s: No memory, dbus_connection_register_object_path\n", __FILE__); retval = -1; goto ERROR; } { void *d; if (!dbus_connection_get_object_path_data (p_dbusrecv_hdl->connection, DBUS_DEFAULT_PATH, &d)) { printf("%s: No memory, dbus_connection_get_object_path_data\n", __FILE__); retval = -1; goto ERROR; } //if (d != (void*) 0xdeadbeef) if (d != (void*) p_dbusrecv_hdl) { printf("%s: dbus_connection_get_object_path_data() doesn't seem to work right\n", __FILE__); retval = -1; goto ERROR; } } result = dbus_bus_request_name(p_dbusrecv_hdl->connection, myname, 0, &p_dbusrecv_hdl->error); if (dbus_error_is_set (&p_dbusrecv_hdl->error)) { printf("%s: Failed to acquire service: %s\n", __FILE__, p_dbusrecv_hdl->error.message); retval = -1; goto ERROR; } //_dbus_verbose("%s: service(%s) entering main loop!\n", __FILE__, myname); //_dbus_loop_run(p_dbusrecv_hdl->dbusloop); retval = 0; ERROR: if (-1 == retval) { dbus_error_free (&p_dbusrecv_hdl->error); if (p_dbusrecv_hdl->connection) { test_connection_shutdown (p_dbusrecv_hdl->dbusloop, p_dbusrecv_hdl->connection); if (p_dbusrecv_hdl->is_addfilter) dbus_connection_remove_filter (p_dbusrecv_hdl->connection, p_dbusrecv_hdl->filter_func, NULL);// dbus_connection_unref (p_dbusrecv_hdl->connection); p_dbusrecv_hdl->connection = NULL; } if (p_dbusrecv_hdl->dbusloop) { _dbus_loop_unref (p_dbusrecv_hdl->dbusloop); p_dbusrecv_hdl->dbusloop = NULL; } dbus_shutdown(); _dbus_verbose("%s: service(%s) exiting!\n", __FILE__, myname); return NULL; } return p_dbusrecv_hdl; }
int DBusUnknownCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_DBusBus *dbus = defaultbus; Tcl_DBusHandlerData *data; Tcl_DBusMethodData *method; Tcl_HashEntry *memberPtr; int x = 1, isNew, flags, index; char c, *path = NULL; Tcl_Obj *handler = NULL, *result; static const char *options[] = {"-details", NULL}; enum options {DBUS_DETAILS}; if (objc > 1) { c = Tcl_GetString(objv[1])[0]; /* Options start with '-', path starts with '/' or is "" */ /* Anything else has to be a busId specification */ if (c != '/' && c != '-' && c != '\0') { if (DBus_BusType(interp, objv[1]) < 0) return TCL_ERROR; dbus = DBus_GetConnection(interp, objv[1]); x++; } } /* Unknown handlers are always async */ flags = DBUSFLAG_ASYNC; for (; x < objc; x++) { c = Tcl_GetString(objv[x])[0]; if (c != '-') break; if (Tcl_GetIndexFromObj(interp, objv[x], options, "option", 0, &index) != TCL_OK) { return TCL_ERROR; } switch ((enum options) index) { case DBUS_DETAILS: flags |= DBUSFLAG_DETAILS; break; } } if (x < objc) { c = Tcl_GetString(objv[x])[0]; if (c != '\0' && !DBus_CheckPath(objv[x])) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid path", -1)); return TCL_ERROR; } path = Tcl_GetString(objv[x++]); } if (x < objc) { handler = objv[x++]; } if (x != objc) { Tcl_WrongNumArgs(interp, 1, objv, "?busId? ?options? ?path ?script??"); return TCL_ERROR; } if (dbus == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Not connected", -1)); return TCL_ERROR; } if (handler == NULL) { /* Request for a report on currently registered handler(s) */ if (path == NULL) { /* Get all handlers for any path */ result = DBus_ListListeners(interp, dbus, "", DBUS_METHODFLAG | DBUS_UNKNOWNFLAG); /* append all currently registered handlers from the root path */ Tcl_ListObjAppendList(NULL, result, DBus_ListListeners(interp, dbus, "/", DBUS_METHODFLAG | DBUS_UNKNOWNFLAG | DBUS_RECURSEFLAG)); Tcl_SetObjResult(interp, result); return TCL_OK; } method = DBus_FindListeners(dbus, path, "", TRUE); if (method != NULL && method->interp == interp) { /* Return the script configured for the handler */ Tcl_IncrRefCount(method->script); Tcl_SetObjResult(interp, method->script); } return TCL_OK; } if (Tcl_GetCharLength(handler) == 0) { /* Unregistering a handler */ if (*path != '\0') { if (!dbus_connection_get_object_path_data(dbus->conn, path, (void **)&data)) return DBus_MemoryError(interp); } else { data = dbus->fallback; } if (data == NULL) return TCL_OK; if (data->method == NULL) return TCL_OK; memberPtr = Tcl_FindHashEntry(data->method, ""); if (memberPtr == NULL) return TCL_OK; method = Tcl_GetHashValue(memberPtr); Tcl_DecrRefCount(method->script); ckfree((char *) method); Tcl_DeleteHashEntry(memberPtr); /* Clean up the message handler, if no longer used */ if (Tcl_CheckHashEmpty(data->method)) { Tcl_DeleteHashTable(data->method); ckfree((char *) data->method); data->method = NULL; if (data->signal == NULL && !(data->flags & DBUSFLAG_FALLBACK)) { ckfree((char *) data); if (*path != '\0') dbus_connection_unregister_object_path(dbus->conn, path); else dbus->fallback = NULL; } } return TCL_OK; } /* Register the new handler */ data = DBus_GetMessageHandler(interp, dbus, path); if (data->method == NULL) { /* No methods have been defined for this path by any interpreter yet So first a hash table indexed by interpreter must be created */ data->method = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(data->method, TCL_STRING_KEYS); } memberPtr = Tcl_CreateHashEntry(data->method, "", &isNew); if (isNew) { method = (Tcl_DBusMethodData *) ckalloc(sizeof(Tcl_DBusMethodData)); method->interp = interp; method->conn = dbus->conn; Tcl_SetHashValue(memberPtr, method); } else { method = Tcl_GetHashValue(memberPtr); if(method->interp == interp) { /* Release the old script */ Tcl_DecrRefCount(method->script); } else { /* Method was registered by another interpreter */ Tcl_SetObjResult(interp, Tcl_NewStringObj("unknown handler is defined " "by another interpreter", -1)); return TCL_ERROR; } } method->script = handler; method->flags = flags; Tcl_IncrRefCount(handler); return TCL_OK; }
int DBusListenCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]) { Tcl_DBusBus *dbus = defaultbus; Tcl_DBusHandlerData *data; Tcl_DBusSignalData *signal; Tcl_HashTable *interps; Tcl_HashEntry *memberPtr, *interpPtr; int x = 1, flags = 0, index, isNew; char c, *path = NULL; Tcl_Obj *name = NULL, *handler = NULL, *result; static const char *options[] = {"-details", NULL}; enum options {DBUS_DETAILS}; if (objc > 1) { c = Tcl_GetString(objv[1])[0]; /* Options start with '-', path starts with '/' or is "" */ /* Anything else has to be a busId specification */ if (c != '/' && c != '-' && c != '\0') { if (DBus_BusType(interp, objv[1]) < 0) return TCL_ERROR; dbus = DBus_GetConnection(interp, objv[1]); x++; } } for (; x < objc; x++) { c = Tcl_GetString(objv[x])[0]; if (c != '-') break; if (Tcl_GetIndexFromObj(interp, objv[x], options, "option", 0, &index) != TCL_OK) { return TCL_ERROR; } switch ((enum options) index) { case DBUS_DETAILS: flags |= DBUSFLAG_DETAILS; break; } } if (x < objc) { if (Tcl_GetCharLength(objv[x]) > 0 && !DBus_CheckPath(objv[x])) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid path", -1)); return TCL_ERROR; } path = Tcl_GetString(objv[x++]); } if (x < objc) { if (!DBus_CheckMember(objv[x]) && DBus_CheckIntfName(objv[x]) < 2) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Invalid signal name", -1)); return TCL_ERROR; } name = objv[x++]; } if (x < objc) { handler = objv[x++]; } if (x != objc) { Tcl_WrongNumArgs(interp, 1, objv, "?busId? ?options? " "?path ?signal ?script???"); return TCL_ERROR; } if (dbus == NULL) { Tcl_SetObjResult(interp, Tcl_NewStringObj("Not connected", -1)); return TCL_ERROR; } if (handler == NULL) { /* Request for a report on currently registered handler(s) */ if (path == NULL) { /* Get all handlers for any path */ result = DBus_ListListeners(interp, dbus, "", 0); /* Append the registered handlers from the root path */ Tcl_ListObjAppendList(NULL, result, DBus_ListListeners(interp, dbus, "/", DBUS_RECURSEFLAG)); Tcl_SetObjResult(interp, result); return TCL_OK; } if (name == NULL) { /* Report all currently registered handlers at the specified path */ Tcl_SetObjResult(interp, DBus_ListListeners(interp, dbus, path, 0)); return TCL_OK; } interps = DBus_FindListeners(dbus, path, Tcl_GetString(name), FALSE); if (interps != NULL) { /* Check if a signal handler was registered by the current interp */ memberPtr = Tcl_FindHashEntry(interps, (char * ) interp); if (memberPtr != NULL) { /* Return the script configured for the handler */ signal = Tcl_GetHashValue(memberPtr); Tcl_IncrRefCount(signal->script); Tcl_SetObjResult(interp, signal->script); } } return TCL_OK; } if (Tcl_GetCharLength(handler) == 0) { /* Unregistering a handler */ if (*path != '\0') { if (!dbus_connection_get_object_path_data(dbus->conn, path, (void **)&data)) return DBus_MemoryError(interp); } else { data = dbus->fallback; } if (data == NULL) return TCL_OK; if (data->signal == NULL) return TCL_OK; memberPtr = Tcl_FindHashEntry(data->signal, Tcl_GetString(name)); if (memberPtr == NULL) return TCL_OK; interps = Tcl_GetHashValue(memberPtr); interpPtr = Tcl_FindHashEntry(interps, (char *) interp); if (interpPtr == NULL) return TCL_OK; signal = Tcl_GetHashValue(interpPtr); Tcl_DecrRefCount(signal->script); ckfree((char *) signal); Tcl_DeleteHashEntry(interpPtr); /* Clean up the message handler, if no longer used */ if (Tcl_CheckHashEmpty(interps)) { Tcl_DeleteHashTable(interps); ckfree((char *) interps); Tcl_DeleteHashEntry(memberPtr); if (Tcl_CheckHashEmpty(data->signal)) { Tcl_DeleteHashTable(data->signal); ckfree((char *) data->signal); data->signal = NULL; if (data->method == NULL && !(data->flags & DBUSFLAG_FALLBACK)) { ckfree((char *) data); if (*path != '\0') dbus_connection_unregister_object_path(dbus->conn, path); else dbus->fallback = NULL; } } } return TCL_OK; } /* Register the new handler */ data = DBus_GetMessageHandler(interp, dbus, path); if (data->signal == NULL) { /* No signals have been defined for this path by any interpreter yet So first a hash table indexed by interpreter must be created */ data->signal = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(data->signal, TCL_STRING_KEYS); } memberPtr = Tcl_CreateHashEntry(data->signal, Tcl_GetString(name), &isNew); if (isNew) { interps = (Tcl_HashTable *) ckalloc(sizeof(Tcl_HashTable)); Tcl_InitHashTable(interps, TCL_ONE_WORD_KEYS); Tcl_SetHashValue(memberPtr, (ClientData) interps); } else { interps = Tcl_GetHashValue(memberPtr); } /* Find the entry for the current interpreter */ memberPtr = Tcl_CreateHashEntry(interps, (char *) interp, &isNew); if (isNew) { signal = (Tcl_DBusSignalData *) ckalloc(sizeof(Tcl_DBusSignalData)); Tcl_SetHashValue(memberPtr, signal); } else { /* Release the old script */ signal = Tcl_GetHashValue(memberPtr); Tcl_DecrRefCount(signal->script); } signal->script = handler; signal->flags = flags; Tcl_IncrRefCount(handler); return TCL_OK; }
static Tcl_Obj *DBus_ListListeners(Tcl_Interp *interp, Tcl_DBusBus *dbus, const char *path, int flags) { Tcl_Obj *list, *sublist; char **entries, **entry, *newpath, *pathentry, *s; Tcl_DBusHandlerData *data; Tcl_DBusSignalData *signal; Tcl_DBusMethodData *method; Tcl_HashTable *interps; Tcl_HashEntry *memberPtr, *interpPtr; Tcl_HashSearch search; list = Tcl_NewObj(); /* Check if the specified path has a handler defined */ if (*path == '\0') data = dbus->fallback; else dbus_connection_get_object_path_data(dbus->conn, path, (void **)&data); if (data != NULL) { if ((flags & DBUS_METHODFLAG) == 0 && data->signal != NULL) { for (memberPtr = Tcl_FirstHashEntry(data->signal, &search); memberPtr != NULL; memberPtr = Tcl_NextHashEntry(&search)) { interps = Tcl_GetHashValue(memberPtr); interpPtr = Tcl_FindHashEntry(interps, (char *) interp); if (interpPtr != NULL) { signal = Tcl_GetHashValue(interpPtr); /* Report both the path and the script configured for the path */ Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj(path, -1)); s = Tcl_GetHashKey(data->signal, memberPtr); Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj(s, -1)); Tcl_ListObjAppendElement(NULL, list, signal->script); } } } else if ((flags & DBUS_METHODFLAG) != 0 && data->method != NULL) { for (memberPtr = Tcl_FirstHashEntry(data->method, &search); memberPtr != NULL; memberPtr = Tcl_NextHashEntry(&search)) { method = Tcl_GetHashValue(memberPtr); if (method->interp == interp) { s = Tcl_GetHashKey(data->method, memberPtr); /* Normally skip unknown handlers. But when listing */ /* unknown handlers, skip all named handlers. */ if (!(flags & DBUS_UNKNOWNFLAG) == (*s == '\0')) continue; /* Report both the path and the script configured for the path */ Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj(path, -1)); /* There is no method name for unknown handlers */ if (!(flags & DBUS_UNKNOWNFLAG)) Tcl_ListObjAppendElement(NULL, list, Tcl_NewStringObj(s, -1)); Tcl_ListObjAppendElement(NULL, list, method->script); } } } } if (flags & DBUS_RECURSEFLAG) { /* Get a list of children of the current path */ dbus_connection_list_registered(dbus->conn, path, &entries); /* Allocate space for concatenating the path and a childs name */ newpath = ckalloc(strlen(path) + 256); /* Copy the path in the allocated space, making sure it ends with a / */ strcpy(newpath, path); pathentry = newpath + strlen(path) - 1; if (*pathentry++ != '/') *pathentry++ = '/'; /* Append each childs name to the path in turn */ for (entry = entries; *entry != NULL; entry++) { strncpy(pathentry, *entry, 255); /* Get a list of descendents from the child */ sublist = DBus_ListListeners(interp, dbus, newpath, flags); /* Append the sublist entries to the total list */ Tcl_ListObjAppendList(NULL, list, sublist); /* Release the temporary sublist */ Tcl_DecrRefCount(sublist); } /* Release the entries array */ dbus_free_string_array(entries); ckfree(newpath); } return list; }
int main (int argc, char **argv) { DBusError error; int result; DBusConnection *connection; dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message); dbus_error_free (&error); return 1; } loop = _dbus_loop_new (); if (loop == NULL) die ("No memory\n"); if (!test_connection_setup (loop, connection)) die ("No memory\n"); if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) die ("No memory"); if (!dbus_connection_register_object_path (connection, echo_path, &echo_vtable, (void*) 0xdeadbeef)) die ("No memory"); { void *d; if (!dbus_connection_get_object_path_data (connection, echo_path, &d)) die ("No memory"); if (d != (void*) 0xdeadbeef) die ("dbus_connection_get_object_path_data() doesn't seem to work right\n"); } result = dbus_bus_request_name (connection, "org.freedesktop.DBus.TestSuiteEchoService", 0, &error); if (dbus_error_is_set (&error)) { fprintf (stderr, "Error %s\n", error.message); _dbus_verbose ("*** Failed to acquire service: %s\n", error.message); dbus_error_free (&error); exit (1); } _dbus_verbose ("*** Test service entering main loop\n"); _dbus_loop_run (loop); test_connection_shutdown (loop, connection); dbus_connection_remove_filter (connection, filter_func, NULL); dbus_connection_unref (connection); _dbus_loop_unref (loop); loop = NULL; dbus_shutdown (); _dbus_verbose ("*** Test service exiting\n"); return 0; }
int main (int argc, char **argv) { DBusError error; int result; DBusConnection *connection; const char *name; dbus_bool_t do_fork; if (argc != 3) { name = "org.freedesktop.DBus.TestSuiteEchoService"; do_fork = FALSE; } else { name = argv[1]; #ifndef DBUS_WIN do_fork = strcmp (argv[2], "fork") == 0; #else do_fork = FALSE; #endif } /* The bare minimum for simulating a program "daemonizing"; the intent * is to test services which move from being legacy init scripts to * activated services. * https://bugzilla.redhat.com/show_bug.cgi?id=545267 */ #ifndef DBUS_WIN if (do_fork) { pid_t pid = fork (); if (pid != 0) exit (0); sleep (1); } #endif dbus_error_init (&error); connection = dbus_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { fprintf (stderr, "*** Failed to open connection to activating message bus: %s\n", error.message); dbus_error_free (&error); return 1; } loop = _dbus_loop_new (); if (loop == NULL) die ("No memory\n"); if (!test_connection_setup (loop, connection)) die ("No memory\n"); if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) die ("No memory"); if (!dbus_connection_register_object_path (connection, echo_path, &echo_vtable, (void*) 0xdeadbeef)) die ("No memory"); { void *d; if (!dbus_connection_get_object_path_data (connection, echo_path, &d)) die ("No memory"); if (d != (void*) 0xdeadbeef) die ("dbus_connection_get_object_path_data() doesn't seem to work right\n"); } result = dbus_bus_request_name (connection, name, 0, &error); if (dbus_error_is_set (&error)) { fprintf (stderr, "Error %s\n", error.message); _dbus_verbose ("*** Failed to acquire service: %s\n", error.message); dbus_error_free (&error); exit (1); } _dbus_verbose ("*** Test service entering main loop\n"); _dbus_loop_run (loop); test_connection_shutdown (loop, connection); dbus_connection_remove_filter (connection, filter_func, NULL); dbus_connection_unref (connection); _dbus_loop_unref (loop); loop = NULL; dbus_shutdown (); _dbus_verbose ("*** Test service exiting\n"); return 0; }