evdev: Allow setting of character device ownership and access mode

by device driver. That is required as game pad and joystick events have
to be accessible by ordinary users.

MFC after:	1 month
This commit is contained in:
Vladimir Kondratyev
2025-12-01 23:42:14 +03:00
parent 882821b78f
commit ecccc9d999
4 changed files with 23 additions and 4 deletions
+3 -3
View File
@@ -772,9 +772,9 @@ evdev_cdev_create(struct evdev_dev *evdev)
make_dev_args_init(&mda);
mda.mda_flags = MAKEDEV_WAITOK | MAKEDEV_CHECKNAME;
mda.mda_devsw = &evdev_cdevsw;
mda.mda_uid = UID_ROOT;
mda.mda_gid = GID_WHEEL;
mda.mda_mode = 0600;
mda.mda_uid = evdev->ev_cdev_uid;
mda.mda_gid = evdev->ev_cdev_gid;
mda.mda_mode = evdev->ev_cdev_mode;
mda.mda_si_drv1 = evdev;
/* Try to coexist with cuse-backed input/event devices */
+16 -1
View File
@@ -37,6 +37,7 @@
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/proc.h>
#include <sys/stat.h>
#include <sys/sx.h>
#include <sys/sysctl.h>
#include <sys/systm.h>
@@ -94,8 +95,14 @@ static int evdev_check_event(struct evdev_dev *, uint16_t, uint16_t, int32_t);
struct evdev_dev *
evdev_alloc(void)
{
struct evdev_dev *evdev;
return malloc(sizeof(struct evdev_dev), M_EVDEV, M_WAITOK | M_ZERO);
evdev = malloc(sizeof(struct evdev_dev), M_EVDEV, M_WAITOK | M_ZERO);
evdev->ev_cdev_uid = UID_ROOT;
evdev->ev_cdev_gid = GID_WHEEL;
evdev->ev_cdev_mode = S_IRUSR | S_IWUSR;
return (evdev);
}
void
@@ -584,6 +591,14 @@ evdev_set_flag(struct evdev_dev *evdev, uint16_t flag)
bit_set(evdev->ev_flags, flag);
}
void
evdev_set_cdev_mode(struct evdev_dev *evdev, uid_t uid, gid_t gid, int mode)
{
evdev->ev_cdev_uid = uid;
evdev->ev_cdev_gid = gid;
evdev->ev_cdev_mode = mode;
}
static int
evdev_check_event(struct evdev_dev *evdev, uint16_t type, uint16_t code,
int32_t value)
+1
View File
@@ -153,6 +153,7 @@ void evdev_support_sw(struct evdev_dev *, uint16_t);
void evdev_set_repeat_params(struct evdev_dev *, uint16_t, int);
int evdev_set_report_size(struct evdev_dev *, size_t);
void evdev_set_flag(struct evdev_dev *, uint16_t);
void evdev_set_cdev_mode(struct evdev_dev *, uid_t, gid_t, int);
void *evdev_get_softc(struct evdev_dev *);
bool evdev_is_grabbed(struct evdev_dev *);
+3
View File
@@ -111,6 +111,9 @@ struct evdev_dev
char ev_shortname[NAMELEN];
char ev_serial[NAMELEN];
struct cdev * ev_cdev;
uid_t ev_cdev_uid;
gid_t ev_cdev_gid;
int ev_cdev_mode;
int ev_unit;
enum evdev_lock_type ev_lock_type;
struct mtx * ev_state_lock; /* State lock */