hello world fails!

Jonne Zutt j.zutt at ewi.tudelft.nl
Sun Mar 5 10:15:13 PST 2006


Trying to write some code such that I can use DBus from Tcl (Tcl binding).
First I wanted to get something working, then think about what it exactly
is that I'm going to use.
At least I want to be able to send and receive DBus signals.

I use the code listed below and found something quite weird. Hopefully
someone can explain me what I'm doing wrong.

--- Dbus is running
eval `dbus-launch` && export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID
[jonne at localhost dbus]$ env | grep DBUS
DBUS_SESSION_BUS_PID=751
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-6Ya2dIZZ9o,guid=b7260b44cb52f5885a6017a045cc8900

--- This test program seems to work (current cvs version)
[jonne at localhost dbus]$ pwd
~/Checkouts/Projects/dbus/test
[jonne at localhost dbus]$ ./test-names
Successfully acquired name 'org.freedesktop.DBus.Test'
Successfully acquired name 'org.freedesktop.DBus.Test-2'
Successfully acquired name 'org.freedesktop.DBus.Test_2'

--- Then why does my program not work? The code that is executed
--- up to the error, seems equivalent to me.
[jonne at localhost dbus]$ ./dbus
Failed to open connection to session bus: Failed to connect to socket
/tmp/dbus-6Ya2dIZZ9o: Connection refused

--- Here is my code
//
// Dbus C API Interface
//

#define DBUS_API_SUBJECT_TO_CHANGE
#define SERVICE "org.freedesktop.DBus.Testing"

#include <stdio.h>
#include <stdlib.h>

#include <dbus/dbus.h>

int main() {
  DBusConnection *connection;
  DBusError error;
  int result;

  dbus_error_init(&error);
  connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
  if(connection == NULL) {
	fprintf(stderr, "Failed to open connection to session bus: %s\n",
error.message);
	dbus_error_free(&error);
	return 1;
  }

  dbus_bus_request_name(connection, SERVICE, 0, &error);
  if(dbus_error_is_set(&error)) {
	fprintf(stderr, "Error has been set: $s\n", error.message);
  }

}


More information about the dbus mailing list