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

closeInputDevices should not decrease num_fds within the loop #1364

Merged
merged 6 commits into from May 4, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions input/input.c
Expand Up @@ -163,14 +163,14 @@ static int openInputDevice(lua_State* L)

static int closeInputDevices(lua_State* L __attribute__((unused)))
{
for (size_t i = 0U; i < num_fds; i++) {
for (size_t i = num_fds - 1; i >= 0; i--) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be a ssize_t (size_t is unsigned, that makes the comparison useless, and, well, breaks it ;p).

if (inputfds[i] != -1) {
ioctl(inputfds[i], EVIOCGRAB, 0);
close(inputfds[i]);
inputfds[i] = -1;
num_fds--;
}
}
num_fds = 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep it inside the loop for real, in case something wonky ever happens and we need to close only some slots.


#if defined(WITH_TIMERFD)
clearAllTimers();
Expand All @@ -181,6 +181,7 @@ static int closeInputDevices(lua_State* L __attribute__((unused)))
// Kill and wait to reap our child process.
kill(fake_ev_generator_pid, SIGTERM);
waitpid(-1, NULL, 0);
fake_ev_generator_pid = -1;
}

return 0;
Expand Down