I've written a daemon that during development had its debugging information going to stderr (before it was fully 'daemonized'). Now the code is more mature, so the stderr has been redirected to /dev/null
with an freopen(2)
call. For the purposes of debugging, I'd really like to be able to connect to the server daemon, send a command and have it magically start sending the stderr
stream over the socket.
Is there a way (in a forked process) to do a 'dup(2)
' like operation on stderr
of the parent process to the child's socket file descriptor? A Linux only solution is acceptable.
There are great swaths of code that print to stderr
, that - for verification purposes - I would rather simply not touch.
If dup2
could do what I'm asking, this would work: Redirect STDOUT and STDERR to socket in C?