c - 无法在没有 $DISPLAY for X11 的情况下自动启动 dbus-daemon。网 bean 。 Pi 作为远程主机

标签 c raspbian raspberry-pi3 netbeans-8 dbus

我正在尝试使用我的 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;
}
来自一个优秀的教程:
DBUS TUTORIAL USING THE LOW-LEVEL API
我为 SSH 设置了 headless Pi,并安装了 dbus 开发所需的所有库。
但是,在 Netbeans 中运行程序时,我收到以下错误
无法在没有 $DISPLAY for X11 的情况下自动启动 dbus-daemon/usr/bin/dbus-launch异常终止并出现以下错误:自动启动错误:X11 初始化失败。
请注意,我在 Netbeans 上的远程主机属性中启用了 X11 转发
我可以看到,如果我自己通过 SSH 连接到 Pi
echo $DISPLAY
这不返回任何内容,为空。
到目前为止,我已经尝试过:
in /etc/ssh/sshd_config 
X11Forwarding yes
X11DisplayOffset 10
X11UseLocalhost no
AllowTcpForwarding yes
不工作。
我尝试将运行环境变量设置为
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"
没用。
并尝试过
In /etc/ssh/ssh_config
ForwardX11 yes
不工作。
是否需要为 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
xauth 安装在远程 Pi 上。
我已经在我的客户端 mac 上安装了 XQuartz。根据 ssh -X pi@IPaddress , xquartz 打开,如果我 echo $DISPLAY在远程 Pi 上我得到 localhost:12.0 ...数字随每个终端而变化。
目前,如果在 Netbeans 中错误地设置了项目环境:
DISPLAY=localhost:11.0
(这是错误的,因为与远程 Pi 的每个 ssh 连接都会更改数字)。
因此,当我尝试运行该程序时,NetBeans 将挂起,我也无法调试。
我现阶段的问题是,如何设置 $DISPLAY NetBeans 的环境正确,因此每次与远程 Pi 建立 SSH 连接并请求 X11 转发时,它都有正确的 $DISPLAY ?

最佳答案

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

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

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

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

关于c - 无法在没有 $DISPLAY for X11 的情况下自动启动 dbus-daemon。网 bean 。 Pi 作为远程主机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45943505/

相关文章:

opencv - 使用 cv_bridge(ROS indigo) 和 OpenCV 3 时出现段错误(核心已转储)

python - Linux实时优先运行Python程序的方法

python - open cv检测到人脸后如何让python执行命令?

c++ - 如何在 QtCreator 上使用带有 highGUI 的 OpenCV?

c - 合并排序算法

visual-studio-code - 使用 SSH 到 Raspbian 的 Visual Studio Code 远程开发

在c中将大端转换为小端。警告 :return from incompatible pointer type [-Wincompatible-pointer-types] return src;

python - SyntaxError : 'break' outside loop, 错误仅在树莓派 3 上给出,而不是在 pc 上

C套接字内存溢出

c - 我应该在 Linux 中释放 getpwuid() 返回的指针吗?