I have a situation where I am spawning a child process that will listen on a socket for RPC calls. My program that is starting the daemon will spawn the process and then attempt to connect on the socket to make sure the process was successful. If it was not successful I want to grab the stderr and print it so that the user can see why the process failed. When I spawn the process I set stderr to Piped so that I can capture it in case there is a failure.
The problem is that, when the daemon succeeds, I want my program to exit and let the daemon run in the background. Because I have set stderr to Piped, though, when my program exits, the child process stalls because, I'm assuming, the stderr pipe was broken.
Everything works fine if I set stderr to null, but the problem with that is that I can't get the error message if the daemon fails in that case.
I guess I can make the daemon process log to a file instead of stderr so that I can get the output that way if that is my only option, but I wanted to make sure I can't do it how I've described first.
Note: I'm the one writing the daemon so I'm not sure if it is my fault that the daemon freezes when the pipe is broken. All of the output is generated with
eprintln!. I would think that the daemon would be panicking if I
eprintln!on the broken pipe, but the process is still visible in htop so I don't know exactly what is going on.