我在socat中观察到了一种我以前从未见过的行为。
我在终端中使用以下命令运行socat (在Debian10下)
# socat tcp-listen:8888,reuseaddr,fork exec:"whoami"并使用netcat连接到8888/tcp:
$ nc localhost 8888
root
Ncat: Broken pipe.在连接到服务时,我正确地接收到了whoami的输出,但是除非我输入两次新行,否则netcat挂起。
这是预期的行为吗?相反,我希望netcat退出并返回提示符。
在socat命令中添加-d -d -d将显示以下几行:
(...)
socat[15813] N execvp'ing "whoami"
socat[15812] N childdied(): handling signal 17
socat[15812] I exec'd process 15813 on socket 1 terminated
socat[15795] I childdied(signum=17)
socat[15812] I waitpid(): child 15813 exited with status 0
socat[15812] I childdied() finished
socat[15812] I transferred 7 bytes from 5 to 6
socat[15795] I waitpid(-1, {}, WNOHANG): No child processes
socat[15812] N socket 2 (fd 5) is at EOF
socat[15812] I shutdown(6, 1)
socat[15812] I terminated child did not leave data for us
socat[15812] I poll timed out (no data within 0.500000 seconds)
socat[15812] I shutdown(6, 2)
socat[15812] I shutdown(5, 2)
socat[15812] N exiting with status 0
socat[15795] N childdied(): handling signal 17
socat[15795] I childdied(signum=17)
socat[15795] I childdied(17): cannot identify child 15812
socat[15795] I waitpid(): child 15812 exited with status 0
socat[15795] I waitpid(-1, {}, WNOHANG): No child processes
socat[15795] I childdied() finished$ socat -V
socat by Gerhard Rieger and contributors - see www.dest-unreach.org
socat version 1.7.3.2 on Nov 19 2017 13:56:10
running on Linux version #1 SMP Debian 5.8.10-1~bpo10+1 (2020-09-26), release 5.8.0-0.bpo.2-amd64, machine x86_64
features:
#define WITH_STDIO 1
#define WITH_FDNUM 1
#define WITH_FILE 1
#define WITH_CREAT 1
#define WITH_GOPEN 1
#define WITH_TERMIOS 1
#define WITH_PIPE 1
#define WITH_UNIX 1
#define WITH_ABSTRACT_UNIXSOCKET 1
#define WITH_IP4 1
#define WITH_IP6 1
#define WITH_RAWIP 1
#define WITH_GENERICSOCKET 1
#define WITH_INTERFACE 1
#define WITH_TCP 1
#define WITH_UDP 1
#define WITH_SCTP 1
#define WITH_LISTEN 1
#define WITH_SOCKS4 1
#define WITH_SOCKS4A 1
#define WITH_PROXY 1
#define WITH_SYSTEM 1
#define WITH_EXEC 1
#undef WITH_READLINE
#define WITH_TUN 1
#define WITH_PTY 1
#define WITH_OPENSSL 1
#undef WITH_FIPS
#define WITH_LIBWRAP 1
#define WITH_SYCLS 1
#define WITH_FILAN 1
#define WITH_RETRY 1
#define WITH_MSGLEVEL 0 /*debug*/发布于 2021-04-04 23:31:55
我用
socat观察到了一种我以前从未见过的行为。
观察nc的正常行为,即输出接收到的数据并发送输入数据;如果不希望nc从标准输入中读取数据,可以使用-d选项。
https://stackoverflow.com/questions/66842912
复制相似问题