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 \
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
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
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;
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,
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);
+++ /dev/null
-/*
- * $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);
-}
-
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
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
# 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
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 \
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);
+
}