f31522130f
Build system (5 gaps hardened): - COOKBOOK_OFFLINE defaults to true (fork-mode) - normalize_patch handles diff -ruN format - New 'repo validate-patches' command (25/25 relibc patches) - 14 patched Qt/Wayland/display recipes added to protected list - relibc archive regenerated with current patch chain Boot fixes (fixable): - Full ISO EFI partition: 16 MiB → 1 MiB (matches mini, BIOS hardcoded 2 MiB offset) - D-Bus system bus: absolute /usr/bin/dbus-daemon path (was skipped) - redbear-sessiond: absolute /usr/bin/redbear-sessiond path (was skipped) - daemon framework: silenced spurious INIT_NOTIFY warnings for oneshot_async services (P0-daemon-silence-init-notify.patch) - udev-shim: demoted INIT_NOTIFY warning to INFO (expected for oneshot_async) - relibc: comprehensive named semaphores (sem_open/close/unlink) replacing upstream todo!() stubs - greeterd: Wayland socket timeout 15s → 30s (compositor DRM wait) - greeter-ui: built and linked (header guard unification, sem_compat stubs removed) - mc: un-ignored in both configs, fixed glib/libiconv/pcre2 transitive deps - greeter config: removed stale keymapd dependency from display/greeter services - prefix toolchain: relibc headers synced, _RELIBC_STDLIB_H guard unified Unfixable (diagnosed, upstream): - i2c-hidd: abort on no-I2C-hardware (QEMU) — process::exit → relibc abort - kded6/greeter-ui: page fault 0x8 — Qt library null deref - Thread panics fd != -1 — Rust std library on Redox - DHCP timeout / eth0 MAC — QEMU user-mode networking - hwrngd/thermald — no hardware RNG/thermal in VM - live preload allocation — BIOS memory fragmentation, continues on demand
283 lines
5.4 KiB
C
283 lines
5.4 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2013 Red Hat, Inc.
|
|
*/
|
|
|
|
#include "config.h"
|
|
#include <fcntl.h>
|
|
#include <poll.h>
|
|
#include <unistd.h>
|
|
#include <string.h>
|
|
#include <stdio.h>
|
|
#include <errno.h>
|
|
#include <linux/uinput.h>
|
|
#include <dirent.h>
|
|
|
|
#include <libevdev/libevdev.h>
|
|
#include <libevdev/libevdev-int.h>
|
|
#include <libevdev/libevdev-util.h>
|
|
#include <libevdev/libevdev-uinput.h>
|
|
|
|
#include "test-common-uinput.h"
|
|
|
|
#define SYS_INPUT_DIR "/sys/class/input"
|
|
#define DEV_INPUT_DIR "/dev/input/"
|
|
|
|
struct uinput_device
|
|
{
|
|
struct libevdev *d; /* lazy, it has all the accessors */
|
|
struct libevdev_uinput *uidev;
|
|
int dev_fd; /* open fd to the devnode */
|
|
int uinput_fd;
|
|
};
|
|
|
|
struct uinput_device*
|
|
uinput_device_new(const char *name)
|
|
{
|
|
struct uinput_device *dev;
|
|
|
|
dev = calloc(1, sizeof(*dev));
|
|
if (!dev)
|
|
return NULL;
|
|
|
|
dev->d = libevdev_new();
|
|
dev->dev_fd = -1;
|
|
dev->uinput_fd = -1;
|
|
|
|
if (name)
|
|
libevdev_set_name(dev->d, name);
|
|
|
|
return dev;
|
|
}
|
|
|
|
int
|
|
uinput_device_new_with_events_v(struct uinput_device **d, const char *name, const struct input_id *id, va_list args)
|
|
{
|
|
int rc;
|
|
struct uinput_device *dev;
|
|
|
|
dev = uinput_device_new(name);
|
|
if (!dev)
|
|
return -ENOMEM;
|
|
if (id != DEFAULT_IDS)
|
|
uinput_device_set_ids(dev, id);
|
|
|
|
rc = uinput_device_set_event_bits_v(dev, args);
|
|
|
|
if (rc == 0)
|
|
rc = uinput_device_create(dev);
|
|
|
|
if (rc != 0) {
|
|
uinput_device_free(dev);
|
|
dev = NULL;
|
|
} else
|
|
*d = dev;
|
|
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
uinput_device_new_with_events(struct uinput_device **d, const char *name, const struct input_id *id, ...)
|
|
{
|
|
int rc;
|
|
va_list args;
|
|
|
|
va_start(args, id);
|
|
rc = uinput_device_new_with_events_v(d, name, id, args);
|
|
va_end(args);
|
|
|
|
return rc;
|
|
}
|
|
|
|
void
|
|
uinput_device_free(struct uinput_device *dev)
|
|
{
|
|
if (!dev)
|
|
return;
|
|
|
|
if (dev->uinput_fd != -1) {
|
|
(void)ioctl(dev->uinput_fd, UI_DEV_DESTROY, NULL);
|
|
close(dev->uinput_fd);
|
|
}
|
|
if (dev->dev_fd != -1)
|
|
close(dev->dev_fd);
|
|
libevdev_free(dev->d);
|
|
libevdev_uinput_destroy(dev->uidev);
|
|
free(dev);
|
|
}
|
|
|
|
int
|
|
uinput_device_get_fd(const struct uinput_device *dev)
|
|
{
|
|
return dev->dev_fd;
|
|
}
|
|
|
|
const char*
|
|
uinput_device_get_devnode(const struct uinput_device *dev)
|
|
{
|
|
return libevdev_uinput_get_devnode(dev->uidev);
|
|
}
|
|
|
|
int
|
|
uinput_device_create(struct uinput_device* d)
|
|
{
|
|
int rc;
|
|
int fd;
|
|
const char *devnode;
|
|
|
|
fd = open("/dev/uinput", O_RDWR);
|
|
if (fd < 0)
|
|
goto error;
|
|
|
|
d->uinput_fd = fd;
|
|
|
|
rc = libevdev_uinput_create_from_device(d->d, fd, &d->uidev);
|
|
if (rc != 0)
|
|
goto error;
|
|
|
|
devnode = libevdev_uinput_get_devnode(d->uidev);
|
|
if (devnode == NULL)
|
|
goto error;
|
|
|
|
d->dev_fd = open(devnode, O_RDWR);
|
|
if (d->dev_fd == -1)
|
|
goto error;
|
|
|
|
/* write abs resolution now */
|
|
if (libevdev_has_event_type(d->d, EV_ABS)) {
|
|
int code;
|
|
for (code = 0; code < ABS_CNT; code++) {
|
|
const struct input_absinfo *abs;
|
|
|
|
/* can't change slots */
|
|
if (code == ABS_MT_SLOT)
|
|
continue;
|
|
|
|
abs = libevdev_get_abs_info(d->d, code);
|
|
if (!abs)
|
|
continue;
|
|
|
|
rc = ioctl(d->dev_fd, EVIOCSABS(code), abs);
|
|
if (rc < 0) {
|
|
printf("error %s for code %d\n", strerror(-rc), code);
|
|
goto error;
|
|
}
|
|
}
|
|
}
|
|
|
|
return 0;
|
|
|
|
error:
|
|
if (d->dev_fd != -1)
|
|
close(d->dev_fd);
|
|
if (d->uinput_fd != -1)
|
|
close(d->uinput_fd);
|
|
return -errno;
|
|
|
|
}
|
|
|
|
int uinput_device_set_name(struct uinput_device *dev, const char *name)
|
|
{
|
|
libevdev_set_name(dev->d, name);
|
|
return 0;
|
|
}
|
|
|
|
int uinput_device_set_ids(struct uinput_device *dev, const struct input_id *ids)
|
|
{
|
|
libevdev_set_id_product(dev->d, ids->product);
|
|
libevdev_set_id_vendor(dev->d, ids->vendor);
|
|
libevdev_set_id_bustype(dev->d, ids->bustype);
|
|
libevdev_set_id_version(dev->d, ids->version);
|
|
return 0;
|
|
}
|
|
|
|
int
|
|
uinput_device_set_bit(struct uinput_device* dev, unsigned int bit)
|
|
{
|
|
return libevdev_enable_event_type(dev->d, bit);
|
|
}
|
|
|
|
int
|
|
uinput_device_set_prop(struct uinput_device *dev, unsigned int prop)
|
|
{
|
|
return libevdev_enable_property(dev->d, prop);
|
|
}
|
|
|
|
int
|
|
uinput_device_set_event_bit(struct uinput_device* dev, unsigned int type, unsigned int code)
|
|
{
|
|
return libevdev_enable_event_code(dev->d, type, code, NULL);
|
|
}
|
|
|
|
int
|
|
uinput_device_set_event_bits_v(struct uinput_device *dev, va_list args)
|
|
{
|
|
int type, code;
|
|
int rc = 0;
|
|
|
|
do {
|
|
type = va_arg(args, int);
|
|
if (type == -1)
|
|
break;
|
|
code = va_arg(args, int);
|
|
if (code == -1)
|
|
break;
|
|
rc = libevdev_enable_event_code(dev->d, type, code, NULL);
|
|
} while (rc == 0);
|
|
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
uinput_device_set_event_bits(struct uinput_device *dev, ...)
|
|
{
|
|
int rc;
|
|
va_list args;
|
|
va_start(args, dev);
|
|
rc = uinput_device_set_event_bits_v(dev, args);
|
|
va_end(args);
|
|
|
|
return rc;
|
|
}
|
|
|
|
int
|
|
uinput_device_set_abs_bit(struct uinput_device* dev, unsigned int code, const struct input_absinfo *absinfo)
|
|
{
|
|
return libevdev_enable_event_code(dev->d, EV_ABS, code, absinfo);
|
|
}
|
|
|
|
int
|
|
uinput_device_event(const struct uinput_device *dev, unsigned int type, unsigned int code, int value)
|
|
{
|
|
return libevdev_uinput_write_event(dev->uidev, type, code, value);
|
|
}
|
|
|
|
int uinput_device_event_multiple_v(const struct uinput_device* dev, va_list args)
|
|
{
|
|
int type, code, value;
|
|
int rc = 0;
|
|
|
|
do {
|
|
type = va_arg(args, int);
|
|
if (type == -1)
|
|
break;
|
|
code = va_arg(args, int);
|
|
if (code == -1)
|
|
break;
|
|
value = va_arg(args, int);
|
|
rc = uinput_device_event(dev, type, code, value);
|
|
} while (rc == 0);
|
|
|
|
return rc;
|
|
}
|
|
|
|
int uinput_device_event_multiple(const struct uinput_device* dev, ...)
|
|
{
|
|
int rc;
|
|
va_list args;
|
|
va_start(args, dev);
|
|
rc = uinput_device_event_multiple_v(dev, args);
|
|
va_end(args);
|
|
return rc;
|
|
}
|