无法在没有 X11 的 $DISPLAY 的情况下自动启动 dbus 守护程序。网豆。Pi作为远程主机

Dan*_*n_R 5 c dbus raspbian netbeans-8 raspberry-pi3

我正在尝试使用我的 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;
}
Run Code Online (Sandbox Code Playgroud)

来自一个优秀的教程: DBUS TUTORIAL USING THE LOW-LEVEL API

我为 SSH 设置了无头 Pi,并安装了 dbus 开发所需的所有库。

但是,在 Netbeans 中运行程序时,我收到以下错误

无法在没有 X11 的 $DISPLAY 的情况下自动启动 dbus 守护程序

/usr/bin/dbus-launch 异常终止并出现以下错误:自动启动错误:X11 初始化失败。

请注意,我在 Netbeans 上的远程主机属性中启用了 X11 转发

我可以看到,如果我自己通过 SSH 连接到 Pi 并且

echo $DISPLAY
Run Code Online (Sandbox Code Playgroud)

这什么都不返回,空的。

到目前为止,我已经尝试过:

in /etc/ssh/sshd_config 
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
AllowTcpForwarding yes
Run Code Online (Sandbox Code Playgroud)

不工作。

我尝试将运行环境变量设置为

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"
Run Code Online (Sandbox Code Playgroud)

没有用。

并尝试

In /etc/ssh/ssh_config
ForwardX11 yes
Run Code Online (Sandbox Code Playgroud)

不工作。

是为 X11 设置我的 Pi 还是配置我的 Netbeans 环境以使用某些参数运行程序?

2017 年 8 月 30 日更新:

我重新安装了 Debian 并遵循了 Gilles 的回答:

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

我可以确认:

in /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
Run Code Online (Sandbox Code Playgroud)

xauth 安装在远程 Pi 上。

我已经在我的客户端 mac 上安装了 XQuartz。在ssh -X pi@IPaddress,xquartz 打开,如果我echo $DISPLAY在远程 Pi 上,我会得到localhost:12.0......数字随每个终端而变化。

目前,如果在 Netbeans 中错误地设置了项目环境:

DISPLAY=localhost:11.0
Run Code Online (Sandbox Code Playgroud)

(这是错误的,因为每次 ssh 连接到远程 Pi 时,数字都会发生变化)。

因此,当我尝试运行该程序时,NetBeans 将挂起并且我也无法调试。

我在这个阶段的问题是,如何$DISPLAY为 NetBeans 正确设置环境,以便每次与远程 Pi 建立 SSH 连接并请求 X11 转发时,它都有正确的$DISPLAY?

n. *_* m. 5

dbus-daemon 的自动启动仅在 X11 会话下有效。否则它会被禁用,因为不同的应用程序无法建立 dbus 守护程序的公共实例。

如果你想在你的 pi box 上独立于 X11 运行一个 dbus 守护进程,你可能应该将它配置为在启动时启动 dbus 守护进程,并在 DBUS_SESSION_BUS_ADDRESS 环境变量中导出总线地址。

有关更多信息,请参阅https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=690530

另一方面,如果您想使用远程 X 会话,则需要修复错误配置的 X11 转发,以便在通过 ssh 连接到 Pi 时正确设置 DISPLAY 环境变量。参见例如https://unix.stackexchange.com/questions/12755/how-to-forward-x-over-ssh-to-run-graphics-applications-remotely


Xer*_*rtz 5

扩展n。1.8e9-我的份额在哪里 m。的答案,因为这是谷歌搜索的最高结果“ Unable to autolaunch a dbus-daemon without a $DISPLAY for X11 ”:

如果您想在 pi 盒子上独立于 X11 运行 dbus 守护进程,您可能应该将其配置为在启动时启动 dbus 守护进程,并在 DBUS_SESSION_BUS_ADDRESS 环境变量中导出总线地址。

在 WSL Ubuntu 20.04 上:

确保 dbus 服务正在运行:

service dbus status
Run Code Online (Sandbox Code Playgroud)

将总线地址导出到 DBUS_SESSION_BUS_ADDRESS 环境变量

export $(dbus-launch)
Run Code Online (Sandbox Code Playgroud)

这解决了我的问题