author | skidd13 |
Tue, 20 Nov 2007 14:11:19 +0000 | |
changeset 8428 | f8300c908bd9 |
parent 6928 | 44797333bcbf |
child 10429 | 1b99254f9607 |
permissions | -rw-r--r-- |
2186 | 1 |
/* $Id$ */ |
2 |
||
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
5835
diff
changeset
|
3 |
/** @file dedicated.cpp */ |
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
5835
diff
changeset
|
4 |
|
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
6 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
7 |
#ifdef ENABLE_NETWORK |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
8 |
|
2195
8960c86bf103
(svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents:
2186
diff
changeset
|
9 |
#if defined(UNIX) && !defined(__MORPHOS__) |
8960c86bf103
(svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents:
2186
diff
changeset
|
10 |
|
8960c86bf103
(svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents:
2186
diff
changeset
|
11 |
#include "openttd.h" |
2159
3b634157c3b2
(svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents:
1959
diff
changeset
|
12 |
#include "variables.h" |
781
9717ff353c17
(svn r1248) -Add: initial OS/2 support (read docs/ReadMe_OS2.txt) (orudge)
truelight
parents:
774
diff
changeset
|
13 |
|
2195
8960c86bf103
(svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents:
2186
diff
changeset
|
14 |
#include <sys/types.h> |
8960c86bf103
(svn r2710) Simplify dedicated server code a bit and don't compile it at all, if network support ist disabled
tron
parents:
2186
diff
changeset
|
15 |
#include <unistd.h> |
2177
73d67828ea5e
(svn r2691) Separate dedicated video driver and fix bemidi declarations
tron
parents:
2163
diff
changeset
|
16 |
|
6558
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
17 |
#if defined(SUNOS) && !defined(_LP64) && !defined(_I32LPx) |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
18 |
/* Solaris has, in certain situation, pid_t defined as long, while in other |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
19 |
* cases it has it defined as int... this handles all cases nicely. */ |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
20 |
# define PRINTF_PID_T "%ld" |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
21 |
#else |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
22 |
# define PRINTF_PID_T "%d" |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
23 |
#endif |
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
24 |
|
6573 | 25 |
void DedicatedFork() |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
26 |
{ |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
27 |
/* Fork the program */ |
1406
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1301
diff
changeset
|
28 |
pid_t pid = fork(); |
2d5baabe4046
(svn r1910) Move two variables out of variables.h which are only used locally
tron
parents:
1301
diff
changeset
|
29 |
switch (pid) { |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
30 |
case -1: |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
31 |
perror("Unable to fork"); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
32 |
exit(1); |
2294
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
33 |
|
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
34 |
case 0: { // We're the child |
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
35 |
FILE* f; |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
36 |
|
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
37 |
/* Open the log-file to log all stuff too */ |
2294
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
38 |
f = fopen(_log_file, "a"); |
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
39 |
if (f == NULL) { |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
40 |
perror("Unable to open logfile"); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
41 |
exit(1); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
42 |
} |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
43 |
/* Redirect stdout and stderr to log-file */ |
2294
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
44 |
if (dup2(fileno(f), fileno(stdout)) == -1) { |
1626 | 45 |
perror("Rerouting stdout"); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
46 |
exit(1); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
47 |
} |
2294
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
48 |
if (dup2(fileno(f), fileno(stderr)) == -1) { |
1626 | 49 |
perror("Rerouting stderr"); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
50 |
exit(1); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
51 |
} |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
52 |
break; |
2294
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
53 |
} |
a938c5ecb1c4
(svn r2818) Don't tell the world about a local variable which is only used once
tron
parents:
2195
diff
changeset
|
54 |
|
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
55 |
default: |
6451
7baba06b4b85
(svn r8862) -Cleanup: doxygen changes, again. Mostly @files missing tags and a few comments style.
belugas
parents:
5835
diff
changeset
|
56 |
/* We're the parent */ |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
57 |
printf("Loading dedicated server...\n"); |
6558
384bfec543ac
(svn r9035) -Fix [SunOS]: Solaris sometimes has pid_t defined as long. Fix warnings in those cases
truelight
parents:
6451
diff
changeset
|
58 |
printf(" - Forked to background with pid " PRINTF_PID_T "\n", pid); |
704
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
59 |
exit(0); |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
60 |
} |
a526dc96fbfc
(svn r1154) -Add: [Network] Forked dedicated server (start openttd with -Df) (GeniusDex)
truelight
parents:
702
diff
changeset
|
61 |
} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
62 |
#endif |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
63 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
64 |
#else |
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
65 |
|
6928
44797333bcbf
(svn r9568) -Documentation: doxygen and comment changes: Root of src is finally done. Now, time to start clearing as much as possible
belugas
parents:
6573
diff
changeset
|
66 |
/** Empty helper function call for NOT(UNIX and not MORPHOS) systems */ |
6573 | 67 |
void DedicatedFork() {} |
543
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
68 |
|
e3b43338096b
(svn r942) -Merged branch/network back into the trunk
truelight
parents:
diff
changeset
|
69 |
#endif /* ENABLE_NETWORK */ |