Openvario / sensord

Daemon to poll air data from Openvario sensorboard
6 stars 11 forks source link

Do not leave stdout closed in daemon mode #27

Closed kedder closed 4 years ago

kedder commented 4 years ago

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.

hpmax commented 4 years ago

So this should redirect any write to stdout in daemonized form to null?

kedder commented 4 years ago

No, not to null, to fp_console.

hpmax commented 4 years ago

Line 429: setbuf(fp_console, NULL);

Looks like fp_console is set to NULL.

kedder commented 4 years ago

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.

hpmax commented 4 years ago

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.