Trying to communicate with external process without using insecure environment.
Go to file
whosit 6e5e51bd2c add some spaghetty code that tries using async for reading 2023-06-06 10:03:04 +03:00
README.md add some spaghetty code that tries using async for reading 2023-06-06 10:03:04 +03:00
init.lua add some spaghetty code that tries using async for reading 2023-06-06 10:03:04 +03:00
process.py add some spaghetty code that tries using async for reading 2023-06-06 10:03:04 +03:00

README.md

This is just a proof of concept for a way of communicating with an external process using unix fifo files (created by mkfifo() call).

Main point: this does not require insecure environment. It only uses default "safe" io.open.

Usage:

First, cd into world directory and launch process.py:

python ../../mods/file_fifo_test/process.py

This will create in the current working directory a pair of FIFO files for input and output.

Then start the server. Exchange should begin as soon as both ends of FIFO are open. Exchange is done in a lock-step fashion at the moment, but maybe using async env can fix that (see Problem 2).

Problems:

  1. If output fifo is closed on the other end, then output_fifo:write() will crash the MT. I don't see a way to check if it's safe to call write or not.

  2. Default lua io module does not provide ways to make the read() from fifo non-blocking.

Solutions:

  1. This patch applied minetest will prevent crashing caused by writing to closed pipe:
--- a/src/porting.cpp
+++ b/src/porting.cpp
@@ -122,6 +122,7 @@ void signal_handler_init(void)
 {
        (void)signal(SIGINT, signal_handler);
        (void)signal(SIGTERM, signal_handler);
+        (void)signal(SIGPIPE, SIG_IGN); // ignores SIGPIPE to not terminate on write to a closed fifo
 }

 #else // _WIN32

It just ignores SIGPIPE, which should be fine to do.

  1. It's possible to do read() in async environment.