From 46981e9afa835f2ced47b817bb33d612daefad3a Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 6 Jul 2006 02:44:20 +0000 Subject: [PATCH] * New HALT command shuts down server but suspends instead of exiting. * setup.c: fixed a citadel.config path problem that prevented alternative dir installations from working properly --- citadel/citserver.c | 25 +++++++++++++++++++++++++ citadel/citserver.h | 1 + citadel/setup.c | 34 +++++++++++++++++----------------- citadel/sysdep.c | 1 + citadel/sysdep_decls.h | 2 ++ citadel/techdoc/protocol.txt | 8 ++++++++ 6 files changed, 54 insertions(+), 17 deletions(-) diff --git a/citadel/citserver.c b/citadel/citserver.c index 411773d08..dca5ce0ea 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -185,6 +185,15 @@ void master_cleanup(int exitcode) { dump_heap(); #endif + /* If the operator requested a halt but not an exit, halt here. */ + if (shutdown_and_halt) { + lprintf(CTDL_NOTICE, "citserver: Halting server without exiting.\n"); + fflush(stdout); fflush(stderr); + while(1) { + sleep(32767); + } + } + /* Now go away. */ lprintf(CTDL_NOTICE, "citserver: Exiting with status %d\n", exitcode); fflush(stdout); fflush(stderr); @@ -765,6 +774,18 @@ void cmd_down(void) { time_to_die = 1; } +/* + * Halt the server without exiting the server process. + */ +void cmd_halt(void) { + + if (CtdlAccessCheck(ac_aide)) return; + + cprintf("%d Halting server. Goodbye.\n", CIT_OK); + time_to_die = 1; + shutdown_and_halt = 1; +} + /* * Schedule or cancel a server shutdown */ @@ -1234,6 +1255,10 @@ void do_command_loop(void) { cmd_down(); } + else if (!strncasecmp(cmdbuf,"HALT",4)) { + cmd_halt(); + } + else if (!strncasecmp(cmdbuf,"SCDN",4)) { cmd_scdn(&cmdbuf[5]); } diff --git a/citadel/citserver.h b/citadel/citserver.h index dd599cb3e..f09f3214e 100644 --- a/citadel/citserver.h +++ b/citadel/citserver.h @@ -27,6 +27,7 @@ void cmd_more (void); void cmd_echo (char *etext); void cmd_ipgm (char *argbuf); void cmd_down (void); +void cmd_halt (void); void cmd_scdn (char *argbuf); void cmd_extn (char *argbuf); void do_command_loop(void); diff --git a/citadel/setup.c b/citadel/setup.c index 8a8effd78..7c6e6f121 100644 --- a/citadel/setup.c +++ b/citadel/setup.c @@ -85,7 +85,7 @@ char *setup_text[] = { "specify a directory other than the default, you will need to\n" "specify the -h flag to the server when you start it up.\n", #else -"Enter the subdirectoryname for an alternating installation of " +"Enter the subdirectory name for an alternate installation of " "Citadel. To do a default installation just leave it blank." "If you specify a directory other than the default, you will need to\n" "specify the -h flag to the server when you start it up.\n" @@ -929,13 +929,7 @@ void write_config_to_disk(void) FILE *fp; int fd; - if ((fd = creat( -#ifndef HAVE_ETC_DIR - "." -#else - ETC_DIR -#endif - "/citadel.config", S_IRUSR | S_IWUSR)) == -1) { + if ((fd = creat(file_citadel_config, S_IRUSR | S_IWUSR)) == -1) { display_error("setup: cannot open citadel.config"); cleanup(1); } @@ -1142,20 +1136,26 @@ int main(int argc, char *argv[]) home=(setup_directory[1]!='\0'); relh=home&(setup_directory[1]!='/'); - if (!relh) safestrncpy(ctdl_home_directory, setup_directory, - sizeof ctdl_home_directory); - else - safestrncpy(relhome, ctdl_home_directory, - sizeof relhome); + if (!relh) { + safestrncpy(ctdl_home_directory, setup_directory, sizeof ctdl_home_directory); + } + else { + safestrncpy(relhome, ctdl_home_directory, sizeof relhome); + } calc_dirs_n_files(relh, home, relhome, ctdldir); enable_home=(relh|home); - if ((home) && (chdir(setup_directory) != 0)) { - important_message("Citadel Setup", - "The directory you specified does not exist."); - cleanup(errno); + if (home) { + if (chdir(setup_directory) == 0) { + strcpy(file_citadel_config, "./citadel.config"); + } + else { + important_message("Citadel Setup", + "The directory you specified does not exist."); + cleanup(errno); + } } /* Determine our host name, in case we need to use it as a default */ diff --git a/citadel/sysdep.c b/citadel/sysdep.c index 33fde1e51..7d65e6c8a 100644 --- a/citadel/sysdep.c +++ b/citadel/sysdep.c @@ -154,6 +154,7 @@ void lprintf(enum LogLevel loglevel, const char *format, ...) { */ volatile int time_to_die = 0; +volatile int shutdown_and_halt = 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 c805176a0..d92d28e57 100644 --- a/citadel/sysdep_decls.h +++ b/citadel/sysdep_decls.h @@ -74,6 +74,8 @@ void create_worker(void); extern int num_sessions; extern volatile int time_to_die; +extern volatile int shutdown_and_halt; + extern int verbosity; extern int rescan[]; diff --git a/citadel/techdoc/protocol.txt b/citadel/techdoc/protocol.txt index b368ae7e4..712a88722 100644 --- a/citadel/techdoc/protocol.txt +++ b/citadel/techdoc/protocol.txt @@ -1666,6 +1666,14 @@ otherwise, it returns OK followed by a number representing the current state of the flag. + HALT (HALT the server without shutting it down) + + Identical to the DOWN command, except instead of exiting, the server process +cleans up and then suspends indefinitely. This could potentially be useful for +shutdown scripts that don't want init to automatically respawn another citserver +process. + + EMSG (Enter a system MeSsaGe) This is the opposite of the MESG command - it allows the creation and editing -- 2.30.2