elput: Fix multiple open/close of drm devices
authorDerek Foreman <derekf@osg.samsung.com>
Mon, 24 Jul 2017 21:03:10 +0000 (16:03 -0500)
committerDerek Foreman <derekf@osg.samsung.com>
Mon, 24 Jul 2017 21:06:52 +0000 (16:06 -0500)
When I added the code to probe drm devices to ensure they're
modeset capable (ref 414d406b3b442216543cdaef112787696ae09898)
I didn't realize elput didn't allow us to open and close more than
one drm device at startup without blowing up libinput.

This is a somewhat dirty hack to rough that in.

The problem is that open/close the device during startup will
result in an async "gone" callback from logind, which then kicks
off an input shutdown.  We need to try harder to only do that
shutdown when it makes sense.

src/lib/elput/elput_logind.c
src/lib/elput/elput_private.h

index aa9006e..91eaffc 100644 (file)
@@ -84,6 +84,7 @@ _cb_device_paused(void *data, const Eldbus_Message *msg)
    uint32_t maj, min;
 
    em = data;
+   if (!em->drm_opens) return;
 
    if (eldbus_message_error_get(msg, &errname, &errmsg))
      {
@@ -93,6 +94,20 @@ _cb_device_paused(void *data, const Eldbus_Message *msg)
 
    if (eldbus_message_arguments_get(msg, "uus", &maj, &min, &type))
      {
+        /* If we opened a device during probing then we're still going
+         * to get a "gone" callback when we release it, so we'd better
+         * eat that instead of treating it like losing the drm device
+         * we currently have open, and crapping up libinput's internals
+         * for a nice deferred explosion at shutdown...
+         *
+         * FIXME: do this better?
+         */
+        if ((em->drm_opens > 1) && (maj == 226) && !strcmp(type, "gone"))
+          {
+             em->drm_opens--;
+             return;
+          }
+
         if (!strcmp(type, "pause"))
           _logind_device_pause_complete(em, maj, min);
 
@@ -607,6 +622,9 @@ _logind_open(Elput_Manager *em, const char *path, int flags)
    fd = _logind_device_take(em, major(st.st_rdev), minor(st.st_rdev));
    if (fd < 0) return fd;
 
+   if (major(st.st_rdev) == 226) //DRM_MAJOR
+     em->drm_opens++;
+
    fl = fcntl(fd, F_GETFL);
    if (fl < 0) goto err;
 
index 5b38c14..709871c 100644 (file)
@@ -279,6 +279,8 @@ struct _Elput_Manager
      } cached;
    int output_w, output_h;
 
+   int drm_opens;
+
    Elput_Input input;
    Eina_Bool del : 1;
 };