Files @ r5857:4b1b2f7c805d
Branch filter:

Location: cpp/openttd-patchpack/source/src/dedicated.cpp

miham
(svn r8431) -Update: WebTranslator2 update to 2007-01-27 19:34:37
catalan - 4 fixed by arnaullv (4)
danish - 4 fixed, 2 changed by MiR (6)
dutch - 4 fixed by habell (4)
french - 4 fixed by glx (4)
german - 4 fixed by Neonox (4)
hungarian - 4 fixed by miham (4)
korean - 4 fixed, 4 changed by Nios (4), leejaeuk5 (4)
lithuanian - 2 changed by Domas (2)
polish - 4 fixed by meush (4)
portuguese - 4 fixed by izhirahider (4)
simplified_chinese - 4 fixed by Fishingsnow (4)
slovenian - 4 fixed, 410 changed by Necrolyte (414)
ukrainian - 34 fixed, 49 changed by mad (79), znikoz (4)
/* $Id$ */

#include "stdafx.h"

#ifdef ENABLE_NETWORK

#if defined(UNIX) && !defined(__MORPHOS__)

#include "openttd.h"
#include "variables.h"

#include <sys/types.h>
#include <unistd.h>

void DedicatedFork(void)
{
	/* Fork the program */
	pid_t pid = fork();
	switch (pid) {
		case -1:
			perror("Unable to fork");
			exit(1);

		case 0: { // We're the child
			FILE* f;

			/* Open the log-file to log all stuff too */
			f = fopen(_log_file, "a");
			if (f == NULL) {
				perror("Unable to open logfile");
				exit(1);
			}
			/* Redirect stdout and stderr to log-file */
			if (dup2(fileno(f), fileno(stdout)) == -1) {
				perror("Rerouting stdout");
				exit(1);
			}
			if (dup2(fileno(f), fileno(stderr)) == -1) {
				perror("Rerouting stderr");
				exit(1);
			}
			break;
		}

		default:
			// We're the parent
			printf("Loading dedicated server...\n");
			printf("  - Forked to background with pid %d\n", pid);
			exit(0);
	}
}
#endif

#else

void DedicatedFork(void) {}

#endif /* ENABLE_NETWORK */