Bug 90884

Summary: Trigger happy assert crashes applications
Product: libva Reporter: Francois Gouget <fgouget>
Component: coreAssignee: haihao <haihao.xiang>
Status: RESOLVED FIXED QA Contact: Sean V Kelley <seanvk>
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: Other   
OS: All   
Whiteboard:
i915 platform: i915 features:
Attachments: va/x11: Don't crash the application if it does not have access to the DRI2 device.

Description Francois Gouget 2015-06-06 22:13:20 UTC
After su-ing to another account, any application attempting to use libva crashes with the following message:

$ mplayer big_buck_bunny_480p_h264.mov
[...]
libva info: VA-API version 0.37.0
mplayer: dri2_util.c:199: isDRI2Connected: Assertion `dri_state->base.fd >= 0' failed.

$ gst-launch-1.0 filesrc location=big_buck_bunny_480p_h264.mov ! decodebin ! fakesink
[...]
libva info: VA-API version 0.37.0
gst-launch-1.0: dri2_util.c:199: isDRI2Connected: Assertion `dri_state->base.fd >= 0' failed.


This is because the effective user does not have access to /dev/dri/card0. This may or may not be right, this is not the issue here.

The issue is that libva unilaterally takes it upon itself to crash the application which robs it of the chance of trying to use other libraries. For instance the above GStreamer commands does not need libva at all but it never gets a chance to try to use libav instead.

Assert are meant to verify for properties of the code they are in, not to verify that the environment is set up as the code wants. That's what regular error handling is for, and indeed such code is present just two lines down. So the fix is really simple:

--- va/x11/dri2_util.c.orig   2015-06-06 23:56:15.728190780 +0200
+++ va/x11/dri2_util.c        2015-06-06 23:56:31.928154507 +0200
@@ -196,7 +196,6 @@
         goto err_out;
 
     dri_state->base.fd = open(device_name, O_RDWR);
-    assert(dri_state->base.fd >= 0);
 
     if (dri_state->base.fd < 0)
         goto err_out;
Comment 1 haihao 2015-06-24 08:19:31 UTC
Could you provide a git formatted patch ?
Comment 2 Francois Gouget 2015-07-18 14:55:28 UTC
Created attachment 117233 [details] [review]
va/x11: Don't crash the application if it does not have access to the DRI2 device.

Sorry for the delay, here's a Git-format patch based on the current tip.
Comment 3 haihao 2015-09-29 07:34:50 UTC
Applied, thanks.

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.