tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: How to properly daemonize?
On Fri, 14 Jul 2017 18:25:32 +0200
Edgar Fuß <ef%math.uni-bonn.de@localhost> wrote:
> what exactly is the point (save sanity) of redirecting stdXXX to /dev/null?
I once had a nasty bug in a custom daemon that took several months to
track down, that I solved by redirecting stdxxx to /dev/null:
When a new client connected over a TCP socket, a file descriptor would
be allocated for it. As stdin, stdout, and stderr were all closed in
advance, these descriptor numbers would be available, and occasionally
standard out would be used as a client socket.
A stray printf() for debugging was buried deep in the code. On rare
cases, it would run, squirting random text into that client socket,
causing protocol errors and a disconnect.
Reproducing the problem was a severe pain, because running the daemon
in the foreground meant stdout was still there and working normally. And
even daemonized, it was rare and random, as a client had to get
standard out as it's socket and then hit the debugging routine.
I would describe the point as being: not all code is perfect, and it's
a cheap guardrail.
--
Aaron B. <aaron%zadzmo.org@localhost>
Home |
Main Index |
Thread Index |
Old Index