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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45943505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 10:42:26  来源:igfitidea点击:

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

craspbianraspberry-pi3netbeans-8dbus

提问by Dan_R

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

我正在尝试使用我的 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

来自一个优秀的教程: 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.

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

however, when running the program in netbeans i receive the following error

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

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

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

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

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

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

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

I can see that, if I SSH into the Pi myself and echo $DISPLAY this returns nothing, empty.

我可以看到,如果我自己通过 SSH 连接到 Pi 并回显 $DISPLAY,这将不返回任何内容,为空。

So far, i have tried:

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

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

did not work.

不工作。

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.

没有用。

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?

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

Thank you in advance for any advice.

预先感谢您的任何建议。

update 30 aug 2017:

2017 年 8 月 30 日更新:

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

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

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

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

I can confirm: in /etc/ssh/sshd_configX11Forwarding yes X11DisplayOffset 10...

我可以确认:在/etc/ssh/sshd_configX11Forwarding yes X11DisplayOffset 10...

xauth is installed on the remote Pi.

xauth 安装在远程 Pi 上。

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

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

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

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

DISPLAY=localhost:11.0 (this is wrong because the number changes with each ssh connection to the remote Pi).

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

So when i try to run the program, NetBeans will hang and i cant debug either.

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

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 will have the correct $DISPLAY?

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

回答by n. 'pronouns' m.

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.

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

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.

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

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

有关更多信息,请参阅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.

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

回答by Dan_R

The solution to this was as follows:

解决方法如下:

https://unix.stackexchange.com/a/12772

https://unix.stackexchange.com/a/12772

Also, ensuring that XQuartz (X11 client) is running on the client computer (macOS in this case).

此外,确保 XQuartz(X11 客户端)在客户端计算机(本例中为 macOS)上运行。

I will confirm if this works with the Pi (server) running in a headless configuration.

我将确认这是否适用于在无头配置中运行的 Pi(服务器)。