Skip to content

improve daemon mode - #90

Merged
NiLuJe merged 1 commit into
NiLuJe:masterfrom
benoit-pierre:pr/fifo_before_fork
Aug 6, 2026
Merged

improve daemon mode#90
NiLuJe merged 1 commit into
NiLuJe:masterfrom
benoit-pierre:pr/fifo_before_fork

Conversation

@benoit-pierre

@benoit-pierre benoit-pierre commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Ensure fifo is created before forking: avoids possible race condition when accessing the fifo immediately after starting fbink.


This change is Reviewable

Ensure fifo is created before forking: avoids possible race condition
when accessing the fifo immediately after starting fbink.
@sonarqubecloud

sonarqubecloud Bot commented Aug 5, 2026

Copy link
Copy Markdown

@benoit-pierre

Copy link
Copy Markdown
Contributor Author

Example, on kindle, with this patch to koreader.sh to test a workaround for fbink crashing (cf. koreader/koreader#15802):

--- a/platform/kindle/koreader.sh
+++ b/platform/kindle/koreader.sh
@@ -138,6 +138,11 @@ ko_update_check() {
         export FBINK_NAMED_PIPE="/tmp/koreader.fbink"
         rm -f "${FBINK_NAMED_PIPE}"
         FBINK_PID="$(/var/tmp/fbink --daemon 1 %KOREADER% -q -y -6 -P 0)"
+        # Open a handle to the fifo ourselves too: this prevent tar checkpointing
+        # calls from hanging when writing to the fifo if fbink crashed (even with
+        # no one reading from the fifo, its buffer should still be big enough to
+        # never be full either).
+        exec 3<>"${FBINK_NAMED_PIPE}"
         # NOTE: To avoid blowing up when an executable get truncated during use, we copy our binaries to the system's
         # tmpfs, and run them from there (c.f., #4602)...  This is most likely a side-effect of the weird fuse overlay
         # being used for /mnt/us (vs. the real vfat on /mnt/base-us), which we cannot use because it's been mounted
@@ -167,6 +172,9 @@ ko_update_check() {
             eips_print_bottom_centered "KOReader may fail to function properly" 1
         fi
         rm -f /tmp/package.index "${NEWUPDATE}" # always purge newupdate to prevent update loops
+        # Fifo cleanup: close our handle, and unlink the path too (in case fbink crashed).
+        exec 3>&-
+        rm -f "${FBINK_NAMED_PIPE}"
         unset FBINK_NAMED_PIPE FBINK_PID
         # Ensure everything is flushed to disk before we restart. This *will* stall for a while on slow storage!
         sync

Without the patch, or a sleep after starting, fbink fails to daemonize successfully.

@NiLuJe NiLuJe left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Huh. Okay!

@NiLuJe
NiLuJe merged commit 886f25f into NiLuJe:master Aug 6, 2026
5 of 6 checks passed
@benoit-pierre
benoit-pierre deleted the pr/fifo_before_fork branch August 6, 2026 00:51
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