SChernykh / p2pool

Decentralized pool for Monero mining
GNU General Public License v3.0
1.07k stars 128 forks source link

Allow named pipe as stdin #238

Closed twlee79 closed 1 year ago

twlee79 commented 1 year ago

Fixes #237 to allow stdin to be a named pipe in addition to TTY.

Implementation details

1) uv_guess_handle(0) is used to determine the stdin handle type, with alternative handling for UV_TTY and UV_NAMED_PIPE; any other type produces an error and no console is initiated. 2) For UV_TTY, uv_tty_init() is used as before. 3) For UV_NAMED_PIPE, uv_pipe_init() and uv_pipe_oepn() are used to initalise/open the pipe. 4) Separate members are used to store the respective uv_tty_t (m_tty, not changed) and uv_pipe_t (m_stdin_pipe) handles; m_stdin_handle is used as a uv_handle_t* reference to whichever of these was actually used. 5) Code which would needs to use the active handle now uses m_stdin_handle, e.g. uv_read_start() and uv_close().

Testing

Testing done in Linux; not tested in Windows but I can see no reason that it won't work.

Interactive shell using TTY

When run in interactive shell, console correctly captured, log output:

2023-03-07 21:11:55.3621 ConsoleCommands uv_guess_handle, return 14
2023-03-07 21:11:55.3621 ConsoleCommands processing stdin as UV_TTY
2023-03-07 21:11:55.3621 ConsoleCommands event loop started

Manually type exit in console:

2023-03-07 21:12:55.8520 ConsoleCommands event loop stopped
2023-03-07 21:12:55.8521 ConsoleCommands stopped
...

Using named pipe

When used with a service/socket configuration, log output:

2023-03-07 12:31:35.5131 ConsoleCommands uv_guess_handle returned 7
2023-03-07 12:31:35.5131 ConsoleCommands processing stdin as UV_NAMED_PIPE
2023-03-07 12:31:35.5133 ConsoleCommands event loop started

With ListenFIFO=/tmp/p2pool.stdin in socket unit and a correctly configured service, issue command by writing to file: echo "status" > /tmp/p2pool.stdin; sleep 1; tail p2pool.log -n 35, output:


Monero node               = <redacted>
Main chain height         = <redacted>
Main chain hashrate       = <redacted>
Side chain ID             = <redacted>
...
twlee79 commented 1 year ago

Suggested changes made to 3df7430.

SChernykh commented 1 year ago

Thanks! I'll merge after CI checks finish.