Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input: Minor logging tweaks #1549

Merged
merged 3 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion input/input-cervantes.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void generateFakeEvent(int pipefd[2]) {

int re = ue_init_listener(&listener);
if (re < 0) {
fprintf(stderr, "[ko-input]: Failed to initialize libue listener, err: %d\n", re);
fprintf(stderr, "[ko-input]: Failed to initialize libue listener (%d)\n", re);
return;
}

Expand Down
8 changes: 4 additions & 4 deletions input/input-kobo.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ static void sendEvent(int fd, struct input_event* ev)
}

// Using strtol right is *fun*...
static int safe_strtol(const char* str)
static int strtol_d(const char* str)
{
char* endptr;
errno = 0;
long int val = strtol(str, &endptr, 10);
if (errno || endptr == str || *endptr || (int) val != val) {
// strtol failure || no digits were found || trailing garbage || cast truncation
return -1;
return -1; // this will conveniently never match a real evdev number ;).
}

return (int) val;
Expand Down Expand Up @@ -104,12 +104,12 @@ static void generateFakeEvent(int pipefd[2])
case UEVENT_ACTION_ADD:
ev.code = CODE_FAKE_USB_DEVICE_PLUGGED_IN;
// Pass along the evdev number
ev.value = safe_strtol(uev.devname + sizeof("input/event") - 1U); // i.e., start right after the t of event
ev.value = strtol_d(uev.devname + sizeof("input/event") - 1U); // i.e., start right after the t of event
sendEvent(pipefd[1], &ev);
break;
case UEVENT_ACTION_REMOVE:
ev.code = CODE_FAKE_USB_DEVICE_PLUGGED_OUT;
ev.value = safe_strtol(uev.devname + sizeof("input/event") - 1U);
ev.value = strtol_d(uev.devname + sizeof("input/event") - 1U);
sendEvent(pipefd[1], &ev);
break;
default:
Expand Down
6 changes: 3 additions & 3 deletions input/input-pocketbook.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,16 +242,16 @@ static int startInkViewMain(lua_State *L, size_t fd_idx, const char *inputdevice

inputfds[fd_idx] = open(inputdevice, O_RDWR | O_NONBLOCK);
if (inputfds[fd_idx] == -1) {
return luaL_error(L, "error opening input device <%s>: %d\n", inputdevice, errno);
return luaL_error(L, "Error opening input device <%s>: %s", inputdevice, strerror(errno));
}

if (pthread_attr_init(&thread_attr) != 0) {
return luaL_error(L, "error initializing event listener thread attributes: %d", errno);
return luaL_error(L, "Error initializing event listener thread attributes: %s", strerror(errno));
}

pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_DETACHED);
if (pthread_create(&thread, &thread_attr, runInkViewThread, 0) == -1) {
return luaL_error(L, "error creating event listener thread: %d", errno);
return luaL_error(L, "Error creating event listener thread: %s", strerror(errno));
}
pthread_attr_destroy(&thread_attr);
return 0;
Expand Down
2 changes: 1 addition & 1 deletion input/input-remarkable.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static void generateFakeEventRM1(int pipefd) {

re = ue_init_listener(&listener);
if (re < 0) {
fprintf(stderr, "[remarkable-fake-event] Failed to initilize libue listener, err: %d\n", re);
fprintf(stderr, "[remarkable-fake-event] Failed to initilize libue listener (%d)\n", re);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion input/input-sony-prstux.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ static void generateFakeEvent(int pipefd[2]) {

re = ue_init_listener(&listener);
if (re < 0) {
fprintf(stderr, "[sony-prstux-fake-event] Failed to initilize libue listener, err: %d\n", re);
fprintf(stderr, "[sony-prstux-fake-event] Failed to initilize libue listener (%d)\n", re);
return;
}

Expand Down
12 changes: 6 additions & 6 deletions input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ static int openInputDevice(lua_State* L)
#if defined(KINDLE_LEGACY)
// pipe2 requires Linux 2.6.27 & glibc 2.9...
if (pipe(pipefd) == -1) {
return luaL_error(L, "Cannot create fake event generator communication pipe (pipe(): %d)", errno);
return luaL_error(L, "Cannot create fake event generator communication pipe (pipe(): %s)", strerror(errno));
}

// Which means we need the fcntl dance like with open below...
Expand All @@ -124,13 +124,13 @@ static int openInputDevice(lua_State* L)
}
#else
if (pipe2(pipefd, O_NONBLOCK | O_CLOEXEC) == -1) {
return luaL_error(L, "Cannot create fake event generator communication pipe (pipe2(): %d)", errno);
return luaL_error(L, "Cannot create fake event generator communication pipe (pipe2(): %s)", strerror(errno));
}
#endif

pid_t childpid;
if ((childpid = fork()) == -1) {
return luaL_error(L, "Cannot fork() fake event generator (%d)", errno);
return luaL_error(L, "Cannot fork() fake event generator: %s", strerror(errno));
}
if (childpid == 0) {
// Deliver SIGTERM to child when parent dies.
Expand Down Expand Up @@ -166,7 +166,7 @@ static int openInputDevice(lua_State* L)
fcntl(inputfds[fd_idx], F_SETFD, fdflags | FD_CLOEXEC);
#endif
} else {
return luaL_error(L, "Error opening input device <%s>: %d", inputdevice, errno);
return luaL_error(L, "Error opening input device <%s>: %s", inputdevice, strerror(errno));
}
}

Expand Down Expand Up @@ -198,7 +198,7 @@ static int closeInputDevice(ssize_t fd_idx_to_close)
inputfds[--fd_idx] = -1;

computeNfds();
printf("[ko-input] Closed input device with idx=%zd, fd=%d\n", fd_idx_to_close, fd);
printf("[ko-input] Closed input device with fd: %d @ idx: %zd\n", fd, fd_idx_to_close);

return 0;
}
Expand Down Expand Up @@ -234,7 +234,7 @@ static int fakeTapInput(lua_State* L)

int inputfd = open(inputdevice, O_WRONLY | O_NONBLOCK);
if (inputfd == -1) {
return luaL_error(L, "Cannot open input device <%s>: %d", inputdevice, errno);
return luaL_error(L, "Error opening tap injection input device <%s>: %s", inputdevice, strerror(errno));
}

// Pop function args, now that we're done w/ inputdevice
Expand Down
1 change: 1 addition & 0 deletions input/libue.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ struct uevent_listener
#define ERR_LISTENER_RECV -4
#define ERR_PARSE_UDEV -1
#define ERR_PARSE_INVALID_HDR -2
// NOTE: This is a *prefix* match, str just needs to *begin* with const_str for it to match!
#define UE_STR_EQ(str, const_str) (strncmp((str), (const_str), sizeof(const_str) - 1U) == 0)

enum uevent_action
Expand Down