* purge ctdlsvc.c
authorWilfried Göesgens <willi@citadel.org>
Wed, 27 Dec 2006 21:11:45 +0000 (21:11 +0000)
committerWilfried Göesgens <willi@citadel.org>
Wed, 27 Dec 2006 21:11:45 +0000 (21:11 +0000)
* add deamonize code to sysdep.c
* modified the init scripts not to use ctdlsvc

citadel/Makefile.in
citadel/citadel_dirs.c
citadel/citadel_dirs.h
citadel/ctdlsvc.c [deleted file]
citadel/debian/citadel-server.install
citadel/debian/citadel.init
citadel/debian/rules
citadel/sysdep.c

index aa06e58dabd9d1339826a45e48eccad649c116c2..e7562db07a00ac6d28595c9dcca20c55ebaa008c 100644 (file)
@@ -26,7 +26,7 @@ all: $(TARGETS)
 EXEEXT=@EXEEXT@
 
 CLIENT_TARGETS=citadel$(EXEEXT) whobbs$(EXEEXT) stress$(EXEEXT)
-SERVER_TARGETS=citserver setup ctdlsvc $(CHKPWD)
+SERVER_TARGETS=citserver setup $(CHKPWD)
 SERV_MODULES=serv_chat.o \
        serv_upgrade.o \
        serv_smtp.o \
@@ -102,7 +102,7 @@ SOURCES=aidepost.c auth.c base64.c chkpwd.c citadel.c citadel_ipc.c \
        serv_newuser.c serv_pas2.c serv_pop3.c serv_rwho.c serv_smtp.c \
        serv_spam.c serv_test.c serv_mrtg.c serv_spam.c serv_upgrade.c \
        serv_vandelay.c serv_vcard.c serv_managesieve.c server_main.c \
-       serv_sieve.c setup.c ctdlsvc.c snprintf.c \
+       serv_sieve.c setup.c snprintf.c \
        stress.c support.c sysdep.c tools.c user_ops.c userlist.c \
        whobbs.c vcard.c serv_notes.c serv_fulltext.c ft_wordbreaker.c \
        crc16.c journaling.c citadel_dirs.c
@@ -158,9 +158,6 @@ citmail: citmail.o config.o citadel_dirs.o
 setup: setup.o tools.o citadel_dirs.o
        $(CC) setup.o tools.o citadel_dirs.o $(LDFLAGS) -o setup $(LIBS) $(SETUP_LIBS)
 
-ctdlsvc: ctdlsvc.o citadel_dirs.o
-       $(CC) ctdlsvc.o citadel_dirs.o $(LDFLAGS) -o ctdlsvc $(SETUP_LIBS)
-
 chkpwd: chkpwd.o auth.o config.o citadel_dirs.o
        $(CC) chkpwd.o auth.o config.o citadel_dirs.o $(LDFLAGS) -o chkpwd $(chkpwd_LIBS)
        chmod 4755 chkpwd
index 79d0d232119b6fd6fbecccf887cbf9a95337c660..321f00f2b5e3ade4f5ff80e03e3fab338b7dc601 100644 (file)
@@ -56,6 +56,7 @@ char file_lmtp_unfiltered_socket[PATH_MAX]="";
 char file_arcq[PATH_MAX]="";
 char file_citadel_socket[PATH_MAX]="";
 char file_mail_aliases[PATH_MAX]="";
+char file_pid_file[PATH_MAX]="";
 
 int home_specified = 0;
 
@@ -168,6 +169,10 @@ void calc_dirs_n_files(int relh, int home, const char *relhome,const char  *ctdl
                         sizeof file_citadel_socket,
                                "%scitadel.socket",
                         ctdl_run_dir);
+       snprintf(file_pid_file, 
+                        sizeof file_pid_file,
+                               "%scitadel.pid",
+                        ctdl_run_dir);
 
        snprintf(file_arcq, 
                         sizeof file_arcq,
index a4ebbf4ae595a5e6d3ac737594939d37058eae5b..2d12c6f97ccefe0032d59c7abc07ea13c4583b3b 100644 (file)
@@ -39,6 +39,7 @@ extern char file_lmtp_unfiltered_socket[PATH_MAX];
 extern char file_arcq[PATH_MAX];
 extern char file_citadel_socket[PATH_MAX];
 extern char file_mail_aliases[PATH_MAX];
+extern char file_pid_file[PATH_MAX];
 
 
 extern void calc_dirs_n_files(int relh, int home, const char *relhome,const char  *ctdldir);
diff --git a/citadel/ctdlsvc.c b/citadel/ctdlsvc.c
deleted file mode 100644 (file)
index ed06ecd..0000000
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * $Id: $
- *
- * This is just a quick little hack to start a program in the background,
- * and automatically restart it if it exits with a nonzero exit status.
- *
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#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;
-
-void graceful_shutdown(int signum) {
-       kill(current_child, signum);
-       if (pidfilename != NULL) {
-               unlink(pidfilename);
-       }
-       exit(0);
-}
-       
-
-int main(int argc, char **argv)
-{
-       pid_t child = 0;
-       int status = 0;
-       FILE *fp;
-//     int nullfd;
-
-       --argc;
-       ++argv;
-
-       pidfilename = argv[0];
-       --argc;
-       ++argv;
-
-       if (access(argv[0], X_OK)) {
-               fprintf(stderr, "%s: cannot execute\n", argv[0]);
-               exit(1);
-       }
-
-       /* 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);
-
-       child = fork();
-       if (child != 0) {
-               fp = fopen(pidfilename, "w");
-               if (fp != NULL) {
-                       fprintf(fp, "%d\n", child);
-                       fclose(fp);
-               }
-               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();
-
-               signal(SIGTERM, graceful_shutdown);
-       
-               if (current_child < 0) {
-                       perror("fork");
-                       exit(errno);
-               }
-       
-               else if (current_child == 0) {
-                       exit(execvp(argv[0], &argv[0]));
-               }
-       
-               else {
-                       waitpid(current_child, &status, 0);
-               }
-
-       } while (status != 0);
-
-       unlink(pidfilename);
-       exit(0);
-}
-
index 87a82b32dac195c78df84b946ec5bfa6e4573e91..8b4769dbdfc5427f994b275e8027a83039fbf672 100644 (file)
@@ -6,6 +6,5 @@ debian/tmp/usr/sbin/userlist
 debian/tmp/usr/sbin/sendcommand
 debian/tmp/usr/sbin/base64
 debian/tmp/usr/lib/citadel-server/setup
-debian/tmp/usr/lib/citadel-server/ctdlsvc
 debian/tmp/usr/sbin/chkpwd
 
index 3c766c51a5254ccae215824f9f1390187d1e6e31..3343b0f06b6bbd352b791bb7127552f72fda5007 100644 (file)
@@ -23,8 +23,7 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin
 DESC="Citadel Groupware "
 NAME=citserver
 DAEMON=/usr/sbin/$NAME
-CTDLSVC=/usr/lib/citadel-server/ctdlsvc
-DAEMON_ARGS=" -x3 -lmail -t/dev/null"
+DAEMON_ARGS=" -d -x3 -lmail -t/dev/null"
 PIDFILE=$RUNDIR/$NAME.pid
 SCRIPTNAME=/etc/init.d/citadel
 SENDCOMMAND=/usr/sbin/sendcommand
@@ -63,7 +62,7 @@ do_start()
        #   0 if daemon has been started
        #   1 if daemon was already running
        #   2 if daemon could not be started
-       if $CTDLSVC $PIDFILE $DAEMON \
+       if $DAEMON \
                $DAEMON_ARGS ; then
            return 0
        else
index e30091092f8921ac727f15621aa8c8601fb0df30..9679e09b8f9aacb971a085f25417e717d3094534 100755 (executable)
@@ -100,9 +100,6 @@ install-arch:
        mv \
                $(CURDIR)/debian/tmp/usr/sbin/setup \
                $(CURDIR)/debian/tmp/usr/lib/citadel-server/
-       mv \
-               $(CURDIR)/debian/tmp/usr/sbin/ctdlsvc \
-               $(CURDIR)/debian/tmp/usr/lib/citadel-server/
 #      cd $(CURDIR)/debian/tmp/usr/share/doc/citadel-server/examples/help; md5sum * >../help.md5sums
 #      cd $(CURDIR)/debian/tmp/usr/share/doc/citadel-server/examples/messages; md5sum * >../messages.md5sums
        cp \
index c992adbe6f6b57a51a89c7cca953a09a807f05ce..df4f714f2e1fab35e8f442f2b20188e2585d7ae6 100644 (file)
@@ -750,34 +750,73 @@ void kill_session(int session_to_kill) {
        end_critical_section(S_SESSION_TABLE);
 }
 
-
+pid_t current_child;
+void graceful_shutdown(int signum) {
+       kill(current_child, signum);
+       unlink(file_pid_file);
+       exit(0);
+}
 
 
 /*
  * Start running as a daemon.
  */
 void start_daemon(int unused) {
-       int nullfd;
+       int status = 0;
+       pid_t child = 0;
+       FILE *fp;
+
+       current_child = 0;
 
        /* 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);
+       chdir(ctdl_run_dir);
+
+       child = fork();
+       if (child != 0) {
+               fp = fopen(file_pid_file, "w");
+               if (fp != NULL) {
+                       fprintf(fp, "%d\n", child);
+                       fclose(fp);
+               }
+               exit(0);
        }
-       dup2(nullfd, 0);
-       dup2(nullfd, 1);
-       dup2(nullfd, 2);
-       close(nullfd);
+       
+       signal(SIGHUP, SIG_IGN);
+       signal(SIGINT, SIG_IGN);
+       signal(SIGQUIT, SIG_IGN);
 
-       if (fork()) exit(0);
        setsid();
-       signal(SIGHUP,SIG_IGN);
-       signal(SIGINT,SIG_IGN);
-       signal(SIGQUIT,SIG_IGN);
+//     umask(0);
+        freopen("/dev/null", "r", stdin);
+        freopen("/dev/null", "w", stdout);
+        freopen("/dev/null", "w", stderr);
+
+       do {
+               current_child = fork();
+
+               signal(SIGTERM, graceful_shutdown);
+       
+               if (current_child < 0) {
+                       perror("fork");
+                       exit(errno);
+               }
+       
+               else if (current_child == 0) {
+                       return; /* continue starting citadel. */
+               }
+       
+               else {
+                       waitpid(current_child, &status, 0);
+               }
+
+       } while (status != 0);
+
+       unlink(file_pid_file);
+       exit(0);
+
 }