2016-03-09 05:22:22 -08:00
|
|
|
/* Portions of this code have been derived from Weston
|
|
|
|
*
|
|
|
|
* Copyright © 2008-2012 Kristian Høgsberg
|
|
|
|
* Copyright © 2010-2012 Intel Corporation
|
|
|
|
* Copyright © 2010-2011 Benjamin Franzke
|
|
|
|
* Copyright © 2011-2012 Collabora, Ltd.
|
|
|
|
* Copyright © 2010 Red Hat <mjg@redhat.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
* Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2014-12-09 06:36:42 -08:00
|
|
|
#include "ecore_drm_private.h"
|
|
|
|
|
|
|
|
static Eina_Bool logind = EINA_FALSE;
|
|
|
|
|
2020-06-20 02:43:56 -07:00
|
|
|
static Eina_Bool
|
2015-01-05 06:08:27 -08:00
|
|
|
_ecore_drm_launcher_cb_vt_switch(void *data, int type EINA_UNUSED, void *event)
|
|
|
|
{
|
|
|
|
Ecore_Drm_Device *dev;
|
|
|
|
Ecore_Event_Key *ev;
|
|
|
|
int keycode;
|
|
|
|
int vt;
|
|
|
|
|
|
|
|
dev = data;
|
|
|
|
ev = event;
|
|
|
|
keycode = ev->keycode - 8;
|
|
|
|
|
|
|
|
if ((ev->modifiers & ECORE_EVENT_MODIFIER_CTRL) &&
|
|
|
|
(ev->modifiers & ECORE_EVENT_MODIFIER_ALT) &&
|
|
|
|
(keycode >= KEY_F1) && (keycode <= KEY_F8))
|
|
|
|
{
|
|
|
|
vt = (keycode - KEY_F1 + 1);
|
|
|
|
|
|
|
|
if (!_ecore_drm_tty_switch(dev, vt))
|
2016-01-14 10:05:55 -08:00
|
|
|
ERR("Failed to activate vt");
|
2015-01-05 06:08:27 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ECORE_CALLBACK_PASS_ON;
|
|
|
|
}
|
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
int
|
|
|
|
_ecore_drm_launcher_device_flags_set(int fd, int flags)
|
2015-01-05 06:08:27 -08:00
|
|
|
{
|
2015-01-22 09:40:32 -08:00
|
|
|
int fl;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
fl = fcntl(fd, F_GETFL);
|
|
|
|
if (fl < 0) return -1;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
if (flags & O_NONBLOCK)
|
|
|
|
fl |= O_NONBLOCK;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
if (fcntl(fd, F_SETFL, fl) < 0)
|
|
|
|
return -1;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
fl = fcntl(fd, F_GETFD);
|
|
|
|
if (fl < 0) return -1;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
if (!(flags & O_CLOEXEC))
|
|
|
|
fl &= ~FD_CLOEXEC;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
if (fcntl(fd, F_SETFD, fl) < 0)
|
|
|
|
return -1;
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
return fd;
|
2015-01-05 06:08:27 -08:00
|
|
|
}
|
|
|
|
|
2020-10-15 11:48:08 -07:00
|
|
|
ECORE_DRM_API Eina_Bool
|
2014-12-09 06:36:42 -08:00
|
|
|
ecore_drm_launcher_connect(Ecore_Drm_Device *dev)
|
|
|
|
{
|
2015-04-24 09:51:34 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(dev, EINA_FALSE);
|
2016-01-21 08:35:45 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
/* try to connect to logind */
|
2014-12-09 06:36:42 -08:00
|
|
|
if (!(logind = _ecore_drm_logind_connect(dev)))
|
|
|
|
{
|
2015-01-22 09:40:32 -08:00
|
|
|
DBG("Launcher: Logind not supported");
|
2014-12-09 06:36:42 -08:00
|
|
|
if (geteuid() == 0)
|
2015-01-22 09:40:32 -08:00
|
|
|
{
|
|
|
|
DBG("Launcher: Trying to continue with root privileges");
|
|
|
|
if (!ecore_drm_tty_open(dev, NULL))
|
|
|
|
{
|
|
|
|
ERR("Launcher: Could not setup tty");
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-09 06:36:42 -08:00
|
|
|
else
|
|
|
|
{
|
2015-01-22 09:40:32 -08:00
|
|
|
ERR("Launcher: Root privileges needed");
|
2014-12-09 06:36:42 -08:00
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
}
|
2015-01-05 06:08:27 -08:00
|
|
|
|
2020-06-20 02:43:56 -07:00
|
|
|
dev->tty.switch_hdlr =
|
|
|
|
ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
|
2015-01-22 09:40:32 -08:00
|
|
|
_ecore_drm_launcher_cb_vt_switch, dev);
|
2014-12-09 06:36:42 -08:00
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
2020-10-15 11:48:08 -07:00
|
|
|
ECORE_DRM_API void
|
2014-12-09 06:36:42 -08:00
|
|
|
ecore_drm_launcher_disconnect(Ecore_Drm_Device *dev)
|
|
|
|
{
|
2015-04-24 09:51:34 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(dev);
|
2016-01-21 06:22:37 -08:00
|
|
|
|
2015-01-05 06:08:27 -08:00
|
|
|
if (dev->tty.switch_hdlr) ecore_event_handler_del(dev->tty.switch_hdlr);
|
|
|
|
dev->tty.switch_hdlr = NULL;
|
2015-01-06 08:12:54 -08:00
|
|
|
|
2015-01-22 09:40:32 -08:00
|
|
|
if (!logind)
|
|
|
|
{
|
|
|
|
if (!ecore_drm_tty_close(dev))
|
|
|
|
ERR("Launcher: Could not close tty");
|
|
|
|
}
|
|
|
|
else
|
2015-01-06 08:12:54 -08:00
|
|
|
{
|
|
|
|
_ecore_drm_logind_disconnect(dev);
|
|
|
|
}
|
2014-12-09 06:36:42 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
_ecore_drm_launcher_device_open(const char *device, Ecore_Drm_Open_Cb callback, void *data, int flags)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (logind)
|
|
|
|
{
|
|
|
|
if (!_ecore_drm_logind_device_open(device, callback, data))
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fd = open(device, flags | O_CLOEXEC);
|
|
|
|
if (fd < 0) return EINA_FALSE;
|
|
|
|
if (fstat(fd, &s) == -1)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
return EINA_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(data, fd, EINA_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
_ecore_drm_launcher_device_open_no_pending(const char *device, int flags)
|
|
|
|
{
|
|
|
|
int fd = -1;
|
|
|
|
struct stat s;
|
|
|
|
|
|
|
|
if (logind)
|
|
|
|
{
|
|
|
|
fd = _ecore_drm_logind_device_open_no_pending(device);
|
2015-04-30 11:27:04 -07:00
|
|
|
if (fd < 0) return -1;
|
2015-04-30 11:28:30 -07:00
|
|
|
if (_ecore_drm_launcher_device_flags_set(fd, flags | O_CLOEXEC) < 0)
|
2014-12-09 06:36:42 -08:00
|
|
|
{
|
2015-04-30 11:27:04 -07:00
|
|
|
close(fd);
|
2014-12-09 06:36:42 -08:00
|
|
|
_ecore_drm_logind_device_close(device);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-10 05:04:32 -08:00
|
|
|
fd = open(device, flags | O_CLOEXEC);
|
2014-12-09 06:36:42 -08:00
|
|
|
if (fd < 0) return fd;
|
|
|
|
if (fstat(fd, &s) == -1)
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return fd;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_drm_launcher_device_close(const char *device, int fd)
|
|
|
|
{
|
2015-04-30 11:31:07 -07:00
|
|
|
if ((logind) && (device)) _ecore_drm_logind_device_close(device);
|
2014-12-09 06:36:42 -08:00
|
|
|
|
ecore-drm: Fix failure of setting/closing evdev->fd which causes fd leak
Summary:
When a input device is plugged in, _cb_open_restricted() is called before creating evdev.
So setting fd value on evdev was failed in _cb_open_restricted() and also closing evdev->fd was invalid.
Using a eina_hash which has 'path-fd' pairs, we can find fd value after evdev is created.
@fix
Test Plan:
(1) Multiple input devices are connected. Their evdev->fd remains zero or initial value.
(2) When one of those devices are plugged out, fd leak would happen.
Reviewers: raster, zmike, gwanglim, stefan_schmidt, devilhorns, ManMower
Subscribers: cedric, jpeg, Jeon, input.hacker
Differential Revision: https://phab.enlightenment.org/D3428
2015-12-15 07:02:49 -08:00
|
|
|
if (fd < 0) return;
|
2014-12-09 06:36:42 -08:00
|
|
|
close(fd);
|
|
|
|
}
|