Index: net.c
===================================================================
RCS file: /opt/cvs/frozen-bubble/server/net.c,v
retrieving revision 1.74
diff -u -r1.74 net.c
--- net.c	26 Oct 2006 18:49:58 -0000	1.74
+++ net.c	26 Oct 2006 21:02:16 -0000
@@ -89,6 +89,7 @@
 static int external_port = -1;
 
 static char* blacklisted_IPs = NULL;
+char* pidfile = NULL;
 
 static GList * conns = NULL;
 static GList * conns_prio = NULL;
@@ -495,6 +496,7 @@
         printf("     -z                        set that there is no preferred language for the server (see -a)\n");
         printf("     -g gracetime              set the gracetime after which a client with no network activity is terminated (in seconds, defaults to %d)\n", DEFAULT_GRACETIME);
         printf("     -b IP1,IP2,IP3..          set the list of blacklisted IPs\n");
+        printf("     -f pidfile                set the file in which the pid of the daemon must be written\n");
         printf("     -c conffile               specify the path of the configuration file\n");
 }
 
@@ -650,6 +652,9 @@
         case 'b':
                 blacklisted_IPs = asprintf_(",%s", param);
                 break;
+        case 'f':
+                pidfile = strdup(param);
+                break;
         default:
                 fprintf(stderr, "unrecognized option %c, ignoring\n", command);
         }
@@ -661,7 +666,7 @@
         int valone = 1;
 
         while (1) {
-                int c = getopt(argc, argv, "hn:lLp:u:t:o:c:dqH:P:a:zg:b:");
+                int c = getopt(argc, argv, "hn:lLp:u:t:o:c:dqH:P:a:zg:b:f:");
                 if (c == -1)
                         break;
                 
Index: net.h
===================================================================
RCS file: /opt/cvs/frozen-bubble/server/net.h,v
retrieving revision 1.10
diff -u -r1.10 net.h
--- net.h	31 Jul 2006 17:00:19 -0000	1.10
+++ net.h	26 Oct 2006 20:55:36 -0000
@@ -26,6 +26,7 @@
 extern const int proto_minor;
 
 extern char* current_command;
+extern char* pidfile;
 
 ssize_t send_line_log(int fd, char* dest_msg, char* inco_msg);
 ssize_t send_line_log_push(int fd, char* dest_msg);
Index: tools.c
===================================================================
RCS file: /opt/cvs/frozen-bubble/server/tools.c,v
retrieving revision 1.12
diff -u -r1.12 tools.c
--- tools.c	13 Sep 2006 17:52:02 -0000	1.12
+++ tools.c	26 Oct 2006 21:04:20 -0000
@@ -197,10 +197,23 @@
                 exit(EXIT_FAILURE);
         }
         if (pid > 0) {
+                // Save pid if needed
+                if (pidfile != NULL) {
+                        FILE* f = fopen(pidfile, "w");
+                        if (f == NULL) {
+                                l2(OUTPUT_TYPE_ERROR, "Cannot open pidfile '%s' for writing: %s", pidfile, strerror(errno));
+                        } else {
+                                char* pid_s = asprintf_("%d\n", pid);
+                                fwrite(pid_s, 1, strlen(pid_s), f);
+                                fclose(f);
+                                free(pid_s);
+                        }
+                }
                 // Need to register from a separate process because master server will test us
                 register_server();
                 exit(EXIT_SUCCESS);
         }
+
         
         // Don't stay orphan
         sid = setsid();

