Unable to autolaunch a dbus-daemon without a $DISPLAY for X11. NetBeans. Pi as remote host
Asked Answered
H

2

8

I am trying to run the following example code using my NetBeans IDE:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dbus/dbus.h>
 
int main() {
    DBusConnection *connection = NULL;
    DBusError error;
    char buffer[1024];
 
    dbus_error_init(&error);
    connection = dbus_bus_get(DBUS_BUS_SESSION, &error);
    if (dbus_error_is_set(&error)) {
        fprintf(stderr, "%s", error.message);
        abort();
    }
 
    puts("This is my unique name");
    puts(dbus_bus_get_unique_name(connection));
    fgets(buffer, sizeof(buffer), stdin);
     
    return 0;
}

From an excellent tutorial: DBUS TUTORIAL USING THE LOW-LEVEL API

I have my headless Pi setup for SSH and have installed all the necessary libraries for dbus development.

however, when running the program in Netbeans I receive the following error

Unable to autolaunch a dbus-daemon without a $DISPLAY for X11

/usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.

note that i have X11 forwarding enabled in my remote host properties on Netbeans

I can see that, if I SSH into the Pi myself and

echo $DISPLAY

this returns nothing, empty.

So far, I have tried:

in /etc/ssh/sshd_config 
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
AllowTcpForwarding yes

did not work.

I tried setting a run environment variable to

DISPLAY export DISPLAY=$HOSTNAME:0.0

0x212d0 "org.freedesktop.DBus.Error.Spawn.ExecFailed"
0x21fe8 "/usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.\\n"

didn’t work.

and tried

In /etc/ssh/ssh_config
ForwardX11 yes

did not work.

Is it a case of getting my Pi setup for X11 or configuring my Netbeans environment to run the program with certain parameters?

update 30 Aug 2017:

I did a fresh install of Debian and followed Gilles' answer:

https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely ...

I can confirm:

in /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10

xauth is installed on the remote Pi.

I have installed XQuartz on my client mac. Upon ssh -X pi@IPaddress, xquartz opens and if I echo $DISPLAY on the remote Pi I get localhost:12.0 ... the number changes with each terminal.

Currently, if have incorrectly set the project environment in Netbeans with:

DISPLAY=localhost:11.0

(this is wrong because the number changes with each ssh connection to the remote Pi).

So when I try to run the program, NetBeans will hang and I can't debug either.

My question at this stage is, how do I set the $DISPLAY Environment correctly for NetBeans so that each time it makes an SSH connection to the remote Pi and requests X11 forwarding, it has the correct $DISPLAY?

Hawserlaid answered 29/8, 2017 at 15:54 Comment(0)
P
7

Autolaunch of dbus-daemon only works when under an X11 session. It is otherwise disabled because there's no way for different applications to establish a common instance of the dbus daemon.

If you want to run a dbus daemon on your pi box independently of X11, you probably should configure it to launch the dbus daemon on startup, and export the bus address in DBUS_SESSION_BUS_ADDRESS environment variable.

For more info see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=690530

If on the other hand you want to use your remote X session, you need to fix your misconfigured X11 forwarding such that the DISPLAY environment variable is set correctly when you ssh into the Pi. See e.g https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely .

Pannell answered 29/8, 2017 at 16:25 Comment(3)
Thanks for your reply. I have followed Gilles' answer in the link you have provided. and also installed XQuartz on the client mac. Please see the updates in my main question. How may i set the $DISPLAY environment correctly in my NetBeans project so that each time netbeans makes an SSH connection to the remote Pi, it correctly sets a DISPLAY? Many thanks.Hawserlaid
@Hawserlaid If you have a new question please ask a new question.Pannell
Apologies, you are correct... I have raised a new question here: [link] (https://mcmap.net/q/1326591/-netbeans-how-to-set-display-environment-for-remote-ssh-server-pi/1315288)Hawserlaid
M
5

Expanding on n. 1.8e9-where's-my-share m.'s answer because this is the top result for Googling "Unable to autolaunch a dbus-daemon without a $DISPLAY for X11":

If you want to run a dbus daemon on your pi box independently of X11, you probably should configure it to launch the dbus daemon on startup, and export the bus address in DBUS_SESSION_BUS_ADDRESS environment variable.

On WSL Ubuntu 20.04:

Make sure dbus service is running:

service dbus status

Export bus address to DBUS_SESSION_BUS_ADDRESS environment variable

export $(dbus-launch)

And this fixed the issue for me

Minutia answered 3/1, 2022 at 1:37 Comment(1)
Thank you. I've been at this for hours. I was RDP'd into this Ubuntu 20.04 server for quite a while, and then the display froze, sshd stopped working, and the fans went crazy. I had just seen the result of my xsession error log, and it said something about dbus-launch not being present! Additionally, systemd reported that dbus was up and running. I did what you said, and when I ran the export $(dbus-launch) I got a message that it needs to be installed from apt-get! Just did that, and boom I'm looking at a screen again.Angary

© 2022 - 2024 — McMap. All rights reserved.