Xinetd:从服务器脚本结束连接

Xinetd:从服务器脚本结束连接

我有一个 xinetd 服务,它是一个脚本,输出由远程主机上的 netcat 读取。

但是,当服务器上的脚本退出时,netcat 仍然等待,但不会执行任何操作。如何关闭与服务器的连接或发送“文件结尾”或类似的内容?

我的服务:

service myservice
{
   port            = 2222
   socket_type     = stream
   protocol        = tcp
   wait            = no
   server          = /opt/myscript.sh
   user            = root
   disable         = no
}

我的脚本:

#!/bin/sh

##Example:
echo "Hello World!"

网络猫输出:

[me@mypc]# nc myhost 2222
Hello World!
*blinking cursor forever*

输出(尾部)strace nc myhost 2222

connect(3, {sa_family=AF_INET6, sin6_port=htons(2222), inet_pton(AF_INET6, "::1", &sin6_addr), sin6_flowinfo=htonl(0), sin6_scope_id=0}, 28) = -1 EINPROGRESS (Operation now in progress)
select(4, [3], [3], [3], {tv_sec=10, tv_usec=0}) = 1 (out [3], left {tv_sec=9, tv_usec=999997})
getsockopt(3, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
select(4, [0 3], [], [], NULL)          = 1 (in [3])
recvfrom(3, "Hello World!\n", 8192, 0, 0x████████████, [128->0]) = 13
write(1, "Hello World!\n", 13Hello World!
)          = 13
select(4, [0 3], [], [], NULL)          = 1 (in [3])
recvfrom(3, "", 8192, 0, 0x████████████, [128->0]) = 0
close(1)                                = 0
select(3, [0], [], [], NULL

它就停在那里。然后我必须 ^C 所以最后一行实际上看起来像:

select(3, [0], [], [], NULL^Cstrace: Process 6232 detached
 <detached ...>

TCP转储:

IP6 localhost.36082 > localhost.myservice: Flags [S], seq 3879998021, win 43690, options [mss 65476,sackOK,TS val 3800136568 ecr 0,nop,wscale 7], length 0
IP6 localhost.myservice > localhost.36082: Flags [S.], seq 3455514626, ack 3879998022, win 43690, options [mss 65476,sackOK,TS val 3800136568 ecr 3800136568,nop,wscale 7], length 0
IP6 localhost.36082 > localhost.myservice: Flags [.], ack 1, win 342, options [nop,nop,TS val 3800136568 ecr 3800136568], length 0
IP6 localhost.myservice > localhost.36082: Flags [P.], seq 1:14, ack 1, win 342, options [nop,nop,TS val 3800136571 ecr 3800136568], length 13
IP6 localhost.36082 > localhost.myservice: Flags [.], ack 14, win 342, options [nop,nop,TS val 3800136571 ecr 3800136571], length 0
IP6 localhost.myservice > localhost.36082: Flags [F.], seq 14, ack 1, win 342, options [nop,nop,TS val 3800136571 ecr 3800136571], length 0
IP6 localhost.36082 > localhost.myservice: Flags [.], ack 15, win 342, options [nop,nop,TS val 3800136612 ecr 3800136571], length 0

相关内容