Open g-rden opened 6 months ago
Interesting. Maybe we should have some kind of logger function? Not sure how to best handle this, or if we should ever close stdout.
There is a logger function that logs to the mentioned logfile. The unintentional thing is that logfile by default is set stdout.
We could also move the usage stats above fclose(), so stdout does not get used after potentially closing it.
logfile, which by default is stdout, gets closed https://github.com/emikulic/darkhttpd/blob/64fe4ccbcf89e1f7f1e7b61954ff60d6404d636c/darkhttpd.c#L2994 and later we want to write to it https://github.com/emikulic/darkhttpd/blob/64fe4ccbcf89e1f7f1e7b61954ff60d6404d636c/darkhttpd.c#L3030-L3037
This results in undefined behavoir: https://pubs.opengroup.org/onlinepubs/9699919799/functions/fclose.html
I am pretty sure that it should be
if (logfile_name != NULL) fclose(logfile);
anyway. If logfile where NULL, the program would have exited already. But since this changes what gets printed to console, I open this issue instead of a PRThere are multiple options: