tron@2186: /* $Id$ */ tron@2186: belugas@6451: /** @file dedicated.cpp */ belugas@6451: 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: truelight@6558: #if defined(SUNOS) && !defined(_LP64) && !defined(_I32LPx) truelight@6558: /* Solaris has, in certain situation, pid_t defined as long, while in other truelight@6558: * cases it has it defined as int... this handles all cases nicely. */ truelight@6558: # define PRINTF_PID_T "%ld" truelight@6558: #else truelight@6558: # define PRINTF_PID_T "%d" truelight@6558: #endif truelight@6558: rubidium@6573: void DedicatedFork() 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: belugas@6451: /* We're the parent */ truelight@704: printf("Loading dedicated server...\n"); truelight@6558: printf(" - Forked to background with pid " PRINTF_PID_T "\n", pid); truelight@704: exit(0); truelight@704: } truelight@704: } truelight@543: #endif truelight@543: truelight@543: #else truelight@543: belugas@6928: /** Empty helper function call for NOT(UNIX and not MORPHOS) systems */ rubidium@6573: void DedicatedFork() {} truelight@543: truelight@543: #endif /* ENABLE_NETWORK */