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
[jonne at localhost dbus]$ env | grep DBUS

--- This test program seems to work (current cvs version)
[jonne at localhost dbus]$ pwd
[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 SERVICE "org.freedesktop.DBus.Testing"

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

#include <dbus/dbus.h>

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

  connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
  if(connection == NULL) {
	fprintf(stderr, "Failed to open connection to session bus: %s\n",
	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