devilhorns pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=42a97a98c22fd2fa7a43c90d1568b809d8144bf0

commit 42a97a98c22fd2fa7a43c90d1568b809d8144bf0
Author: Chris Michael <[email protected]>
Date:   Mon Sep 15 15:45:31 2014 -0400

    ecore-drm: Fix drm VT switching to work again
    
    This commit fixes VT switching in the ecore_drm library code to work
    again. Previously we were not dup'ing the stdin fd which lead to
    inappropriate ioctls for that fd. Fix that by adding the missing dup
    call. This also adds more error messages during ioctl function calls,
    and cleans up the switching handler code (for keyboard events).
    
    @fix
    
    Signed-off-by: Chris Michael <[email protected]>
---
 src/lib/ecore_drm/ecore_drm_tty.c | 95 ++++++++++++++++++---------------------
 1 file changed, 43 insertions(+), 52 deletions(-)

diff --git a/src/lib/ecore_drm/ecore_drm_tty.c 
b/src/lib/ecore_drm/ecore_drm_tty.c
index cf19b89..c047494 100644
--- a/src/lib/ecore_drm/ecore_drm_tty.c
+++ b/src/lib/ecore_drm/ecore_drm_tty.c
@@ -30,10 +30,8 @@ _ecore_drm_tty_cb_vt_switch(void *data, int type 
EINA_UNUSED, void *event)
      {
         vt = (keycode - KEY_F1 + 1);
 
-        /* make a vt #vt active */
-        ioctl(dev->tty.fd, VT_ACTIVATE, vt);
-
-        return ECORE_CALLBACK_DONE;
+        if (ioctl(dev->tty.fd, VT_ACTIVATE, vt) < 0)
+          ERR("Failed to activate vt: %m");
      }
 
    return ECORE_CALLBACK_PASS_ON;
@@ -49,9 +47,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, 
void *event)
    dev = data;
    ev = event;
 
-   /* FIXME: this sigdata doesn't have pid or uid info
-    * si_code is single value to get from sigdata
-    */
    sigdata = ev->data;
    if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
 
@@ -62,8 +57,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, 
void *event)
         Ecore_Drm_Sprite *sprite;
         Eina_List *l;
 
-        DBG("Release VT");
-
         /* disable inputs (suspends) */
         EINA_LIST_FOREACH(dev->inputs, l, input)
           ecore_drm_inputs_disable(input);
@@ -76,36 +69,25 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, 
void *event)
         EINA_LIST_FOREACH(dev->sprites, l, sprite)
           ecore_drm_sprites_fb_set(sprite, 0, 0);
 
-        /* close input fds ?? */
-
         /* drop drm master */
         if (ecore_drm_device_master_drop(dev))
           {
              /* issue ioctl to release vt */
              if (!ecore_drm_tty_release(dev))
                ERR("Could not release VT: %m");
-
-             /* remove switch handler */
-             if (dev->tty.switch_hdlr)
-               {
-                  ecore_event_handler_del(dev->tty.switch_hdlr);
-                  dev->tty.switch_hdlr = NULL;
-               }
           }
         else
           ERR("Could not drop drm master: %m");
      }
    else if (ev->number == 2)
      {
-        Ecore_Drm_Output *output;
-        Ecore_Drm_Input *input;
-        Eina_List *l;
-
-        DBG("Acquire VT");
-
         /* issue ioctl to acquire vt */
         if (ecore_drm_tty_acquire(dev))
           {
+             Ecore_Drm_Output *output;
+             Ecore_Drm_Input *input;
+             Eina_List *l;
+
              /* set drm master */
              if (!ecore_drm_device_master_set(dev))
                ERR("Could not set drm master: %m");
@@ -117,12 +99,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, 
void *event)
              /* enable inputs */
              EINA_LIST_FOREACH(dev->inputs, l, input)
                ecore_drm_inputs_enable(input);
-
-             /* listen key event for vt switch */
-             if (!dev->tty.switch_hdlr)
-               ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
-                                       _ecore_drm_tty_cb_vt_switch, dev);
-
           }
         else
           ERR("Could not acquire VT: %m");
@@ -135,7 +111,7 @@ static Eina_Bool
 _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
 {
    struct stat st;
-   int kb_mode;
+   int kmode;
    struct vt_mode vtmode = { 0 };
 
    if (fstat(dev->tty.fd, &st) == -1)
@@ -144,9 +120,21 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
         return EINA_FALSE;
      }
 
-   if (ioctl(dev->tty.fd, KDGKBMODE, &kb_mode))
+   if (ioctl(dev->tty.fd, KDGETMODE, &kmode))
+     {
+        ERR("Could not get tty mode: %m");
+        return EINA_FALSE;
+     }
+
+   if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0)
+     {
+        ERR("Failed to activate vt: %m");
+        return EINA_FALSE;
+     }
+
+   if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0)
      {
-        ERR("Could not get tty keyboard mode: %m");
+        ERR("Failed to wait active: %m");
         return EINA_FALSE;
      }
 
@@ -158,10 +146,13 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
    /*      return EINA_FALSE; */
    /*   } */
 
-   if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
+   if (kmode != KD_GRAPHICS)
      {
-        ERR("Could not set graphics mode: %m");
-        return EINA_FALSE;
+        if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
+          {
+             ERR("Could not set graphics mode: %m");
+             return EINA_FALSE;
+          }
      }
 
    vtmode.mode = VT_PROCESS;
@@ -174,18 +165,6 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
         return EINA_FALSE;
      }
 
-   /* if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0) */
-   /*   { */
-   /*      ERR("Failed to activate vt: %m"); */
-   /*      return EINA_FALSE; */
-   /*   } */
-
-   /* if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0) */
-   /*   { */
-   /*      ERR("Failed to wait active: %m"); */
-   /*      return EINA_FALSE; */
-   /*   } */
-
    return EINA_TRUE;
 }
 
@@ -224,7 +203,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
         if ((env = getenv("ECORE_DRM_TTY")))
           snprintf(tty, sizeof(tty), "%s", env);
         else
-          dev->tty.fd = STDIN_FILENO;
+          dev->tty.fd = dup(STDIN_FILENO);
      }
    else // FIXME: NB: This should Really check for format of name (/dev/xyz)
      snprintf(tty, sizeof(tty), "%s", name);
@@ -241,7 +220,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
           }
      }
 
-   DBG("Opened Tty %s : %d", tty, dev->tty.fd);
+   /* DBG("Opened Tty %s : %d", tty, dev->tty.fd); */
 
    /* save tty name */
    dev->tty.name = eina_stringshare_add(tty);
@@ -289,6 +268,10 @@ ecore_drm_tty_close(Ecore_Drm_Device *dev)
    if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
    dev->tty.event_hdlr = NULL;
 
+   /* destroy the event handler */
+   if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
+   dev->tty.switch_hdlr = NULL;
+
    /* clear the tty name */
    if (dev->tty.name) eina_stringshare_del(dev->tty.name);
    dev->tty.name = NULL;
@@ -314,7 +297,11 @@ ecore_drm_tty_release(Ecore_Drm_Device *dev)
    if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
 
    /* send ioctl for vt release */
-   if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0) return EINA_FALSE;
+   if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0) 
+     {
+        ERR("Could not release VT: %m");
+        return EINA_FALSE;
+     }
 
    return EINA_TRUE;
 }
@@ -335,7 +322,11 @@ ecore_drm_tty_acquire(Ecore_Drm_Device *dev)
    if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
 
    /* send ioctl for vt acquire */
-   if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0) return EINA_FALSE;
+   if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0) 
+     {
+        ERR("Could not acquire VT: %m");
+        return EINA_FALSE;
+     }
 
    return EINA_TRUE;
 }

-- 


Reply via email to