hosted: open input device as read-only.

Change-Id: I4dcd98f45f41fe06a0a75a2a0dd45c753c2cf365
This commit is contained in:
Solomon Peachy 2020-10-16 14:11:51 -04:00
parent 1a76bc403e
commit c6d2a0358f
5 changed files with 14 additions and 15 deletions

View file

@ -70,14 +70,14 @@ static int button_map(int keycode)
void button_init_device(void) void button_init_device(void)
{ {
const char * const input_devs[] = { const char * const input_devs[NR_POLL_DESC] = {
"/dev/input/event0", "/dev/input/event0",
"/dev/input/event1" "/dev/input/event1"
}; };
for(int i = 0; i < NR_POLL_DESC; i++) for(int i = 0; i < NR_POLL_DESC; i++)
{ {
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC); int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC);
if(fd < 0) if(fd < 0)
{ {
@ -146,4 +146,3 @@ void button_close_device(void)
close(poll_fds[i].fd); close(poll_fds[i].fd);
} }
} }

View file

@ -38,7 +38,7 @@
#include "backlight-target.h" #include "backlight-target.h"
#include "erosqlinux_codec.h" #include "erosqlinux_codec.h"
#define NR_POLL_DESC 3 #define NR_POLL_DESC 2
static struct pollfd poll_fds[NR_POLL_DESC]; static struct pollfd poll_fds[NR_POLL_DESC];
static int button_map(int keycode) static int button_map(int keycode)
@ -82,18 +82,18 @@ static int button_map(int keycode)
void button_init_device(void) void button_init_device(void)
{ {
const char * const input_devs[] = { const char * const input_devs[NR_POLL_DESC] = {
"/dev/input/event0", // Rotary encoder "/dev/input/event0", // Rotary encoder
"/dev/input/event1" // Keys "/dev/input/event1" // Keys
}; };
for(int i = 0; i < NR_POLL_DESC; i++) for(int i = 0; i < NR_POLL_DESC; i++)
{ {
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC); int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC);
if(fd < 0) if(fd < 0)
{ {
panicf("Cannot open input device: %s\n", input_devs[i]); panicf("Cannot open input device: %s (%d)\n", input_devs[i], errno);
} }
poll_fds[i].fd = fd; poll_fds[i].fd = fd;

View file

@ -219,14 +219,14 @@ static int button_map_timer(void)
void button_init_device(void) void button_init_device(void)
{ {
const char * const input_devs[] = { const char * const input_devs[NR_POLL_DESC] = {
"/dev/input/event0", "/dev/input/event0",
"/dev/input/event1", "/dev/input/event1",
}; };
for(int i = 0; i < NR_POLL_DESC; i++) for(int i = 0; i < NR_POLL_DESC; i++)
{ {
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC); int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC);
if(fd < 0) if(fd < 0)
{ {

View file

@ -156,7 +156,7 @@ static void key_init_state(int fd)
static void open_input_device(const char *path) static void open_input_device(const char *path)
{ {
int fd = open(path, O_RDWR); int fd = open(path, O_RDONLY | O_CLOEXEC);
if(fd < 0) if(fd < 0)
return; return;
/* query name */ /* query name */

View file

@ -76,7 +76,7 @@ static int button_map(int keycode)
void button_init_device(void) void button_init_device(void)
{ {
const char * const input_devs[] = { const char * const input_devs[NR_POLL_DESC] = {
"/dev/input/event0", "/dev/input/event0",
"/dev/input/event1", "/dev/input/event1",
"/dev/input/event2" "/dev/input/event2"
@ -84,7 +84,7 @@ void button_init_device(void)
for(int i = 0; i < NR_POLL_DESC; i++) for(int i = 0; i < NR_POLL_DESC; i++)
{ {
int fd = open(input_devs[i], O_RDWR | O_CLOEXEC); int fd = open(input_devs[i], O_RDONLY | O_CLOEXEC);
if(fd < 0) if(fd < 0)
{ {