Gtk-WARNING **: cannot open display

5,464

'Background' doesn't really change how the program works.

When text-only programs run "in background", they still require something to be attached to 'stdin' (keyboard) and 'stdout' (terminal); they simply get /dev/null in place of an actual terminal.

Similarly, no matter how you run a GTK program, it remains a GTK program – it will always try to connect to an X11 or Wayland server and open its windows there.

Therefore you need some kind of X11 server on the guest. You don't need a full graphical interface, just the X server; and you don't even need Xorg – ideally it should be something that is dedicated to your program, instead of being accessible via console.

Your best option would be to use Xdummy or Xvfb (perhaps using xpra to make configuration simpler). Figure out how to launch one of them in 'background', then make sure your webapp sets the apropriate environment variables – DISPLAY= and XAUTHORITY=.

Even if the guest already has a full graphical interface with Xorg, you still need to tell the program how to access it. It can't just pop up a window somewhere randomly (especially over SSH); it needs the same environment variables to find the guest's Xorg server. (There's a problem though, for the actual graphical interface they will be different after every reboot, so you should still use Xdummy or Xvfb to have a predictable address.)

Share:
5,464

Related videos on Youtube

Sridhar
Author by

Sridhar

Updated on September 18, 2022

Comments

  • Sridhar
    Sridhar over 1 year

    I have centos 6 minimal (headless) as a Host and installed ubuntu 14.04 Desktop as a guest and using KVM.

    There is a web application deployed inside Guest, and it opens and closes one GTK application (javafx) in background.

    I am invoking this web app from my host thru ssh as "curl http://guest/myapp/start" I observed the logs in Guest OS and see the error message "Gtk-WARNING **: cannot open display"

    I didn't understand the reason for this error. 1) This GTK app is not opening any window physically in ssh console on host and moreover it's background. 2) Guest is desktop version.

    Can any one help me how to resolve this. I can't enable XWindows due to security requirements by the client.

    Thanks,

    Sridhar

  • Sridhar
    Sridhar about 9 years
    I am not sure if i have followed you completely. My host is headless and guest is Ubuntu Desktop. Are you suggesting me to use Xdummy or xvfb on CentOS which is host? I am invoking a restful url of the web application in guest from ssh session to Host (centos headless). I pretty new to linux configurations..
  • user1686
    user1686 about 9 years
    The host is completely irrelevant here. Your webapp runs on the guest. It tries to start the GTK app on the same guest.