forked from enlightenment/efl
handle some error conditions better to avoid segvs, add a little bit of info on watch creation failure, fix some return types to bools, clean up formatting failures
SVN revision: 53479
This commit is contained in:
parent
496e6350b2
commit
73e8abd5d9
|
@ -56,8 +56,8 @@ eeze_init(void)
|
|||
|
||||
if (!((udev) = udev_new()))
|
||||
{
|
||||
EINA_LOG_ERR("Could not initialize udev library!");
|
||||
goto fail;
|
||||
EINA_LOG_ERR("Could not initialize udev library!");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
return _eeze_init_count;
|
||||
|
|
|
@ -8,6 +8,10 @@
|
|||
|
||||
extern _udev *udev;
|
||||
|
||||
/*
|
||||
* helper function to set up a new device from a syspath
|
||||
* which may or may not include /sys at the beginning
|
||||
*/
|
||||
_udev_device *
|
||||
_new_device(const char *syspath)
|
||||
{
|
||||
|
@ -54,7 +58,7 @@ _walk_parents_test_attr(_udev_device * device, const char *sysattr,
|
|||
const char *test;
|
||||
|
||||
if (udev_device_get_sysattr_value(device, sysattr))
|
||||
return 1;
|
||||
return EINA_TRUE;
|
||||
|
||||
parent = udev_device_get_parent(child);
|
||||
|
||||
|
@ -64,13 +68,13 @@ _walk_parents_test_attr(_udev_device * device, const char *sysattr,
|
|||
continue;
|
||||
|
||||
if (!value)
|
||||
return 1;
|
||||
return EINA_TRUE;
|
||||
else
|
||||
if (!strcmp(test, value))
|
||||
return 1;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
const char *
|
||||
|
@ -115,7 +119,7 @@ _get_unlisted_parents(Eina_List * list, _udev_device * device)
|
|||
|
||||
for (; parent; child = parent, parent = udev_device_get_parent(child))
|
||||
{
|
||||
found = 0;
|
||||
found = EINA_FALSE;
|
||||
|
||||
if (!(vendor2 = udev_device_get_property_value(child, "ID_VENDOR_ID")))
|
||||
vendor2 = udev_device_get_property_value(child, "ID_VENDOR");
|
||||
|
@ -136,7 +140,7 @@ _get_unlisted_parents(Eina_List * list, _udev_device * device)
|
|||
{
|
||||
if (!strcmp(test, devname))
|
||||
{
|
||||
found = 1;
|
||||
found = EINA_TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -189,8 +189,8 @@ eeze_udev_syspath_get_sysattr(const char *syspath, const char *sysattr)
|
|||
EAPI Eina_Bool
|
||||
eeze_udev_syspath_is_mouse(const char *syspath)
|
||||
{
|
||||
_udev_device *device;
|
||||
Eina_Bool mouse = 0;
|
||||
_udev_device *device = NULL;
|
||||
Eina_Bool mouse = EINA_FALSE;
|
||||
const char *test = NULL;
|
||||
|
||||
if (!syspath)
|
||||
|
@ -206,14 +206,14 @@ eeze_udev_syspath_is_mouse(const char *syspath)
|
|||
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||
|
||||
if ((test) && (!strcmp(test, "mouse")))
|
||||
mouse = 1;
|
||||
mouse = EINA_TRUE;
|
||||
}
|
||||
|
||||
#else
|
||||
test = udev_device_get_property_value(device, "ID_INPUT_MOUSE");
|
||||
|
||||
if (test)
|
||||
mouse = atoi(test);
|
||||
if (test && (test[0] == '1'))
|
||||
mouse = EINA_TRUE;
|
||||
|
||||
#endif
|
||||
udev_device_unref(device);
|
||||
|
@ -229,12 +229,12 @@ eeze_udev_syspath_is_mouse(const char *syspath)
|
|||
EAPI Eina_Bool
|
||||
eeze_udev_syspath_is_kbd(const char *syspath)
|
||||
{
|
||||
_udev_device *device;
|
||||
Eina_Bool kbd = 0;
|
||||
_udev_device *device = NULL;
|
||||
Eina_Bool kbd = EINA_FALSE;
|
||||
const char *test = NULL;
|
||||
|
||||
if (!syspath)
|
||||
return 0;
|
||||
return EINA_FALSE;
|
||||
|
||||
if (!(device = _new_device(syspath)))
|
||||
return EINA_FALSE;
|
||||
|
@ -246,14 +246,14 @@ eeze_udev_syspath_is_kbd(const char *syspath)
|
|||
test = udev_device_get_property_value(device, "ID_CLASS");
|
||||
|
||||
if ((test) && (!strcmp(test, "kbd")))
|
||||
kbd = 1;
|
||||
kbd = EINA_TRUE;
|
||||
}
|
||||
|
||||
#else
|
||||
test = udev_device_get_property_value(device, "ID_INPUT_KEYBOARD");
|
||||
|
||||
if (test)
|
||||
kbd = atoi(test);
|
||||
if (test && (test[0] == '1'))
|
||||
kbd = EINA_TRUE;
|
||||
|
||||
#endif
|
||||
udev_device_unref(device);
|
||||
|
@ -269,11 +269,11 @@ eeze_udev_syspath_is_kbd(const char *syspath)
|
|||
EAPI Eina_Bool
|
||||
eeze_udev_syspath_is_touchpad(const char *syspath)
|
||||
{
|
||||
_udev_device *device;
|
||||
Eina_Bool touchpad = 0;
|
||||
_udev_device *device = NULL;
|
||||
Eina_Bool touchpad = EINA_FALSE;
|
||||
|
||||
if (!syspath)
|
||||
return 0;
|
||||
return EINA_FALSE;
|
||||
|
||||
if (!(device = _new_device(syspath)))
|
||||
return EINA_FALSE;
|
||||
|
@ -283,8 +283,8 @@ eeze_udev_syspath_is_touchpad(const char *syspath)
|
|||
const char *test;
|
||||
test = udev_device_get_property_value(device, "ID_INPUT_TOUCHPAD");
|
||||
|
||||
if (test)
|
||||
touchpad = atoi(test);
|
||||
if (test && (test[0] == '1'))
|
||||
touchpad = EINA_TRUE;
|
||||
|
||||
#endif
|
||||
udev_device_unref(device);
|
||||
|
|
|
@ -37,7 +37,7 @@ eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
|
|||
const char *test = NULL;
|
||||
|
||||
if (!udev)
|
||||
return 0;
|
||||
return EINA_FALSE;
|
||||
|
||||
if (!(device = _new_device(syspath)))
|
||||
return EINA_FALSE;
|
||||
|
@ -55,7 +55,7 @@ eeze_udev_walk_check_sysattr(const char *syspath, const char *sysattr,
|
|||
}
|
||||
|
||||
udev_device_unref(device);
|
||||
return 0;
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -52,7 +52,7 @@ static Eina_Bool
|
|||
_get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
||||
{
|
||||
struct _store_data *store = data;
|
||||
_udev_device *device, *parent, *tmpdev;
|
||||
_udev_device *device = NULL, *parent, *tmpdev;
|
||||
const char *ret, *test;
|
||||
Eeze_Udev_Watch_Cb func = store->func;
|
||||
void *sdata = store->data;
|
||||
|
@ -206,17 +206,17 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
/* if device is not the one which has the temp input, we must go up the chain */
|
||||
if (!udev_device_get_sysattr_value(device, "temp1_input"))
|
||||
{
|
||||
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
|
||||
if (udev_device_get_sysattr_value(parent, "temp1_input"))
|
||||
{
|
||||
tmpdev = device;
|
||||
for (parent = udev_device_get_parent(device); parent; parent = udev_device_get_parent(parent)) /*check for parent */
|
||||
if (udev_device_get_sysattr_value(parent, "temp1_input"))
|
||||
{
|
||||
tmpdev = device;
|
||||
|
||||
if (!(device = _copy_device(parent)))
|
||||
goto error;
|
||||
if (!(device = _copy_device(parent)))
|
||||
goto error;
|
||||
|
||||
udev_device_unref(tmpdev);
|
||||
break;
|
||||
}
|
||||
udev_device_unref(tmpdev);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -230,53 +230,54 @@ _get_syspath_from_watch(void *data, Ecore_Fd_Handler * fd_handler)
|
|||
|
||||
if (store->event)
|
||||
{
|
||||
if (!strcmp(test, "add"))
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_ADD) != EEZE_UDEV_EVENT_ADD)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_ADD;
|
||||
}
|
||||
else
|
||||
if (!strcmp(test, "remove"))
|
||||
if (!strcmp(test, "add"))
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
|
||||
EEZE_UDEV_EVENT_REMOVE)
|
||||
goto error;
|
||||
if ((store->event & EEZE_UDEV_EVENT_ADD) != EEZE_UDEV_EVENT_ADD)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_REMOVE;
|
||||
event |= EEZE_UDEV_EVENT_ADD;
|
||||
}
|
||||
else
|
||||
if (!strcmp(test, "change"))
|
||||
if (!strcmp(test, "remove"))
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_CHANGE) !=
|
||||
EEZE_UDEV_EVENT_CHANGE)
|
||||
goto error;
|
||||
if ((store->event & EEZE_UDEV_EVENT_REMOVE) !=
|
||||
EEZE_UDEV_EVENT_REMOVE)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_CHANGE;
|
||||
event |= EEZE_UDEV_EVENT_REMOVE;
|
||||
}
|
||||
else
|
||||
if (!strcmp(test, "online"))
|
||||
if (!strcmp(test, "change"))
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_ONLINE) !=
|
||||
EEZE_UDEV_EVENT_ONLINE)
|
||||
goto error;
|
||||
if ((store->event & EEZE_UDEV_EVENT_CHANGE) !=
|
||||
EEZE_UDEV_EVENT_CHANGE)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_ONLINE;
|
||||
event |= EEZE_UDEV_EVENT_CHANGE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_OFFLINE) !=
|
||||
EEZE_UDEV_EVENT_OFFLINE)
|
||||
goto error;
|
||||
if (!strcmp(test, "online"))
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_ONLINE) !=
|
||||
EEZE_UDEV_EVENT_ONLINE)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_OFFLINE;
|
||||
}
|
||||
event |= EEZE_UDEV_EVENT_ONLINE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ((store->event & EEZE_UDEV_EVENT_OFFLINE) !=
|
||||
EEZE_UDEV_EVENT_OFFLINE)
|
||||
goto error;
|
||||
|
||||
event |= EEZE_UDEV_EVENT_OFFLINE;
|
||||
}
|
||||
}
|
||||
|
||||
(*func)(eina_stringshare_add(ret), event, sdata, watch);
|
||||
error:
|
||||
udev_device_unref(device);
|
||||
if (device)
|
||||
udev_device_unref(device);
|
||||
return EINA_TRUE;
|
||||
}
|
||||
/**
|
||||
|
@ -300,8 +301,8 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event,
|
|||
_udev_monitor *mon = NULL;
|
||||
int fd;
|
||||
Ecore_Fd_Handler *handler;
|
||||
Eeze_Udev_Watch *watch;
|
||||
struct _store_data *store;
|
||||
Eeze_Udev_Watch *watch = NULL;
|
||||
struct _store_data *store = NULL;
|
||||
|
||||
if (!(store = calloc(sizeof(struct _store_data), 1)))
|
||||
return NULL;
|
||||
|
@ -375,9 +376,13 @@ eeze_udev_watch_add(Eeze_Udev_Type type, int event,
|
|||
watch->handler = handler;
|
||||
return watch;
|
||||
error:
|
||||
free(store);
|
||||
free(watch);
|
||||
udev_monitor_unref(mon);
|
||||
if (store)
|
||||
free(store);
|
||||
if (watch)
|
||||
free(watch);
|
||||
if (mon)
|
||||
udev_monitor_unref(mon);
|
||||
ERR("Could not create watch!");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue