summaryrefslogtreecommitdiff
path: root/src/lib/ecore_drm/ecore_drm_tty.c
diff options
context:
space:
mode:
authorChris Michael <cp.michael@samsung.com>2014-09-15 15:45:31 -0400
committerChris Michael <cp.michael@samsung.com>2014-09-15 15:45:31 -0400
commit42a97a98c22fd2fa7a43c90d1568b809d8144bf0 (patch)
treefc3526f3633637985e47662d9ced1d0aae4826e2 /src/lib/ecore_drm/ecore_drm_tty.c
parentd91e607dd63da0a0d2a7de832ce1e5455a6fa878 (diff)
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 <cp.michael@samsung.com>
Diffstat (limited to 'src/lib/ecore_drm/ecore_drm_tty.c')
-rw-r--r--src/lib/ecore_drm/ecore_drm_tty.c95
1 files 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 cf19b89c86..c047494311 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)
30 { 30 {
31 vt = (keycode - KEY_F1 + 1); 31 vt = (keycode - KEY_F1 + 1);
32 32
33 /* make a vt #vt active */ 33 if (ioctl(dev->tty.fd, VT_ACTIVATE, vt) < 0)
34 ioctl(dev->tty.fd, VT_ACTIVATE, vt); 34 ERR("Failed to activate vt: %m");
35
36 return ECORE_CALLBACK_DONE;
37 } 35 }
38 36
39 return ECORE_CALLBACK_PASS_ON; 37 return ECORE_CALLBACK_PASS_ON;
@@ -49,9 +47,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, void *event)
49 dev = data; 47 dev = data;
50 ev = event; 48 ev = event;
51 49
52 /* FIXME: this sigdata doesn't have pid or uid info
53 * si_code is single value to get from sigdata
54 */
55 sigdata = ev->data; 50 sigdata = ev->data;
56 if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW; 51 if (sigdata.si_code != SI_KERNEL) return ECORE_CALLBACK_RENEW;
57 52
@@ -62,8 +57,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, void *event)
62 Ecore_Drm_Sprite *sprite; 57 Ecore_Drm_Sprite *sprite;
63 Eina_List *l; 58 Eina_List *l;
64 59
65 DBG("Release VT");
66
67 /* disable inputs (suspends) */ 60 /* disable inputs (suspends) */
68 EINA_LIST_FOREACH(dev->inputs, l, input) 61 EINA_LIST_FOREACH(dev->inputs, l, input)
69 ecore_drm_inputs_disable(input); 62 ecore_drm_inputs_disable(input);
@@ -76,36 +69,25 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, void *event)
76 EINA_LIST_FOREACH(dev->sprites, l, sprite) 69 EINA_LIST_FOREACH(dev->sprites, l, sprite)
77 ecore_drm_sprites_fb_set(sprite, 0, 0); 70 ecore_drm_sprites_fb_set(sprite, 0, 0);
78 71
79 /* close input fds ?? */
80
81 /* drop drm master */ 72 /* drop drm master */
82 if (ecore_drm_device_master_drop(dev)) 73 if (ecore_drm_device_master_drop(dev))
83 { 74 {
84 /* issue ioctl to release vt */ 75 /* issue ioctl to release vt */
85 if (!ecore_drm_tty_release(dev)) 76 if (!ecore_drm_tty_release(dev))
86 ERR("Could not release VT: %m"); 77 ERR("Could not release VT: %m");
87
88 /* remove switch handler */
89 if (dev->tty.switch_hdlr)
90 {
91 ecore_event_handler_del(dev->tty.switch_hdlr);
92 dev->tty.switch_hdlr = NULL;
93 }
94 } 78 }
95 else 79 else
96 ERR("Could not drop drm master: %m"); 80 ERR("Could not drop drm master: %m");
97 } 81 }
98 else if (ev->number == 2) 82 else if (ev->number == 2)
99 { 83 {
100 Ecore_Drm_Output *output;
101 Ecore_Drm_Input *input;
102 Eina_List *l;
103
104 DBG("Acquire VT");
105
106 /* issue ioctl to acquire vt */ 84 /* issue ioctl to acquire vt */
107 if (ecore_drm_tty_acquire(dev)) 85 if (ecore_drm_tty_acquire(dev))
108 { 86 {
87 Ecore_Drm_Output *output;
88 Ecore_Drm_Input *input;
89 Eina_List *l;
90
109 /* set drm master */ 91 /* set drm master */
110 if (!ecore_drm_device_master_set(dev)) 92 if (!ecore_drm_device_master_set(dev))
111 ERR("Could not set drm master: %m"); 93 ERR("Could not set drm master: %m");
@@ -117,12 +99,6 @@ _ecore_drm_tty_cb_signal(void *data, int type EINA_UNUSED, void *event)
117 /* enable inputs */ 99 /* enable inputs */
118 EINA_LIST_FOREACH(dev->inputs, l, input) 100 EINA_LIST_FOREACH(dev->inputs, l, input)
119 ecore_drm_inputs_enable(input); 101 ecore_drm_inputs_enable(input);
120
121 /* listen key event for vt switch */
122 if (!dev->tty.switch_hdlr)
123 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
124 _ecore_drm_tty_cb_vt_switch, dev);
125
126 } 102 }
127 else 103 else
128 ERR("Could not acquire VT: %m"); 104 ERR("Could not acquire VT: %m");
@@ -135,7 +111,7 @@ static Eina_Bool
135_ecore_drm_tty_setup(Ecore_Drm_Device *dev) 111_ecore_drm_tty_setup(Ecore_Drm_Device *dev)
136{ 112{
137 struct stat st; 113 struct stat st;
138 int kb_mode; 114 int kmode;
139 struct vt_mode vtmode = { 0 }; 115 struct vt_mode vtmode = { 0 };
140 116
141 if (fstat(dev->tty.fd, &st) == -1) 117 if (fstat(dev->tty.fd, &st) == -1)
@@ -144,9 +120,21 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
144 return EINA_FALSE; 120 return EINA_FALSE;
145 } 121 }
146 122
147 if (ioctl(dev->tty.fd, KDGKBMODE, &kb_mode)) 123 if (ioctl(dev->tty.fd, KDGETMODE, &kmode))
124 {
125 ERR("Could not get tty mode: %m");
126 return EINA_FALSE;
127 }
128
129 if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0)
130 {
131 ERR("Failed to activate vt: %m");
132 return EINA_FALSE;
133 }
134
135 if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0)
148 { 136 {
149 ERR("Could not get tty keyboard mode: %m"); 137 ERR("Failed to wait active: %m");
150 return EINA_FALSE; 138 return EINA_FALSE;
151 } 139 }
152 140
@@ -158,10 +146,13 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
158 /* return EINA_FALSE; */ 146 /* return EINA_FALSE; */
159 /* } */ 147 /* } */
160 148
161 if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS)) 149 if (kmode != KD_GRAPHICS)
162 { 150 {
163 ERR("Could not set graphics mode: %m"); 151 if (ioctl(dev->tty.fd, KDSETMODE, KD_GRAPHICS))
164 return EINA_FALSE; 152 {
153 ERR("Could not set graphics mode: %m");
154 return EINA_FALSE;
155 }
165 } 156 }
166 157
167 vtmode.mode = VT_PROCESS; 158 vtmode.mode = VT_PROCESS;
@@ -174,18 +165,6 @@ _ecore_drm_tty_setup(Ecore_Drm_Device *dev)
174 return EINA_FALSE; 165 return EINA_FALSE;
175 } 166 }
176 167
177 /* if (ioctl(dev->tty.fd, VT_ACTIVATE, minor(st.st_rdev)) < 0) */
178 /* { */
179 /* ERR("Failed to activate vt: %m"); */
180 /* return EINA_FALSE; */
181 /* } */
182
183 /* if (ioctl(dev->tty.fd, VT_WAITACTIVE, minor(st.st_rdev)) < 0) */
184 /* { */
185 /* ERR("Failed to wait active: %m"); */
186 /* return EINA_FALSE; */
187 /* } */
188
189 return EINA_TRUE; 168 return EINA_TRUE;
190} 169}
191 170
@@ -224,7 +203,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
224 if ((env = getenv("ECORE_DRM_TTY"))) 203 if ((env = getenv("ECORE_DRM_TTY")))
225 snprintf(tty, sizeof(tty), "%s", env); 204 snprintf(tty, sizeof(tty), "%s", env);
226 else 205 else
227 dev->tty.fd = STDIN_FILENO; 206 dev->tty.fd = dup(STDIN_FILENO);
228 } 207 }
229 else // FIXME: NB: This should Really check for format of name (/dev/xyz) 208 else // FIXME: NB: This should Really check for format of name (/dev/xyz)
230 snprintf(tty, sizeof(tty), "%s", name); 209 snprintf(tty, sizeof(tty), "%s", name);
@@ -241,7 +220,7 @@ ecore_drm_tty_open(Ecore_Drm_Device *dev, const char *name)
241 } 220 }
242 } 221 }
243 222
244 DBG("Opened Tty %s : %d", tty, dev->tty.fd); 223 /* DBG("Opened Tty %s : %d", tty, dev->tty.fd); */
245 224
246 /* save tty name */ 225 /* save tty name */
247 dev->tty.name = eina_stringshare_add(tty); 226 dev->tty.name = eina_stringshare_add(tty);
@@ -289,6 +268,10 @@ ecore_drm_tty_close(Ecore_Drm_Device *dev)
289 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr); 268 if (dev->tty.event_hdlr) ecore_event_handler_del(dev->tty.event_hdlr);
290 dev->tty.event_hdlr = NULL; 269 dev->tty.event_hdlr = NULL;
291 270
271 /* destroy the event handler */
272 if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
273 dev->tty.switch_hdlr = NULL;
274
292 /* clear the tty name */ 275 /* clear the tty name */
293 if (dev->tty.name) eina_stringshare_del(dev->tty.name); 276 if (dev->tty.name) eina_stringshare_del(dev->tty.name);
294 dev->tty.name = NULL; 277 dev->tty.name = NULL;
@@ -314,7 +297,11 @@ ecore_drm_tty_release(Ecore_Drm_Device *dev)
314 if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE; 297 if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
315 298
316 /* send ioctl for vt release */ 299 /* send ioctl for vt release */
317 if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0) return EINA_FALSE; 300 if (ioctl(dev->tty.fd, VT_RELDISP, 1) < 0)
301 {
302 ERR("Could not release VT: %m");
303 return EINA_FALSE;
304 }
318 305
319 return EINA_TRUE; 306 return EINA_TRUE;
320} 307}
@@ -335,7 +322,11 @@ ecore_drm_tty_acquire(Ecore_Drm_Device *dev)
335 if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE; 322 if ((!dev) || (!dev->drm.name) || (dev->tty.fd < 0)) return EINA_FALSE;
336 323
337 /* send ioctl for vt acquire */ 324 /* send ioctl for vt acquire */
338 if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0) return EINA_FALSE; 325 if (ioctl(dev->tty.fd, VT_RELDISP, VT_ACKACQ) < 0)
326 {
327 ERR("Could not acquire VT: %m");
328 return EINA_FALSE;
329 }
339 330
340 return EINA_TRUE; 331 return EINA_TRUE;
341} 332}