c++sshstdoutpipeinetd

Why does write() to pipe exit program when pipe writes to stdout?


I have a server application that writes to a popen("myCommand", "w") file descriptor in a separate thread and if the command passed to popen() results in any output to stdout or stderr, the my application exits. However, this is only an issue when my server application was invoked via inetd, if I used ssh to launch the server, it does not have this issue.

Similarly, when my server application reads from a popen("myCommand2", "r") file descriptor in a separate thread and if the command passed to popen() results in any output to stderr (stdin is going to my pipe), the application exits. Again, this only occurs with inetd summoning, not ssh summoning.


Solution

  • you need to close all existed fds of the process before open the pipe, then do i/o redirection. that's because if inetd, the process runs as a daemon.