]> code.citadel.org Git - citadel.git/blobdiff - citadel/ctdlsvc.c
* When enumerating rooms in the drop-down list
[citadel.git] / citadel / ctdlsvc.c
index 69f60327c898f226a23a7468d5e5294ba4ecddca..ed06ecd6347ad3e88fc8312a4c561db7b170b795 100644 (file)
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <signal.h>
+#include <fcntl.h>
+#include <string.h>
 
 char *pidfilename = NULL;
 pid_t current_child = 0;
@@ -31,6 +34,7 @@ int main(int argc, char **argv)
        pid_t child = 0;
        int status = 0;
        FILE *fp;
+//     int nullfd;
 
        --argc;
        ++argv;
@@ -44,8 +48,21 @@ int main(int argc, char **argv)
                exit(1);
        }
 
-       close(1);
-       close(2);
+       /* Close stdin/stdout/stderr and replace them with /dev/null.
+        * We don't just call close() because we don't want these fd's
+        * to be reused for other files.
+        */
+/*
+       nullfd = open("/dev/null", O_RDWR);
+       if (nullfd < 0) {
+               fprintf(stderr, "/dev/null: %s\n", strerror(errno));
+               exit(2);
+       }
+       dup2(nullfd, 0);
+       dup2(nullfd, 1);
+       dup2(nullfd, 2);
+       close(nullfd);
+*/
        signal(SIGHUP, SIG_IGN);
        signal(SIGINT, SIG_IGN);
        signal(SIGQUIT, SIG_IGN);
@@ -59,6 +76,13 @@ int main(int argc, char **argv)
                }
                exit(0);
        }
+       
+       setsid();
+       chdir("/");
+       umask(0);
+        freopen("/dev/null", "r", stdin);
+        freopen("/dev/null", "w", stdout);
+        freopen("/dev/null", "w", stderr);
 
        do {
                current_child = fork();