Closed kedder closed 4 years ago
So this should redirect any write to stdout in daemonized form to null?
No, not to null, to fp_console
.
Line 429: setbuf(fp_console, NULL);
Looks like fp_console is set to NULL.
No. Please see the docs for setbuf().
Specifies the buffer to be used by the stream for I/O operations, which becomes a fully buffered stream. Or, alternatively, if buffer is a null pointer, buffering is disabled for the stream, which becomes an unbuffered stream.
Okay, this is an aspect of C I've never seen before, but it does seem to positively set stdout, so it doesn't end up writing to the wrong stream.
When sensord daemonizes, it closes stderr and stdout files. It then assigns stderr to be a log file. stdout is kept closed, however sensord still tries to output to it with regular
printf
statements.This messes communication with
/dev/i2c-1 device
, which is being assigned file descriptor "1", typically used by stdout.Assign stdout to log file, so that prints are routed to the right place.
Fixes #24.