We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2446

Summary: Issue sudo with SDL - with or without X11 - Error while initializing SDL: No available video device
Product: SDL Reporter: Luis R. Rodriguez <mcgrof>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED WONTFIX QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.2   
Hardware: x86_64   
OS: Linux   
Attachments: SDL sudo X11 example issue

Description Luis R. Rodriguez 2014-03-11 20:53:51 UTC
Created attachment 1592 [details]
SDL sudo X11 example issue

There is what seems to be a known issue when running SDL on Linux with something like sudo. Some folks work around this with by setting the display but this doesn't work at all times. Some other programs have a work around and set the driver environment variable to X11, but this also doesn't work at all times. Since SDL is the preferred environment for some environments, in particular xen for when spawning its guest interfaces it'd be nice to see this fixed.

I've narrowed down the issue into an simple example program which can be tested as a regular user and then with sudo. This issue was tested with a rolling Linux distribution release, OpenSuse Tumbleweed, and it has these libraries installed:

libSDL2-2_0-0-2.0.0-2.1.1.x86_64
libSDL-1_2-0-1.2.15-10.4.1.x86_64

libSDL2-devel-2.0.0-2.1.1.x86_64
libSDL-devel-1.2.15-10.4.1.x86_64

I've attached the example program sdl.c and an example Makefile which can be used. Alternatively you can download this from:

http://drvbp1.linux-foundation.org/~mcgrof/examples/2014/11/qemu-x11-sdl-issue/

As a regular user you see no issues (note: this will full screen,               
and its not easy to recover):                                                   
                                                                                
        ./sdl1                                                                  
        ./sdl2                                                                  
                                                                                
You can trigger the same observed issue as seen on xen when creating            
a guest with 'xl create /etc/xen/foo.hvm' by running this program as            
root as well:                                                                   
                                                                                
        sudo ./sdl2                                                             
        sudo ./sdl2                                                             
                                                                                
This will fail on Linux with:                                                   
                                                                                
Error while initializing SDL:  No available video device                        
                                                                                
To account for this upstream qemu/ui/sdl.c sets the default video               
driver to x11 with:                                                             
                                                                                
setenv("SDL_VIDEODRIVER", "x11", 0);                                            
                                                 
                                                                                
/* on Linux, SDL may use fbcon|directfb|svgalib when run without                
 * accessible $DISPLAY to open X11 window.  This is often the case              
 * when qemu is run using sudo.  But in this case, and when actually            
 * run in X11 environment, SDL fights with X11 for the video card,              
 * making current display unavailable, often until reboot.                      
 * So make x11 the default SDL video driver if this variable is unset.          
 * This is a bit hackish but saves us from bigger problem.                      
 * Maybe it's a good idea to fix this in SDL instead.                           
 */   

My hope is if we can fix this upstream on SDL we can do so and if not then figure out what is required for good.
Comment 1 Sam Lantinga 2014-04-18 06:23:41 UTC
What fix do you suggest? If you don't have access to the X11 display and you force the X11 driver, wouldn't failing to initialize be the natural result?

SDL 2.0 no longer has svgalib or fbcon backends which would conflict with X11.
Comment 2 Sam Lantinga 2017-08-14 20:19:42 UTC
No response, closing this bug.

Please feel free to reopen it if you have suggestions on how to fix it.