* moved some flags so that our run flags are collected in one place.
authorWilfried Göesgens <willi@citadel.org>
Sun, 29 Jul 2007 19:24:05 +0000 (19:24 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sun, 29 Jul 2007 19:24:05 +0000 (19:24 +0000)
* 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
citadel/citserver.h
citadel/server_main.c
citadel/sysdep.c
citadel/sysdep_decls.h
citadel/tools.h

index 39f0fb66daa394cd0196e32c83227550cf4c895a..825d756e544ff6150a851210f1a72154119b2b59 100644 (file)
@@ -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)) {
index f09f3214e4c928e304252d04a06186c3dad5f39d..24bb9f7122cbc636d93574267882a4cf83c0f0cc 100644 (file)
@@ -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);
index 2d2309b09407bec9213a19b973a0376bdba84f40..23ef71d91df4f136fe26746fd6f40a3330e764e1 100644 (file)
@@ -69,8 +69,6 @@
 #include "snprintf.h"
 #endif
 
-int running_as_daemon = 0;
-
 /*
  * Here's where it all begins.
  */
index 761b225c746ca6620b3a8f3c6ac9029af952c5f5..64ea7ee6b3e0e229b905dedaf093944f3a1ac492 100644 (file)
@@ -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);
index f77d6e4a5d6f886453f83592bee01aea9e743ede..a1e551c9f468467b6fb86b010ae101c405bafe8d 100644 (file)
@@ -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[];
index c1666f8c6ef92009238f3a28c00f0cc36e43e9e1..d11c86105ac3d78cbd432dc0da6a597b5c41a861 100644 (file)
@@ -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);