31 #define CROSSFIRE_SERVER "/usr/stud/stieber/bin/server"
34 #define CROSSFIRE_TMPDIR "/usr/stud/stieber/crossfire/tmp/"
39 #define CRASH_COUNT 10
40 #define CRASH_INTERVAL 30
43 #define ERROR_SLEEP 30
47 #include <sys/unistd.h>
53 #include <sys/types.h>
54 #include <sys/socket.h>
55 #include <netinet/in.h>
68 if (write(
Pipe[1],
"", 1) != 1) {
79 struct protoent *protoent;
80 struct sockaddr_in insock;
83 memset(&insock, 0,
sizeof(insock));
85 if ((protoent = getprotobyname(
"udp")) == NULL) {
86 perror(
"Can't get protobyname");
89 if ((fd = socket(PF_INET, SOCK_DGRAM, protoent->p_proto)) == -1) {
90 perror(
"Can't create socket");
93 insock.sin_family = AF_INET;
94 insock.sin_port = htons((
unsigned short)13325);
95 if (bind(fd, (
struct sockaddr *)&insock,
sizeof(insock)) == -1) {
96 perror(
"Error on bind");
111 if (pipe(
Pipe) == 0) {
112 void (*OldHandler)(int);
116 switch (Server = fork()) {
129 struct timeval Timeout;
133 FD_SET(
Pipe[0], &Files);
135 Timeout.tv_sec = 5*60;
142 while (select(Max, &Files, NULL, NULL, &Timeout) == -1) {
143 if (errno != EINTR) {
144 perror(
"Error on select");
148 if (FD_ISSET(
Pipe[0], &Files)) {
151 waitpid(Server, NULL, 0);
152 printf(
"Server crash!\n");
154 }
else if (FD_ISSET(fd, &Files)) {
161 printf(
"Watchdog timeout!\n");
162 if (kill(Server, SIGKILL) != 0) {
163 perror(
"Error on kill");
169 waitpid(Server, NULL, 0);
172 signal(SIGCHLD, OldHandler);
void SignalHandler(int Unused)