Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00012 #include "stdafx.h"
00013
00014 #ifdef ENABLE_NETWORK
00015
00016 char *_log_file = NULL;
00017 FILE *_log_fd = NULL;
00018
00019 #if defined(UNIX) && !defined(__MORPHOS__)
00020
00021 #include <unistd.h>
00022
00023 #if (defined(SUNOS) && !defined(_LP64) && !defined(_I32LPx)) || defined(__HAIKU__)
00024
00025
00026
00027
00028 # define PRINTF_PID_T "%ld"
00029 #else
00030 # define PRINTF_PID_T "%d"
00031 #endif
00032
00033 void DedicatedFork()
00034 {
00035
00036 pid_t pid = fork();
00037 switch (pid) {
00038 case -1:
00039 perror("Unable to fork");
00040 exit(1);
00041
00042 case 0: {
00043
00044 _log_fd = fopen(_log_file, "a");
00045 if (_log_fd == NULL) {
00046 perror("Unable to open logfile");
00047 exit(1);
00048 }
00049
00050 if (dup2(fileno(_log_fd), fileno(stdout)) == -1) {
00051 perror("Rerouting stdout");
00052 exit(1);
00053 }
00054 if (dup2(fileno(_log_fd), fileno(stderr)) == -1) {
00055 perror("Rerouting stderr");
00056 exit(1);
00057 }
00058 break;
00059 }
00060
00061 default:
00062
00063 printf("Loading dedicated server...\n");
00064 printf(" - Forked to background with pid " PRINTF_PID_T "\n", pid);
00065 exit(0);
00066 }
00067 }
00068 #endif
00069
00070 #else
00071
00073 void DedicatedFork() {}
00074
00075 #endif