tron@2186: /* $Id$ */ tron@2186: truelight@543: #include "stdafx.h" truelight@543: truelight@543: #ifdef ENABLE_NETWORK truelight@543: tron@2195: #if defined(UNIX) && !defined(__MORPHOS__) tron@2195: tron@2195: #include "openttd.h" tron@2159: #include "variables.h" truelight@781: tron@2195: #include tron@2195: #include tron@2177: darkvater@774: void DedicatedFork(void) truelight@704: { truelight@704: /* Fork the program */ tron@1406: pid_t pid = fork(); tron@1406: switch (pid) { truelight@704: case -1: truelight@704: perror("Unable to fork"); truelight@704: exit(1); tron@2294: tron@2294: case 0: { // We're the child tron@2294: FILE* f; truelight@704: truelight@704: /* Open the log-file to log all stuff too */ tron@2294: f = fopen(_log_file, "a"); tron@2294: if (f == NULL) { truelight@704: perror("Unable to open logfile"); truelight@704: exit(1); truelight@704: } truelight@704: /* Redirect stdout and stderr to log-file */ tron@2294: if (dup2(fileno(f), fileno(stdout)) == -1) { pasky@1626: perror("Rerouting stdout"); truelight@704: exit(1); truelight@704: } tron@2294: if (dup2(fileno(f), fileno(stderr)) == -1) { pasky@1626: perror("Rerouting stderr"); truelight@704: exit(1); truelight@704: } truelight@704: break; tron@2294: } tron@2294: truelight@704: default: truelight@704: // We're the parent truelight@704: printf("Loading dedicated server...\n"); tron@1406: printf(" - Forked to background with pid %d\n", pid); truelight@704: exit(0); truelight@704: } truelight@704: } truelight@543: #endif truelight@543: truelight@543: #else truelight@543: darkvater@774: void DedicatedFork(void) {} truelight@543: truelight@543: #endif /* ENABLE_NETWORK */