Opened 15 years ago

Closed 15 years ago

#2865 closed defect (fixed)

Calling mythfrontend with option -display results in segmentation fault

Reported by: m.brekhof@… Owned by: danielk
Priority: minor Milestone: unknown
Component: mythtv Version: 0.20
Severity: medium Keywords:
Cc: Ticket locked: no


Running mythfrontend (0.20) with commandline argument -display :0 from a virtual console results in a segmentation fault right after it fails to open the display checking for xinerama support with the function GetNumberOfXineramaScreens? in the file: mythtv-0.20/libs/libmyth/util-x11.cpp.

Problem is calling the Xinerama function XineramaQueryExtension? in the file libs/libmyth/util-x11.cpp with a Display structure that is non-existing. Through numerous other functions in Xorg (version 7.1) the call finally segfaults in the Xlib function XQueryExtension when it tries to lock the display.

I have fixed the segmentation fault by checking if the structure is not NULL before calling XQueryExtension. The fix is included as a patch attached to this bugreport.

Although the fix results in a working system I am not sure if this is the correct fix. The problem occurs when calling mythfrontend with the display option (e.g. -display :1) and X is not available on the current display (i.e. executing mythfrontend from a virtual console). The reason that this results in a segfault is that before the commandline arguments are parsed in the main function of mythfrontend (programs/mythfrontend/main.cpp) GetNumberOfXineramaScreens?() gets called through the init() method of class MythContext (main.cpp line 797) which calls the Init() method of the class MythContextPrivate? which calls GetScreenBounds?() (mythcontext.cpp line 441) which finally calls GetNumberOfXineramaScreens?(). Hence, the first time MythXOpenDisplay() is called it tries to open a display that does not exist. The second time (ofcourse only possible after the patch has been applied) MythXOpenDisplay() gets called, the commandline arguments have been parsed and the correct display is opened which succeeds. Now I believe the real problem is that the display settings are set through gContext->SetX11Display() (main.cpp line 1057) which however requires gContext to be initialized first. I figure that the egg should come before the chicken but then again I'm not sure (Chicken-and-egg_problem).

Output mythfrontend:

bash-3.1# mythfrontend -display :0
Qt: Locales not supported on X server
2005-03-04 23:03:10.583 Using runtime prefix = /usr
2005-03-04 23:03:10.615 DPMS is disabled.
2005-03-04 23:03:10.708 New DB connection, total: 1
2005-03-04 23:03:10.759 Connected to database 'mythconverg' at host:
2005-03-04 23:03:10.764 Total desktop dim: 640x480, with 1 screen[s].
2005-03-04 23:03:10.765 MythXOpenDisplay() failed
Segmentation fault (core dumped)

GDB output:

(gdb) run -display :0
Starting program: /usr/bin/mythfrontend -display :0
[Thread debugging using libthread_db enabled]
[New Thread -1241478656 (LWP 837)]
Qt: Locales not supported on X server
2005-03-04 22:44:49.047 Using runtime prefix = /usr
2005-03-04 22:44:49.077 DPMS is disabled.
2005-03-04 22:44:49.161 New DB connection, total: 1
2005-03-04 22:44:49.629 Connected to database 'mythconverg' at host:
2005-03-04 22:44:49.634 Total desktop dim: 640x480, with 1 screen[s].
2005-03-04 22:44:49.636 MythXOpenDisplay() failed

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1241478656 (LWP 837)]
0xb63d316a in XQueryExtension () from /usr/lib/
(gdb) quit

Output GDB logging (gdb.txt):

bash-3.1# more gdb.txt
[Thread debugging using libthread_db enabled]
[New Thread -1240692224 (LWP 834)]

Program exited with code 01.
Current language: auto; currently c

Attachments (1)

patch.txt (888 bytes) - added by m.brekhof@… 15 years ago.

Download all attachments as: .zip

Change History (4)

Changed 15 years ago by m.brekhof@…

Attachment: patch.txt added

comment:1 Changed 15 years ago by danielk

Owner: changed from Isaac Richards to danielk

comment:2 Changed 15 years ago by Nigel

The patch looks correct (although I would shorten to just if (!d) return 0; ), but I have been unable to reproduce the fault. e.g. on an ssh into a working setup:

$ mythfrontend -display :4
mythfrontend: cannot connect to X server :4
$ mythfrontend --version  
mythfrontend: cannot connect to X server 

or after Ctrl-Alt-F1 on the same machine:

$ mythfrontend -display :0
Xlib: connection to ":0.0" refused by server
Xlib: No protocol specified

mythfrontend: cannot connect to X server :0

This was with something slightly newer than 0.20, but nothing much seems to have changed in the X chicken-and-egg startup.
Note also that -display and --display behave slightly differently. One uses Qt first, one doesn't

comment:3 Changed 15 years ago by danielk

Resolution: fixed
Status: newclosed

(In [12485]) Fixes #2865. Fixes SEGFAULT when -display used without another valid display in DISPLAY env variable.

Unfortunately this requires a MYTH_BINARY_VERSION change so you must recompile & install the plugins after installing the update mythtv libraries.

The problem was that we attempted to open the display before we had parsed and/or set the MythContext's X11 display string. This meant that at best we opened the wrong display when detecting the screen settings the first time, and at worst we segfaulted if the DISPLAY environment variable wasn't set to a valid X11 server.

Note: See TracTickets for help on using tickets.