Skip to content

Commit f6d0eac

Browse files
committed
Replace threat handler file with named pipe
This was causing problems in MacOS for some reason. The named pipe is probably a better solution in general, but it's strange that it happened at all.
1 parent 20d38b3 commit f6d0eac

File tree

5 files changed

+21
-30
lines changed

5 files changed

+21
-30
lines changed

src/threads/thread_controller.sh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,22 @@ PURR_THREAD_START="purr_thread_start"
1919
PURR_THREAD_STOP="purr_thread_stop"
2020

2121
# The background handler is responsible for starting and killing
22-
# the stream threads. It uses the purr_background_handler_cache
22+
# the stream threads. It uses the thread_io_pipe
2323
# as a one-way communication between the core process and itself,
2424
# and then handles asynchronous processes related to the stream threads.
2525
__purr_background_handler() {
2626
__purr_start_streams
2727

28-
while read line; do
29-
if [ $line = "$PURR_THREAD_STOP" ]; then
30-
__purr_cleanup_streams
31-
elif [ $line = "$PURR_THREAD_START" ]; then
32-
__purr_start_streams
33-
elif [ $line = "$PURR_THREAD_CLEANUP" ]; then
34-
__purr_cleanup_streams
35-
exit 0
28+
while true; do
29+
if read line <$thread_io_pipe; then
30+
if [ $line = "$PURR_THREAD_STOP" ]; then
31+
__purr_cleanup_streams
32+
elif [ $line = "$PURR_THREAD_START" ]; then
33+
__purr_start_streams
34+
elif [ $line = "$PURR_THREAD_CLEANUP" ]; then
35+
__purr_cleanup_streams
36+
exit 0
37+
fi
3638
fi
37-
done < <(/usr/bin/tail -f $purr_background_handler_cache 2>/dev/null)
39+
done
3840
}

src/threads/thread_interface.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
# limitations under the License.
1616

1717
__purr_start_stream() {
18-
echo "$PURR_THREAD_START" >>$purr_background_handler_cache
18+
echo "$PURR_THREAD_START" >$thread_io_pipe
1919
}
2020

2121
__purr_thread_stop_stream() {
22-
echo "$PURR_THREAD_STOP" >>$purr_background_handler_cache
22+
echo "$PURR_THREAD_STOP" >$thread_io_pipe
2323
}
2424

2525
__purr_cleanup() {
2626
local dir_name=$1
2727

2828
# Send a message to the background threads that they need to die.
29-
if [ -f $purr_background_handler_cache ]; then
30-
echo "$PURR_THREAD_CLEANUP" >>$purr_background_handler_cache
29+
if [ -p $thread_io_pipe ]; then
30+
echo "$PURR_THREAD_CLEANUP" >$thread_io_pipe
3131
fi
3232

3333
# Delete all of the cached state files.

src/threads/thread_setup.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ __purr_create_files() {
7070
purr_preview_command_cache="$dir_name/preview-command-cache.purr"
7171
/usr/bin/touch $purr_preview_command_cache
7272

73-
# File to communicate with the background handler.
74-
purr_background_handler_cache="$dir_name/background-handler-IO.purr"
75-
/usr/bin/touch $purr_background_handler_cache
73+
# Pipe to communicate with the background handler.
74+
thread_io_pipe=$dir_name/thread_io_pipe
75+
mkfifo $thread_io_pipe
7676

7777
# File to communicate what the accept command intent was.
7878
purr_accept_command_cache="$dir_name/purr_accept_command_cache.purr"

src/ui/ui_strings.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,5 +150,5 @@ set_header_serial="echo \"$stream_serial_msg\" >| $purr_stream_header_cache;"
150150
hint_preview_window="top,70%,nohidden,wrap,+200/2"
151151
hint_preview_window_hidden="top,70%,hidden,wrap,+200/2"
152152

153-
start_stream="echo \"$PURR_THREAD_START\" >> $purr_background_handler_cache;"
154-
stop_stream="echo \"$PURR_THREAD_STOP\" >> $purr_background_handler_cache;"
153+
start_stream="echo \"$PURR_THREAD_START\" >$thread_io_pipe;"
154+
stop_stream="echo \"$PURR_THREAD_STOP\" >$thread_io_pipe;"

tests/validators/file_validator.sh

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ validate_runtime_purr_files() {
2727
grep -q -- "Verbose" $dir_name/stream-header.purr
2828
echo "Input stream is verbose."
2929

30-
# Is the handler processing IO?
31-
if [ -s $dir_name/background-handler-IO.purr ]; then
32-
return 1
33-
else
34-
echo "Thread IO working."
35-
fi
36-
3730
# Did we start on the instruction preview? And it is visible?
3831
grep -q -- "instruction" $dir_name/preview-command-cache.purr
3932
grep -q -- "nohidden" $dir_name/preview-visibility-cache.purr
@@ -57,10 +50,6 @@ validate_runtime_purr_files() {
5750
validate_exit_time_purr_files() {
5851
dir_name=$1
5952

60-
# Has the handler been told to clean up?
61-
grep -q -- "purr_thread_cleanup" $dir_name/background-handler-IO.purr
62-
echo "Threads are in cleanup."
63-
6453
# Did the handler actually do clean up?
6554
if [ ! -f $dir_name/verbose-input-cache.purr ]; then
6655
echo "Threads did actually cleanup."

0 commit comments

Comments
 (0)