EDCD / EDMarketConnector

Downloads commodity market and other station data from the game Elite: Dangerous for use with all popular online and offline trading tools.
GNU General Public License v2.0
992 stars 155 forks source link

Segmentation fault when DISPLAY variable is not set #500

Closed zdenek-crha closed 4 years ago

zdenek-crha commented 4 years ago

Since python2 libaries required by EDMarketConnector are not available anymore in Debian Testing and it is not possible to install them due to dependency conflicts with python3 version, I tried to use chroot with older Debian version installed.

When I run application from chroot with no DISPLAY variable set it crashes with segmentation fault:

$ ./EDMarketConnector.py --help
Segmentation fault

I've investigated a bit and looks like DISPLAY variable is not set in chroot environment. Setting it manually fixes the issue:

$ export DISPLAY=:0.0
$ ./EDMarketConnector.py --help$#
$ ./EDMarketConnector.py --help
loading plugin inara from "/home/user/games/Elite/EDMarketConnector/plugins/inara.py"
loading plugin eddb from "/home/user/games/Elite/EDMarketConnector/plugins/eddb.py"
loading plugin coriolis from "/home/user/games/Elite/EDMarketConnector/plugins/coriolis.py"
loading plugin edsm from "/home/user/games/Elite/EDMarketConnector/plugins/edsm.py"
loading plugin eddn from "/home/user/games/Elite/EDMarketConnector/plugins/eddn.py"
loading plugin edsy from "/home/user/games/Elite/EDMarketConnector/plugins/edsy.py"
... snip log ...

Reproduction

The reproduction scenario uses schroot tool to make it easier to manage access to the chroot and mounting all appropriated directories in there.

# create chroot directory
$ mkdir -p games/Elite
$ cd games/Elite
$ sudo debootstrap buster ~/games/Elite/chroot-edmc
.... snip installation ...

# setup schroot to be able to use new chroot
$ cat > /etc/schroot/chroot.d/edmc <<EOF
[elite-edmc]
type=directory
profile=default
description=Elite Market Connector
directory=/home/user/games/Elite/chroot-edmc/
users=user
groups=user
root-users=root,user
root-groups=root,user
EOF

# install required packages 
$ schroot -c chroot:elite-edmc -u root
$ install python-iniparse python-requests python-tk git
$ exit

# clone EDMarketConnector and attempt to run it
$ schroot -c chroot:elite-edmc -u user
$ cd games/Elite
$ git clone https://github.com/Marginal/EDMarketConnector.git
$ cd EDMarketConnector
$ python  ./EDMarketConnector.py

Notes

pwerken commented 4 years ago

If you don't have X display EDMC is not going to work. Still, it shouldn't just segfault.

Did a bit of digging and found that the segfault happens in theme.py#L88 motif_wm_hints_property = XInternAtom(dpy, b'_MOTIF_WM_HINTS', False) Because $DISPLAY is not set, the line just before it that opens the display returns a null pointer. The returned dpy should be checked to prevent the segfault, something along the lines of:

dpy = xlib.XOpenDisplay(None)
if not dpy: raise Exception('could not connect to display')
Athanasius commented 4 years ago

I'm going pretty much with the fix above, but a slightly different message. This then leads to:

09:34:12 0$ ./EDMarketConnector.py
Traceback (most recent call last):
  File "/home/users/athan/games/elite-dangerous/tools/EDMarketConnector/theme.py", line 89, in <module>
    raise Exception("Can't find your X11/Xorg/Wayland display, can't continue")
Exception: Can't find your display, can't continue
Traceback (most recent call last):
  File "./EDMarketConnector.py", line 909, in <module>
    root = tk.Tk(className=appname.lower())
  File "/usr/lib/python3.7/tkinter/__init__.py", line 2023, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable