Changeset View
Changeset View
Standalone View
Standalone View
config/devd.c
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#include "input.h" | #include "input.h" | ||||
#include "inputstr.h" | #include "inputstr.h" | ||||
#include "hotplug.h" | #include "hotplug.h" | ||||
#include "config-backends.h" | #include "config-backends.h" | ||||
#include "os.h" | #include "os.h" | ||||
#define DEVD_SOCK_PATH "/var/run/devd.pipe" | #define DEVD_SOCK_PATH "/var/run/devd.pipe" | ||||
#define DEVD_EVENT_ADD '+' | #define DEVD_EVENT_CDEV "cdev=" | ||||
#define DEVD_EVENT_REMOVE '-' | #define DEVD_EVENT_ADD "type=CREATE" | ||||
#define DEVD_EVENT_REMOVE "type=DESTROY" | |||||
#define RECONNECT_DELAY 5 * 1000 | #define RECONNECT_DELAY 5 * 1000 | ||||
static int sock_devd; | static int sock_devd; | ||||
static bool is_console_kbd = false; | static bool is_console_kbd = false; | ||||
static bool is_kbdmux = false; | static bool is_kbdmux = false; | ||||
static OsTimerPtr rtimer = NULL; | static OsTimerPtr rtimer = NULL; | ||||
Show All 9 Lines | static struct hw_type hw_types[] = { | ||||
{ "kbdmux", ATTR_KEYBOARD, "kbd" }, | { "kbdmux", ATTR_KEYBOARD, "kbd" }, | ||||
{ "sysmouse", ATTR_POINTER, "mouse" }, | { "sysmouse", ATTR_POINTER, "mouse" }, | ||||
{ "ums", ATTR_POINTER, "mouse" }, | { "ums", ATTR_POINTER, "mouse" }, | ||||
{ "psm", ATTR_POINTER, "mouse" }, | { "psm", ATTR_POINTER, "mouse" }, | ||||
{ "vboxguest", ATTR_POINTER, "vboxmouse" }, | { "vboxguest", ATTR_POINTER, "vboxmouse" }, | ||||
{ "joy", ATTR_JOYSTICK, NULL }, | { "joy", ATTR_JOYSTICK, NULL }, | ||||
{ "atp", ATTR_TOUCHPAD, NULL }, | { "atp", ATTR_TOUCHPAD, NULL }, | ||||
{ "uep", ATTR_TOUCHSCREEN, NULL }, | { "uep", ATTR_TOUCHSCREEN, NULL }, | ||||
{ "input/event", 0, "evdev" }, | |||||
{ NULL, -1, NULL }, | { NULL, -1, NULL }, | ||||
}; | }; | ||||
static bool | static bool | ||||
sysctl_exists(const struct hw_type *device, int unit, | sysctl_exists(const struct hw_type *device, int unit, | ||||
char *devname, size_t devname_len) | char *devname, size_t devname_len) | ||||
{ | { | ||||
char sysctlname[PATH_MAX]; | char sysctlname[PATH_MAX]; | ||||
Show All 38 Lines | devpath_exists(const struct hw_type *device, | ||||
if (ret == 0) { | if (ret == 0) { | ||||
strncpy(devname, device->driver, devname_len); | strncpy(devname, device->driver, devname_len); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
static bool | |||||
evdev_exists(const struct hw_type *device, int unit, | |||||
char *devname, size_t devname_len) | |||||
{ | |||||
char devpath[1024]; | |||||
struct stat st; | |||||
if (device == NULL || device->driver == NULL) | |||||
return false; | |||||
if (device->xdriver == 0 || 0 != strcmp(device->xdriver, "evdev")) | |||||
return false; | |||||
/* Check if /dev/$driver$unit exists. */ | |||||
snprintf(devpath, sizeof(devpath), "/dev/%s%i", device->driver, unit); | |||||
if (0 != stat(devpath, &st)) | |||||
return false; | |||||
snprintf(devname, devname_len, "%s%i", device->driver, unit); | |||||
return true; | |||||
} | |||||
static char * | static char * | ||||
sysctl_get_str(const char *sysctlname) | sysctl_get_str(const char *sysctlname) | ||||
{ | { | ||||
char *dest = NULL; | char *dest = NULL; | ||||
size_t len; | size_t len; | ||||
if (sysctlname == NULL) | if (sysctlname == NULL) | ||||
return NULL; | return NULL; | ||||
▲ Show 20 Lines • Show All 297 Lines • ▼ Show 20 Lines | socket_getline(int fd, char **out) | ||||
/* Number of bytes in the line, not counting the line break */ | /* Number of bytes in the line, not counting the line break */ | ||||
return sz; | return sz; | ||||
} | } | ||||
static void | static void | ||||
wakeup_handler(void *data, int err, void *read_mask) | wakeup_handler(void *data, int err, void *read_mask) | ||||
{ | { | ||||
char *line = NULL; | char *line = NULL; | ||||
char *type = NULL; | |||||
char *cdev = NULL; | |||||
char *walk; | char *walk; | ||||
if (err < 0) | if (err < 0) | ||||
return; | return; | ||||
if (FD_ISSET(sock_devd, (fd_set *) read_mask)) { | if (FD_ISSET(sock_devd, (fd_set *) read_mask)) { | ||||
if (socket_getline(sock_devd, &line) < 0) | if (socket_getline(sock_devd, &line) < 0) | ||||
return; | return; | ||||
walk = strchr(line + 1, ' '); | cdev = strrchr(line + 1, ' '); | ||||
if (walk != NULL) | if (cdev == NULL) | ||||
walk[0] = '\0'; | goto unwind; | ||||
(cdev++)[0] = '\0'; | |||||
switch (*line) { | const size_t len = strlen(DEVD_EVENT_CDEV); | ||||
case DEVD_EVENT_ADD: | if (0 != strncmp(cdev, DEVD_EVENT_CDEV, len)) | ||||
device_added(line + 1); | goto unwind; | ||||
break; | cdev += len; | ||||
case DEVD_EVENT_REMOVE: | |||||
device_removed(line + 1); | type = strrchr(line + 1, ' '); | ||||
break; | if (type == NULL) | ||||
default: | goto unwind; | ||||
break; | (type++)[0] = '\0'; | ||||
if (0 == strcmp(type, DEVD_EVENT_ADD)) { | |||||
device_added(cdev); | |||||
} else if (0 == strcmp(type, DEVD_EVENT_REMOVE)) { | |||||
device_removed(cdev); | |||||
} | } | ||||
unwind: | |||||
free(line); | free(line); | ||||
} | } | ||||
} | } | ||||
static void | static void | ||||
block_handler(void *data, struct timeval **tv, void *read_mask) | block_handler(void *data, struct timeval **tv, void *read_mask) | ||||
{ | { | ||||
} | } | ||||
Show All 12 Lines | config_devd_init(void) | ||||
*/ | */ | ||||
if ((is_kbdmux = is_kbdmux_enabled()) == true) | if ((is_kbdmux = is_kbdmux_enabled()) == true) | ||||
device_added("kbdmux"); | device_added("kbdmux"); | ||||
for (i = 0; hw_types[i].driver != NULL; i++) { | for (i = 0; hw_types[i].driver != NULL; i++) { | ||||
/* First scan the sysctl to determine the hardware */ | /* First scan the sysctl to determine the hardware */ | ||||
for (j = 0; j < 16; j++) { | for (j = 0; j < 16; j++) { | ||||
if (sysctl_exists(&hw_types[i], j, | if (sysctl_exists(&hw_types[i], j, | ||||
devicename, sizeof(devicename)) != 0) | |||||
device_added(devicename); | |||||
if (evdev_exists(&hw_types[i], j, | |||||
devicename, sizeof(devicename)) != 0) | devicename, sizeof(devicename)) != 0) | ||||
device_added(devicename); | device_added(devicename); | ||||
} | } | ||||
if (devpath_exists(&hw_types[i], devicename, sizeof(devicename)) != 0) | if (devpath_exists(&hw_types[i], devicename, sizeof(devicename)) != 0) | ||||
device_added(devicename); | device_added(devicename); | ||||
} | } | ||||
Show All 24 Lines |