From 8d1aa3abcbc0872607064e7769275bab86c67a5c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Wilfried=20G=C3=B6esgens?= Date: Sun, 29 Jul 2007 19:24:05 +0000 Subject: [PATCH] * moved some flags so that our run flags are collected in one place. * added IsEmptyStr from webcit * added optional Parameter to "DOWN" command that will make the server restart instead of stopping. * if the new flag is set, we will exit(1) to hopefully make our watcher fire us up again. --- citadel/citserver.c | 27 ++++++++++++++++++++++++--- citadel/citserver.h | 2 +- citadel/server_main.c | 2 -- citadel/sysdep.c | 3 ++- citadel/sysdep_decls.h | 2 ++ citadel/tools.h | 2 ++ 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index 39f0fb66d..825d756e5 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -175,6 +175,8 @@ void master_cleanup(int exitcode) { lprintf(CTDL_NOTICE, "citserver: Exiting with status %d\n", exitcode); fflush(stdout); fflush(stderr); + if (restart_server != 0) + exit(1); exit(exitcode); } @@ -746,11 +748,30 @@ void cmd_ipgm(char *argbuf) /* * Shut down the server */ -void cmd_down(void) { +void cmd_down(char *argbuf) { + char *Reply ="%d Shutting down server. Goodbye.\n"; if (CtdlAccessCheck(ac_aide)) return; - cprintf("%d Shutting down server. Goodbye.\n", CIT_OK); + if (!IsEmptyStr(argbuf)) + { + int state = CIT_OK; + restart_server = extract_int(argbuf, 0); + + if (restart_server > 0) + Reply = "%d Restarting server. See you soon.\n"; + if ((restart_server > 0) && !running_as_daemon) + { + lprintf(CTDL_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n"); + Reply = "%d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n"; + state = ERROR; + } + cprintf(Reply, state); + } + else + { + cprintf(Reply, CIT_OK); + } time_to_die = 1; } @@ -1237,7 +1258,7 @@ void do_command_loop(void) { } else if (!strncasecmp(cmdbuf,"DOWN",4)) { - cmd_down(); + cmd_down(&cmdbuf[5]); } else if (!strncasecmp(cmdbuf,"HALT",4)) { diff --git a/citadel/citserver.h b/citadel/citserver.h index f09f3214e..24bb9f712 100644 --- a/citadel/citserver.h +++ b/citadel/citserver.h @@ -26,7 +26,7 @@ void cmd_term (char *cmdbuf); void cmd_more (void); void cmd_echo (char *etext); void cmd_ipgm (char *argbuf); -void cmd_down (void); +void cmd_down (char *argbuf); void cmd_halt (void); void cmd_scdn (char *argbuf); void cmd_extn (char *argbuf); diff --git a/citadel/server_main.c b/citadel/server_main.c index 2d2309b09..23ef71d91 100644 --- a/citadel/server_main.c +++ b/citadel/server_main.c @@ -69,8 +69,6 @@ #include "snprintf.h" #endif -int running_as_daemon = 0; - /* * Here's where it all begins. */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 761b225c7..64ea7ee6b 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -99,7 +99,6 @@ pthread_t checkpoint_thread_tid; int syslog_facility = LOG_DAEMON; int enable_syslog = 0; -extern int running_as_daemon; void DestroyWorkerList(void); @@ -157,6 +156,8 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { volatile int time_to_die = 0; volatile int shutdown_and_halt = 0; +volatile int restart_server = 0; +volatile int running_as_daemon = 0; static RETSIGTYPE signal_cleanup(int signum) { lprintf(CTDL_DEBUG, "Caught signal %d; shutting down.\n", signum); diff --git a/citadel/sysdep_decls.h b/citadel/sysdep_decls.h index f77d6e4a5..a1e551c9f 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -78,6 +78,8 @@ void create_worker(void); extern int num_sessions; extern volatile int time_to_die; extern volatile int shutdown_and_halt; +extern volatile int running_as_daemon; +extern volatile int restart_server; extern int verbosity; extern int rescan[]; diff --git a/citadel/tools.h b/citadel/tools.h index c1666f8c6..d11c86105 100644 --- a/citadel/tools.h +++ b/citadel/tools.h @@ -21,6 +21,8 @@ int strncasecmp(char *, char *, int); #define strcasecmp(x,y) strncasecmp(x,y,INT_MAX); #endif +#define IsEmptyStr(a) ((a)[0] == '\0') + #define num_parms(source) num_tokens(source,(char)'|') void stripout(char *str, char leftboundary, char rightboundary); void stripallbut(char *str, char leftboundary, char rightboundary); -- 2.30.2