LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Can't connect to Xserver (https://www.linuxquestions.org/questions/linux-software-2/cant-connect-to-xserver-936391/)

jlinkels 03-25-2012 08:14 PM

Can't connect to Xserver
 
Hello all,

I am trying to pop up a messagebox in KDE4 from a background process. In order to test this, I have opened a real console (CTRL-ALT-F1) and su-ed to root.

According to ps ax | grep X, X is running on display :0 and VT8:
/usr/bin/X :0 vt8 -br -nolisten tcp -auth /var/run/xauth/A:0-9tDrka

Now my problem is that I can't connect to the X server from a console. This is the error message that I get when entering this command:
export DISPLAY=:0 && kdialog --msgbox "Hello world"
returns:
kdialog: cannot connect to xserver :0

Thinking that this might have to do something with allowed connections, I tried to set xhost:
export DISPLAY=:0 && xhost +localhost
which returns
xhost: unable to open display ":0"

For DISPLAY I tried :0, :1, :0.0, :0.1, :1.0, :1,1, but to no avail.

From a virtual console (pts/0) it is no problem to pop up message boxes.

I am running Debian Squeeze, KDE 4.4.5, kernel 2.6.32-5-amd64

Anyone who has some tips on how to accomplish this, or how to find out which DISPLAY to use?

jlinkels

ukiuki 03-26-2012 04:38 AM

Im not so sure about this but what about:
Code:

export DISPLAY=/usr/bin/X :0 && kdialog --msgbox "Hello world"
or yet(this one might be a bit rough)
Code:

export DISPLAY=/usr/bin/X :0 vt8 -br -nolisten tcp -auth /var/run/xauth/A:0-9tDrka && kdialog --msgbox "Hello world"
:twocents:

Regards

pan64 03-26-2012 06:39 AM

xhost must be executed in a terminal window and after that you can try to access it from your console.
executing xhost in the console will not work (it is not allowed to modify access outside of the X windows)

jlinkels 03-26-2012 11:35 AM

pan64: Something is starting to dawn now.
Console is considered something different than Xterm. Xterm is able to connect to the Xserver, but Console cannot because it is an external connection. So from Xterm the xhost command has to be issued, and then Console should be able to connect?
Let me experiment with that later.

jlinkels

pan64 03-26-2012 11:50 AM

xhost is used to set access control. By default the owner of the xserver (the user who started that session) will be able to modify it. Xterm is started within the session, so there is no problem with it, but when you want to start something from the console....
So you need to switch off access control - that is xhost +, you can execute it in the Xterm window - and than you can make connections from outside.

in the real unix/linux life the X windows system is a client/server pair of applications, the Xserver itself is owned by root, and is usually named X or Xorg. It is only used to draw the content on the display. The client side is called session manager and this is owned by the user. All the applications within a session connect to the session manager, and the manager takes care about the access rights (to itself).

jlinkels 03-26-2012 02:00 PM

Good, thanks for pointing me in the right direction.
What I did is this:
I am logged in into KDE as jlinkels
In Xterm I issued the command xhost +localhost
Then in Console (TTY1), logged in as jlinkels, the kdialog command succeeded.
However, as root it did not. Which is understandable according to the text in your post.
When I tried:
root# su - jlinkels -c "export DISPLAY=:0 && kdialog \"Hello\""
this worked as well.
The script I am writing will be running with root credentials. So by using the su command and specifying this user, I can pop up a dialog for this user. Would that be the correct approach?

jlinkels

eantoranz 03-26-2012 03:10 PM

I don't know if you noticed but the -nolisten tcp option sounds like X won't be listening to anything you want to send it through network, even if it's from localhost.

pan64 03-26-2012 03:27 PM

you would need to read the man page of xhost..http://www.manpagez.com/man/1/xhost/.
xhost +localhost will allow to connect from console or from another x session on the localhost but only for the same user.
xhost +root will allow the user root to connect.
xhost + will completely switch off access control, so anyone can connect from anywhere.

eantoranz 03-26-2012 03:36 PM

I just tried adding xhost +localhost on my computer (runs with -nolisten tcp) and just got kicked out of trying to run one application from a VT (as I expected, as a matter of fact).

jlinkels 03-26-2012 05:19 PM

Quote:

Originally Posted by eantoranz (Post 4636897)
I don't know if you noticed but the -nolisten tcp option sounds like X won't be listening to anything you want to send it through network, even if it's from localhost.

I did see the -nolisten. But:
- I know I am able to connect from other hosts over ssh, using ssh -x, which means there connection possible from the localhost. (I believe ssh -x acts like a tunnel)
- Turning off -nolisten in Debian is one of the best kept secrets in the X environment. Googling yields hundreds of solutions telling (a) to switch this off in /etc/X11/xinit/xserverrc, but this file and directory doesn't exist or (b) grep in /etc/ and subfolders for the string nolisten, which is not found.

Ref. the second paragraph, I would be extremely happy if someone can tell me how to switch off this option so I can experiment with it. It is not funny to see how numerous parrot posters on forums simply repeat (verbatim): "you have to turn off this option by editing xserverrc".

jlinkels

jlinkels 03-26-2012 05:24 PM

Quote:

Originally Posted by pan64 (Post 4636913)
you would need to read the man page of xhost..http://www.manpagez.com/man/1/xhost/.

That might be an idea. :D I did browse thru the man page, but I might have missed a paragraph or two...
Quote:

Originally Posted by pan64 (Post 4636913)
xhost +localhost will allow to connect from console or from another x session on the localhost but only for the same user.
xhost +root will allow the user root to connect.

Let me try that as well.
Quote:

Originally Posted by pan64 (Post 4636913)
xhost + will completely switch off access control, so anyone can connect from anywhere.

Although this network is behind a NATted router and the local network is completely trusted, I don't think that is a good thing to do. Even if it is safe, it is a brute force approach. I think you gave this example as how not to set the permissions, right?

jlinkels

pan64 03-27-2012 12:13 AM

Quote:

Originally Posted by jlinkels (Post 4636996)

Although this network is behind a NATted router and the local network is completely trusted, I don't think that is a good thing to do. Even if it is safe, it is a brute force approach. I think you gave this example as how not to set the permissions, right?

You are right, xhost + is not suggested anyway. But if you want to test if it works you can give it a try. This is the simplest way to check the configuration. xhost - will switch on access control again.

ukiuki 03-27-2012 01:03 AM

Quote:

Originally Posted by jlinkels (Post 4636994)
... /etc/X11/xinit/xserverrc, but this file and directory doesn't exist or ...

Ok that got me because on one of my Debian machines i do have that file, but some others not. I know that because of this post. The package that generates it is xbase-clients.

Regards

jlinkels 03-27-2012 08:08 AM

Quote:

Originally Posted by ukiuki (Post 4637273)
Ok that got me because on one of my Debian machines i do have that file, but some others not. I know that because of this post. The package that generates it is xbase-clients.
Regards

Weird, I am running Squeeze as well. But on none of the machines I originally installed with Squeeze this directory or file is present. On upgraded machines this file is present, and on the sole Lenny machine which I haven't touched for 730 days the file is there as well.

Frankly I despise the Xorg/KDM/KDE policy to hide, move, rename or obsolete configuration files. If the config files are still present and being used they can be in 17 different locations, and on top of that Debian applies its own policy of using or ignoring files. Xorg/KDM/KDE is not the easiest by nature alone, and we could do without additional obfuscation.

jlinkels

OT1: Love to see that configuration in the post you are referring to. I used to sell those machines in 1998 with Win98 installed. Yikes!

OT2: Your statement about Facebook could not be more true! Someday I would expect Facebook to collect all information about my machine, web pages I have visited and whatnot, and then add me to a community: "Hi jlinkels: we thought you might like to know that all these people have visited amazon.com like you did, so we added you to that group. You will receive all mail from those group members, and we carefully have hidden the unsubscribe button"

jlinkels 03-27-2012 08:12 AM

Quote:

Originally Posted by pan64 (Post 4636913)
xhost +root will allow the user root to connect.

No, it doesn't. xhost considers root as a hostname. As I understand if I want to use a name, it should be a nis name. I do have nis running, but root is a local account.

jlinkels


All times are GMT -5. The time now is 03:49 PM.