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: Ensure clearTimer won't compute a lower nfds value than one of our opened fds #1685

Merged
merged 3 commits into from
Nov 1, 2023

Conversation

NiLuJe
Copy link
Member

@NiLuJe NiLuJe commented Oct 29, 2023

By making sure in openInputDevice that the top member of the array also happens to be the highest fd number.


Initial draft below:

Mention that nfds computations assume the inputfds array is sorted in increasing fd numbers

This doesn't necessarily hold true in practice (e.g., if one were to first open an fd during a directory walk with a few dir/file fds open...)


This change is Reviewable

sorted in increasing fd numbers

This doesn't necessarily hold true in practice (e.g., if one were to
first open an fd during a directory walk with a few dir/file fds
open...)
@NiLuJe
Copy link
Member Author

NiLuJe commented Oct 29, 2023

Just so that I remember to fix that one day ;).

(Possibly by sorting the inputfds array on open/close, to keep the timer code simple and avoid having to walk it).

our opened fds

By making sure in openInputDevice that the top member of the array also
happens to be the highest fd number.
@NiLuJe NiLuJe marked this pull request as ready for review October 30, 2023 01:56
@NiLuJe NiLuJe changed the title Input: Mention that nfds computations assume the inputfds array is Input: Ensure clearTimer won't compute a lower nfds value than one our opened fds Oct 30, 2023
@NiLuJe
Copy link
Member Author

NiLuJe commented Oct 30, 2023

Open random fds between input.open calls in Kobo (or basically any device with multiple input.open calls) to repro, e.g.,

diff --git a/frontend/device/kobo/device.lua b/frontend/device/kobo/device.lua
index e2df4a95a..dd2f94322 100644
--- a/frontend/device/kobo/device.lua
+++ b/frontend/device/kobo/device.lua
@@ -816,12 +816,16 @@ function Kobo:init()
     -- And then handle the extra shenanigans if necessary.
     self:initEventAdjustHooks()
 
+    local f = io.open("/dev/null", "r")
+    local f2 = io.open("/dev/null", "w")
     -- Various HW Buttons, Switches & Synthetic NTX events
     self.ntx_fd = self.input.open(self.ntx_dev)
     -- Dedicated Power Button input device (if any)
     if self.power_dev then
         self.input.open(self.power_dev)
     end
+    f:close()
+    f2:close()
     -- Touch panel
     self.input.open(self.touch_dev)
     -- NOTE: On devices with a gyro, there may be a dedicated input device outputting the raw accelerometer data

Then strace -fittvTyY -s128 -e trace=_newselect -p $(pidof reader.lua | sed -e 's/ / -p /g') to watch the horror unfold ;).

@NiLuJe NiLuJe changed the title Input: Ensure clearTimer won't compute a lower nfds value than one our opened fds Input: Ensure clearTimer won't compute a lower nfds value than one of our opened fds Oct 30, 2023
@NiLuJe NiLuJe merged commit d1516bd into koreader:master Nov 1, 2023
2 checks passed
Frenzie added a commit to Frenzie/koreader that referenced this pull request Nov 2, 2023
Includes:

* Input: Ensure clearTimer won't compute a lower nfds value than one of our opened fds <koreader/koreader-base#1685>

Also includes various dependency bumps.

<koreader/koreader-base@16a856a...master>
Frenzie added a commit to koreader/koreader that referenced this pull request Nov 2, 2023
Includes:

* Input: Ensure clearTimer won't compute a lower nfds value than one of our opened fds <koreader/koreader-base#1685>

Also includes various dependency bumps.

<koreader/koreader-base@16a856a...master>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants