вилка socat приводит к зависанию netcat

#netcat #socat

#netcat #socat

Вопрос:

Я наблюдаю поведение, socat которого раньше не видел.

Я запускаю socat в терминале с помощью команды (под Debian 10)

 # socat tcp-listen:8888,reuseaddr,fork exec:"whoami"
 

и подключитесь к 8888 / tcp с помощью netcat :

 $ nc localhost 8888
root


Ncat: Broken pipe.
 

При подключении к сервису я правильно получаю вывод whoami , но если я не введу новую строку дважды, netcat зависает.

Это ожидаемое поведение? Вместо этого я бы ожидал netcat выхода и вернул мне приглашение.

Добавление -d -d -d к socat команде дает следующие строки:

 (...)
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*/
 

Ответ №1:

Я наблюдаю поведение, socat которого раньше не видел.

Вы наблюдаете нормальное поведение nc , которое заключается в выводе полученных данных, а также отправке входных данных; если вы не хотите nc читать из стандартного интерфейса, есть опция -d .