Skip to content

Commit

Permalink
Fix std* files not being redirected when daemonising
Browse files Browse the repository at this point in the history
This could occur when built with assertions removed.

Closes #2708. Thanks to ckoehne.
  • Loading branch information
ralight committed Dec 16, 2022
1 parent ec173ff commit 62b6836
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions ChangeLog.txt
Expand Up @@ -3,6 +3,8 @@ Broker:
disappearing.
- Fix some retained topic memory not being cleared immediately after used.
- Fix error handling related to the `bind_interface` option.
- Fix std* files not being redirected when daemonising, when built with
assertions removed. Closes #2708.

2.0.15 - 2022-08-16
===================
Expand Down
15 changes: 12 additions & 3 deletions src/mosquitto.c
Expand Up @@ -160,9 +160,18 @@ static void mosquitto__daemonise(void)
exit(1);
}

assert(freopen("/dev/null", "r", stdin));
assert(freopen("/dev/null", "w", stdout));
assert(freopen("/dev/null", "w", stderr));
if(!freopen("/dev/null", "r", stdin)){
log__printf(NULL, MOSQ_LOG_ERR, "Error whilst daemonising (%s): %s", "stdin", strerror(errno));
exit(1);
}
if(!freopen("/dev/null", "w", stdout)){
log__printf(NULL, MOSQ_LOG_ERR, "Error whilst daemonising (%s): %s", "stdout", strerror(errno));
exit(1);
}
if(!freopen("/dev/null", "w", stderr)){
log__printf(NULL, MOSQ_LOG_ERR, "Error whilst daemonising (%s): %s", "stderr", strerror(errno));
exit(1);
}
#else
log__printf(NULL, MOSQ_LOG_WARNING, "Warning: Can't start in daemon mode in Windows.");
#endif
Expand Down

0 comments on commit 62b6836

Please sign in to comment.