The fork
s in a daemon play an important role for the daemon to work as expected as mentioned in the answers to this question.
If the only problems are due to multiple processes logging the fork should not be a problem since you don't have to log befor you have done the forks. Besides the parent processes of these forks are going to terminate anyway.
If termination of the parents are problematic, you could maybe postpone initialization of the boost logging until after the second fork
.
If boost logging is always initialized before main the solution might need to be to make sure that the fork
s happen even before that, that is to manage to make the code run befor boost logging initialization - which will need a implementation specific solution.
For an implementation independent (other than posix support) solution for the worst case scenario is to use execl
to make sure that the actual daemon doesn't fork, that you in effect use one program that does the daemonizing thing which don't use boost logging and one program that's the proper daemon program. If it's not a big problem with fork if you don't use the logging fascility (after the fork) you could even do this with one single executable and differ the behaviour from command line switches. In pseudo code:
int main() {
parse_command_line();
if( no_daemonize_flag() )
run_daemon()
else {
daemonize();
execl("/path/to/daemon", "/path/to/daemon", "--no-daemonize", ...other flags..., NULL);
}
}