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
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>
...
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 forUV_TTY
andUV_NAMED_PIPE
; any other type produces an error and no console is initiated. 2) ForUV_TTY
,uv_tty_init()
is used as before. 3) ForUV_NAMED_PIPE
,uv_pipe_init()
anduv_pipe_oepn()
are used to initalise/open the pipe. 4) Separate members are used to store the respectiveuv_tty_t
(m_tty
, not changed) anduv_pipe_t
(m_stdin_pipe
) handles;m_stdin_handle
is used as auv_handle_t*
reference to whichever of these was actually used. 5) Code which would needs to use the active handle now usesm_stdin_handle
, e.g.uv_read_start()
anduv_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:
Manually type
exit
in console:Using named pipe
When used with a service/socket configuration, log output:
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: