summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2015-01-22 12:37:16 -0500
committerChris Michael <cp.michael@samsung.com>2015-01-26 08:37:08 -0500
commite6970f4f8b13177c64f7020e26d46a65a527a126 (patch)
treea4e5d68c701fd25bed814c1d41053bd9c2d2169d /src/lib/ecore_drm
parentbee13a55e1edeaa71f124a3b8c2e19e37159070f (diff)
ecore-drm: Cleanup tty code and handle vt signal trapping
Summary: This cleans up the tty code a bit, and makes it the responsibility of the tty code to handle VT switching signals @fix Signed-off-by: Chris Michael <cp.michael@samsung.com>
Diffstat (limited to 'src/lib/ecore_drm')
-rw-r--r--src/lib/ecore_drm/ecore_drm_tty.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/lib/ecore_drm/ecore_drm_tty.c b/src/lib/ecore_drm/ecore_drm_tty.c
index fe338f52fa..f88d9f1278 100644
--- a/src/lib/ecore_drm/ecore_drm_tty.c
+++ b/src/lib/ecore_drm/ecore_drm_tty.c
@@ -1,12 +1,4 @@
1#ifdef HAVE_CONFIG_H
2# include "config.h"
3#endif
4
5#include "ecore_drm_private.h" 1#include "ecore_drm_private.h"
6#include <sys/stat.h>
7#include <sys/ioctl.h>
8#include <linux/vt.h>
9#include <linux/kd.h>
10 2
11#ifndef KDSKBMUTE 3#ifndef KDSKBMUTE
12# define KDSKBMUTE 0x4B51 4# define KDSKBMUTE 0x4B51
@@ -14,6 +6,35 @@
14 6
15static int kbd_mode = 0; 7static int kbd_mode = 0;
16 8
9static Eina_Bool
10_ecore_drm_tty_cb_vt_signal(void *data, int type EINA_UNUSED, void *event)
11{
12 Ecore_Drm_Device *dev;
13 Ecore_Event_Signal_User *ev;
14 siginfo_t sig;
15
16 ev = event;
17 sig = ev->data;
18 if (sig.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
19 if (!(dev = data)) return ECORE_CALLBACK_RENEW;
20
21 switch (ev->number)
22 {
23 case 1:
24 ecore_drm_device_master_drop(dev);
25 ioctl(dev->tty.fd, VT_RELDISP, 1);
26 break;
27 case 2:
28 ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ);
29 ecore_drm_device_master_set(dev);
30 break;
31 default:
32 break;
33 }
34
35 return ECORE_CALLBACK_RENEW;
36}
37
17Eina_Bool 38Eina_Bool
18_ecore_drm_tty_switch(Ecore_Drm_Device *dev, int activate_vt) 39_ecore_drm_tty_switch(Ecore_Drm_Device *dev, int activate_vt)
19{ 40{
@@ -29,7 +50,8 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
29 int kmode; 50 int kmode;
30 struct vt_mode vtmode = { 0 }; 51 struct vt_mode vtmode = { 0 };
31 52
32 if (fstat(dev->tty.fd, &st) == -1) 53 if ((fstat(dev->tty.fd, &st) == -1) ||
54 (major(st.st_rdev) != TTY_MAJOR) || (minor(st.st_rdev) == 0))
33 { 55 {
34 ERR("Failed to get stats for tty: %m"); 56 ERR("Failed to get stats for tty: %m");
35 return EINA_FALSE; 57 return EINA_FALSE;
@@ -41,6 +63,12 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
41 return EINA_FALSE; 63 return EINA_FALSE;
42 } 64 }
43 65
66 if (kmode != KD_TEXT)
67 {
68 WRN("Virtual Terminal already in KD_GRAPHICS mode");
69 return EINA_FALSE;
70 }
71
44 if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0) 72 if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0)
45 { 73 {
46 ERR("Failed to activate vt: %m"); 74 ERR("Failed to activate vt: %m");
@@ -66,13 +94,10 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
66 return EINA_FALSE; 94 return EINA_FALSE;
67 } 95 }
68 96
69 if (kmode != KD_GRAPHICS) 97 if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
70 { 98 {
71 if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS)) 99 ERR("Could not set graphics mode: %m");
72 { 100 goto err_kmode;
73 ERR("Could not set graphics mode: %m");
74 goto err_kmode;
75 }
76 } 101 }
77 102
78 vtmode.mode = VT_PROCESS; 103 vtmode.mode = VT_PROCESS;
@@ -136,7 +161,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
136 { 161 {
137 DBG("Trying to Open Tty: %s", tty); 162 DBG("Trying to Open Tty: %s", tty);
138 163
139 dev->tty.fd = open(tty, O_RDWR | O_NOCTTY); 164 dev->tty.fd = open(tty, (O_RDWR | O_CLOEXEC)); //O_RDWR | O_NOCTTY);
140 if (dev->tty.fd < 0) 165 if (dev->tty.fd < 0)
141 { 166 {
142 DBG("Failed to Open Tty: %m"); 167 DBG("Failed to Open Tty: %m");
@@ -149,7 +174,6 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
149 /* save tty name */ 174 /* save tty name */
150 dev->tty.name = eina_stringshare_add(tty); 175 dev->tty.name = eina_stringshare_add(tty);
151 176
152 /* FIXME */
153 if (!_ecore_drm_tty_setup(dev)) 177 if (!_ecore_drm_tty_setup(dev))
154 { 178 {
155 close(dev->tty.fd); 179 close(dev->tty.fd);
@@ -162,6 +186,10 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
162 return EINA_FALSE; 186 return EINA_FALSE;
163 } 187 }
164 188
189 dev->tty.event_hdlr =
190 ecore_event_handler_add(ECORE_EVENT_SIGNAL_USER,
191 _ecore_drm_tty_cb_vt_signal, dev);
192
165 /* set current tty into env */ 193 /* set current tty into env */
166 setenv("ECORE_DRM_TTY", tty, 1); 194 setenv("ECORE_DRM_TTY", tty, 1);
167 195