如果没有$ DISPLAY的X11,则无法自动启动dbus守护程序. NetBeans. Pi作为远程主机 [英] Unable to autolaunch a dbus-daemon without a $DISPLAY for X11. NetBeans. Pi as remote host
问题描述
我正在尝试使用NetBeans IDE运行以下示例代码:
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;
}
从一个出色的教程中: 使用低级的DBUS教程API
From an excellent tutorial: DBUS TUTORIAL USING THE LOW-LEVEL API
我为SSH设置了无头Pi设置,并安装了所有用于dbus开发的必需库.
I have my headless Pi setup for SSH and have installed all the necessary libraries for dbus development.
但是,在netbeans中运行程序时,出现以下错误
however, when running the program in netbeans i receive the following error
在X11上没有$ DISPLAY的情况下无法自动启动dbus守护程序
Unable to autolaunch a dbus-daemon without a $DISPLAY for X11
/usr/bin/dbus-launch异常终止,出现以下错误:自动启动错误:X11初始化失败.
/usr/bin/dbus-launch terminated abnormally with the following error: Autolaunch error: X11 initialization failed.
请注意,我在Netbeans的远程主机属性中启用了X11转发
note that i have X11 forwarding enabled in my remote host properties on Netbeans
我可以看到,如果我本人和 回声$ DISPLAY 这将不返回任何内容,为空.
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
没有用.
试图将运行环境变量设置为
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"
没有工作.
尝试
In /etc/ssh/ssh_config
ForwardX11 yes
没有用.
是否需要为X11设置Pi设置或配置netbeans环境以使用某些参数运行程序?
Is it a case of getting my Pi setup for X11 or configuring my netbeans environment to run the program with certain parameters?
预先感谢您的任何建议.
Thank you in advance for any advice.
更新2017年8月30日:
我重新安装了debian,并遵循Gilles的回答:
I did a fresh install of debian and followed Gilles' answer:
https://unix .stackexchange.com/questions/12755/如何远程转发x-over-ssh-to-run-graphics-applications ...
我可以确认:
在/etc/ssh/sshd_config
中
X11Forwarding yes
X11DisplayOffset 10
...
I can confirm:
in /etc/ssh/sshd_config
X11Forwarding yes
X11DisplayOffset 10
...
xauth已安装在远程Pi上.
xauth is installed on the remote Pi.
我已经在客户端Mac上安装了XQuartz.使用ssh -X pi @ IPaddress时,xquartz打开,如果远程Pi上的我echo $DISPLAY
我得到localhost:12.0
...,则数字随每个终端而变化.
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.
当前,如果使用以下方法在netbeans中错误地设置了项目环境:
Currently, if have incorrectly set the project environment in netbeans with:
DISPLAY = localhost:11.0(这是错误的,因为该数字随与远程Pi的每个ssh连接的变化而变化).
DISPLAY=localhost:11.0 (this is wrong because the number changes with each ssh connection to the remote Pi).
因此,当我尝试运行该程序时,NetBeans将挂起,并且我也无法调试.
So when i try to run the program, NetBeans will hang and i cant debug either.
现阶段我的问题是,如何为NetBeans正确设置DISPLAY Environment,以便每次它与远程Pi建立SSH连接并请求X11转发时,它将具有正确的$ DISPLAY?
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?
推荐答案
仅在X11会话下才能自动启动dbus-daemon.否则将其禁用,因为无法让不同的应用程序建立dbus守护程序的通用实例.
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.
如果要独立于X11在pi盒上运行dbus守护程序,则可能应将其配置为在启动时启动dbus守护程序,然后将总线地址导出到 DBUS_SESSION_BUS_ADDRESS环境变量.
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.
有关更多信息,请参见 https://bugs.debian.org /cgi-bin/bugreport.cgi?bug=690530
For more info see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=690530
另一方面,如果您想使用远程X会话,则需要修复配置错误的X11转发,以便在ssh进入Pi时正确设置DISPLAY环境变量.参见例如 https://unix. stackexchange.com/questions/12755/如何远程转发x-over-ssh-to-run-graphics-applications .
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 .
这篇关于如果没有$ DISPLAY的X11,则无法自动启动dbus守护程序. NetBeans. Pi作为远程主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!