st/xa: Don't close the drm fd on failure v2
authorThomas Hellstrom <thellstrom@vmware.com>
Thu, 3 Jul 2014 09:07:36 +0000 (02:07 -0700)
committerThomas Hellstrom <thellstrom@vmware.com>
Thu, 3 Jul 2014 09:55:00 +0000 (02:55 -0700)
If XA fails to initialize with pipe_loader enabled, the pipe_loader's
cleanup function will close the drm file descriptor. That's pretty bad
because the file descriptor will probably be the X server driver's only
connection to drm. Temporarily solve this by dup()'ing the file descriptor
before handing it over to the pipe loader.

This fixes freedesktop.org bugzilla bug #80645.

v2: Fix CC addresses.

Cc: "10.2" <mesa-stable@lists.freedesktop.org>
Signed-off-by: Thomas Hellstrom <thellstrom@vmware.com>
Reviewed-by: Jakob Bornecrantz <jakob@vmware.com>
src/gallium/state_trackers/xa/xa_tracker.c

index 6e4312e0079b2b064fbd5d3a16f5329f193dd48b..268d56b0a16d53c609343b1e1250e7f5a61bb5cd 100644 (file)
@@ -26,6 +26,7 @@
  * Thomas Hellstrom <thellstrom-at-vmware-dot-com>
  */
 
+#include <unistd.h>
 #include "xa_tracker.h"
 #include "xa_priv.h"
 #include "pipe/p_state.h"
@@ -140,6 +141,7 @@ xa_tracker_create(int drm_fd)
     struct xa_tracker *xa = calloc(1, sizeof(struct xa_tracker));
     enum xa_surface_type stype;
     unsigned int num_formats;
+    int loader_fd;
 
     if (!xa)
        return NULL;
@@ -147,7 +149,10 @@ xa_tracker_create(int drm_fd)
 #if GALLIUM_STATIC_TARGETS
     xa->screen = dd_create_screen(drm_fd);
 #else
-    if (pipe_loader_drm_probe_fd(&xa->dev, drm_fd, false))
+    loader_fd = dup(drm_fd);
+    if (loader_fd == -1)
+        return NULL;
+    if (pipe_loader_drm_probe_fd(&xa->dev, loader_fd, false))
        xa->screen = pipe_loader_create_screen(xa->dev, PIPE_SEARCH_DIR);
 #endif
     if (!xa->screen)