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-03-06 01:43:48 -08:00
|
|
|
#include "ecore_drm_private.h"
|
|
|
|
|
|
|
|
/* local variables */
|
|
|
|
static int _ecore_drm_init_count = 0;
|
|
|
|
|
|
|
|
/* external variables */
|
|
|
|
int _ecore_drm_log_dom = -1;
|
|
|
|
|
2014-12-10 09:12:21 -08:00
|
|
|
EAPI int ECORE_DRM_EVENT_ACTIVATE = 0;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ecore_drm_event_activate_free(void *data EINA_UNUSED, void *event)
|
|
|
|
{
|
|
|
|
free(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ecore_drm_event_activate_send(Eina_Bool active)
|
|
|
|
{
|
|
|
|
Ecore_Drm_Event_Activate *e;
|
|
|
|
|
2014-12-10 09:13:33 -08:00
|
|
|
if (!(e = calloc(1, sizeof(Ecore_Drm_Event_Activate)))) return;
|
|
|
|
|
2014-12-10 09:12:21 -08:00
|
|
|
e->active = active;
|
2014-12-10 09:13:33 -08:00
|
|
|
ecore_event_add(ECORE_DRM_EVENT_ACTIVATE, e,
|
|
|
|
_ecore_drm_event_activate_free, NULL);
|
2014-12-10 09:12:21 -08:00
|
|
|
}
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/**
|
|
|
|
* @defgroup Ecore_Drm_Init_Group Drm Library Init and Shutdown Functions
|
|
|
|
*
|
|
|
|
* Functions that start and shutdown the Ecore_Drm Library.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize the Ecore_Drm library
|
|
|
|
*
|
|
|
|
* @return The number of times the library has been initialized without
|
|
|
|
* being shut down. 0 is returned if an error occurs.
|
|
|
|
*
|
|
|
|
* @ingroup Ecore_Drm_Init_Group
|
|
|
|
*/
|
|
|
|
EAPI int
|
|
|
|
ecore_drm_init(void)
|
|
|
|
{
|
|
|
|
/* if we have already initialized, return the count */
|
|
|
|
if (++_ecore_drm_init_count != 1) return _ecore_drm_init_count;
|
|
|
|
|
|
|
|
/* try to init eina */
|
|
|
|
if (!eina_init()) return --_ecore_drm_init_count;
|
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* try to init ecore */
|
2014-03-06 01:43:48 -08:00
|
|
|
if (!ecore_init())
|
|
|
|
{
|
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* try to init ecore_event */
|
|
|
|
if (!ecore_event_init())
|
|
|
|
{
|
|
|
|
ecore_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* set logging level */
|
2016-03-09 12:24:24 -08:00
|
|
|
/* eina_log_level_set(EINA_LOG_LEVEL_DBG); */
|
2014-03-06 01:43:48 -08:00
|
|
|
|
|
|
|
/* try to create logging domain */
|
|
|
|
_ecore_drm_log_dom =
|
|
|
|
eina_log_domain_register("ecore_drm", ECORE_DRM_DEFAULT_LOG_COLOR);
|
|
|
|
if (!_ecore_drm_log_dom)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not create log domain for Ecore_Drm");
|
|
|
|
goto log_err;
|
|
|
|
}
|
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
/* try to init eeze */
|
|
|
|
if (!eeze_init()) goto eeze_err;
|
2014-03-06 01:43:48 -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
|
|
|
_ecore_drm_inputs_init();
|
|
|
|
|
2014-12-10 09:12:21 -08:00
|
|
|
ECORE_DRM_EVENT_ACTIVATE = ecore_event_type_new();
|
2015-02-19 11:47:34 -08:00
|
|
|
ECORE_DRM_EVENT_OUTPUT = ecore_event_type_new();
|
2015-03-24 07:45:11 -07:00
|
|
|
ECORE_DRM_EVENT_SEAT_ADD = ecore_event_type_new();
|
2014-12-10 09:12:21 -08:00
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* return init count */
|
|
|
|
return _ecore_drm_init_count;
|
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
eeze_err:
|
2014-03-06 01:43:48 -08:00
|
|
|
eina_log_domain_unregister(_ecore_drm_log_dom);
|
|
|
|
_ecore_drm_log_dom = -1;
|
|
|
|
log_err:
|
2014-07-24 08:33:21 -07:00
|
|
|
ecore_event_shutdown();
|
|
|
|
ecore_shutdown();
|
2014-03-06 01:43:48 -08:00
|
|
|
eina_shutdown();
|
|
|
|
return --_ecore_drm_init_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shutdown the Ecore_Drm library.
|
2016-01-11 13:53:18 -08:00
|
|
|
*
|
2014-03-06 01:43:48 -08:00
|
|
|
* @return The number of times the library has been initialized without
|
|
|
|
* being shutdown. 0 is returned if an error occurs.
|
2016-01-11 13:53:18 -08:00
|
|
|
*
|
2014-03-06 01:43:48 -08:00
|
|
|
* @ingroup Ecore_Drm_Init_Group
|
|
|
|
*/
|
2016-01-11 13:53:18 -08:00
|
|
|
EAPI int
|
2014-03-06 01:43:48 -08:00
|
|
|
ecore_drm_shutdown(void)
|
|
|
|
{
|
2016-01-11 13:53:18 -08:00
|
|
|
Eina_List *lists;
|
|
|
|
Ecore_Drm_Device *dev;
|
|
|
|
|
2014-10-23 06:04:29 -07:00
|
|
|
/* _ecore_drm_init_count should not go below zero. */
|
2014-10-23 07:32:59 -07:00
|
|
|
if (_ecore_drm_init_count < 1)
|
|
|
|
{
|
|
|
|
ERR("Ecore_Drm Shutdown called without Ecore_Drm Init");
|
|
|
|
return 0;
|
|
|
|
}
|
2014-10-23 06:04:29 -07:00
|
|
|
|
2014-03-06 01:43:48 -08:00
|
|
|
/* if we are still in use, decrement init count and get out */
|
|
|
|
if (--_ecore_drm_init_count != 0) return _ecore_drm_init_count;
|
|
|
|
|
2017-03-09 16:10:49 -08:00
|
|
|
ecore_event_type_flush(ECORE_DRM_EVENT_ACTIVATE,
|
|
|
|
ECORE_DRM_EVENT_OUTPUT,
|
|
|
|
ECORE_DRM_EVENT_SEAT_ADD);
|
|
|
|
|
2016-01-11 13:53:18 -08:00
|
|
|
/* free the list of devices */
|
|
|
|
lists = eina_list_clone(ecore_drm_devices_get());
|
|
|
|
EINA_LIST_FREE(lists, dev)
|
|
|
|
{
|
|
|
|
ecore_drm_device_free(dev);
|
|
|
|
}
|
|
|
|
|
2016-01-11 10:57:23 -08:00
|
|
|
_ecore_drm_inputs_shutdown();
|
|
|
|
|
2014-09-23 07:34:00 -07:00
|
|
|
/* close eeze */
|
|
|
|
eeze_shutdown();
|
2014-03-06 01:43:48 -08:00
|
|
|
|
2014-03-10 01:26:53 -07:00
|
|
|
/* shutdown ecore_event */
|
|
|
|
ecore_event_shutdown();
|
|
|
|
|
|
|
|
/* shutdown ecore */
|
2014-03-06 01:43:48 -08:00
|
|
|
ecore_shutdown();
|
|
|
|
|
|
|
|
/* unregsiter log domain */
|
|
|
|
eina_log_domain_unregister(_ecore_drm_log_dom);
|
|
|
|
_ecore_drm_log_dom = -1;
|
|
|
|
|
|
|
|
/* shutdown eina */
|
|
|
|
eina_shutdown();
|
|
|
|
|
|
|
|
/* return init count */
|
|
|
|
return _ecore_drm_init_count;
|
|
|
|
}
|