]> git.sesse.net Git - cubemap/blobdiff - main.cpp
Support daemonizing.
[cubemap] / main.cpp
index 75c36d8d6a409c025d67e65ba092b67a0ba85d91..2c5ef67d90bb78b7c897040ce8d3710d6975c044 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -291,6 +291,16 @@ int main(int argc, char **argv)
        if (test_config) {
                exit(0);
        }
+       
+       // Ideally we'd like to daemonize only when we've started up all threads etc.,
+       // but daemon() forks, which is not good in multithreaded software, so we'll
+       // have to do it here.
+       if (config.daemonize) {
+               if (daemon(0, 0) == -1) {
+                       log_perror("daemon");
+                       exit(1);
+               }
+       }
 
 start:
        // Open logs as soon as possible.