From a799f677ca673c433515a8259f65701662b21983 Mon Sep 17 00:00:00 2001 From: Wilfried Goesgens Date: Sat, 14 Sep 2013 21:44:55 +0200 Subject: [PATCH] start moving system commands into its own file --- citadel/citserver.c | 93 ------------- citadel/modules/ctdlproto/serv_syscmds.c | 163 +++++++++++++++++++++++ citadel/scripts/mk_module_init.sh | 2 +- 3 files changed, 164 insertions(+), 94 deletions(-) create mode 100644 citadel/modules/ctdlproto/serv_syscmds.c diff --git a/citadel/citserver.c b/citadel/citserver.c index 5fe1fdd4e..28de7e6bf 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -443,84 +443,6 @@ int CtdlAccessCheck(int required_level) { -/* - * Shut down the server - */ -void cmd_down(char *argbuf) { - char *Reply ="%d Shutting down server. Goodbye.\n"; - - if (CtdlAccessCheck(ac_aide)) return; - - if (!IsEmptyStr(argbuf)) - { - int state = CIT_OK; - restart_server = extract_int(argbuf, 0); - - if (restart_server > 0) - { - Reply = "%d citserver will now shut down and automatically restart.\n"; - } - if ((restart_server > 0) && !running_as_daemon) - { - syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n"); - Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n"; - state = ERROR; - } - cprintf(Reply, state); - } - else - { - cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN); - } - CC->kill_me = KILLME_SERVER_SHUTTING_DOWN; - server_shutting_down = 1; -} - - -/* - * Halt the server without exiting the server process. - */ -void cmd_halt(char *argbuf) { - - if (CtdlAccessCheck(ac_aide)) return; - - cprintf("%d Halting server. Goodbye.\n", CIT_OK); - server_shutting_down = 1; - shutdown_and_halt = 1; -} - - -/* - * Schedule or cancel a server shutdown - */ -void cmd_scdn(char *argbuf) -{ - int new_state; - int state = CIT_OK; - char *Reply = "%d %d\n"; - - if (CtdlAccessCheck(ac_aide)) return; - - new_state = extract_int(argbuf, 0); - if ((new_state == 2) || (new_state == 3)) - { - restart_server = 1; - if (!running_as_daemon) - { - syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n"); - Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n"; - state = ERROR; - } - - restart_server = extract_int(argbuf, 0); - new_state -= 2; - } - if ((new_state == 0) || (new_state == 1)) { - ScheduledShutdown = new_state; - } - cprintf(Reply, state, ScheduledShutdown); -} - /* @@ -707,18 +629,3 @@ void do_async_loop(void) { PerformSessionHooks(EVT_ASYNC); } - -/*****************************************************************************/ -/* MODULE INITIALIZATION STUFF */ -/*****************************************************************************/ - -CTDL_MODULE_INIT(citserver) -{ - if (!threading) { - CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown"); - CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process"); - CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown"); - } - /* return our id for the Log */ - return "citserver"; -} diff --git a/citadel/modules/ctdlproto/serv_syscmds.c b/citadel/modules/ctdlproto/serv_syscmds.c new file mode 100644 index 000000000..daf5c9f38 --- /dev/null +++ b/citadel/modules/ctdlproto/serv_syscmds.c @@ -0,0 +1,163 @@ + +/* + * Main source module for the Citadel server + * + * Copyright (c) 1987-2011 by the citadel.org team + * + * This program is open source software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License, version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include "sysdep.h" +#include +#include +#include +#include +#include +#include +#include + +#if TIME_WITH_SYS_TIME +# include +# include +#else +# if HAVE_SYS_TIME_H +# include +# else +# include +# endif +#endif + +#if HAVE_BACKTRACE +#include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "citadel.h" +#include "server.h" +#include "sysdep_decls.h" +#include "threads.h" +#include "citserver.h" +#include "config.h" +#include "database.h" +#include "housekeeping.h" +#include "user_ops.h" +#include "msgbase.h" +#include "support.h" +#include "locate_host.h" +#include "room_ops.h" +#include "control.h" +#include "euidindex.h" +#include "context.h" +#include "svn_revision.h" +#include "ctdl_module.h" + + + +/* + * Shut down the server + */ +void cmd_down(char *argbuf) { + char *Reply ="%d Shutting down server. Goodbye.\n"; + + if (CtdlAccessCheck(ac_aide)) return; + + if (!IsEmptyStr(argbuf)) + { + int state = CIT_OK; + restart_server = extract_int(argbuf, 0); + + if (restart_server > 0) + { + Reply = "%d citserver will now shut down and automatically restart.\n"; + } + if ((restart_server > 0) && !running_as_daemon) + { + syslog(LOG_ERR, "The user requested restart, but not running as daemon! Geronimooooooo!\n"); + Reply = "%d Warning: citserver is not running in daemon mode and is therefore unlikely to restart automatically.\n"; + state = ERROR; + } + cprintf(Reply, state); + } + else + { + cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN); + } + CC->kill_me = KILLME_SERVER_SHUTTING_DOWN; + server_shutting_down = 1; +} + + +/* + * Halt the server without exiting the server process. + */ +void cmd_halt(char *argbuf) { + + if (CtdlAccessCheck(ac_aide)) return; + + cprintf("%d Halting server. Goodbye.\n", CIT_OK); + server_shutting_down = 1; + shutdown_and_halt = 1; +} + + +/* + * Schedule or cancel a server shutdown + */ +void cmd_scdn(char *argbuf) +{ + int new_state; + int state = CIT_OK; + char *Reply = "%d %d\n"; + + if (CtdlAccessCheck(ac_aide)) return; + + new_state = extract_int(argbuf, 0); + if ((new_state == 2) || (new_state == 3)) + { + restart_server = 1; + if (!running_as_daemon) + { + syslog(LOG_ERR, "The user requested restart, but not running as deamon! Geronimooooooo!\n"); + Reply = "%d %d Warning, not running in deamon mode. maybe we will come up again, but don't lean on it.\n"; + state = ERROR; + } + + restart_server = extract_int(argbuf, 0); + new_state -= 2; + } + if ((new_state == 0) || (new_state == 1)) { + ScheduledShutdown = new_state; + } + cprintf(Reply, state, ScheduledShutdown); +} + + +/*****************************************************************************/ +/* MODULE INITIALIZATION STUFF */ +/*****************************************************************************/ + +CTDL_MODULE_INIT(syscmd) +{ + if (!threading) { + CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown"); + CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process"); + CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown"); + } + /* return our id for the Log */ + return "syscmd"; +} diff --git a/citadel/scripts/mk_module_init.sh b/citadel/scripts/mk_module_init.sh index 84de37702..e0642bb13 100755 --- a/citadel/scripts/mk_module_init.sh +++ b/citadel/scripts/mk_module_init.sh @@ -30,7 +30,7 @@ U_FILE="$CUR_DIR/modules_upgrade.c" /usr/bin/printf "Scanning extension modules for entry points.\n" -STATIC_FIRST_MODULES="citserver control modules euidindex msgbase nttlist database internet_addressing" +STATIC_FIRST_MODULES="control modules euidindex msgbase nttlist database internet_addressing" DYNAMIC_MODULES=`grep CTDL_MODULE_INIT modules/*/*.c |$SED 's;.*(\(.*\));\1;'` if test -d user_modules; then USER_MODULES=`grep CTDL_MODULE_INIT user_modules/*/*.c |$SED 's;.*(\(.*\));\1;'` -- 2.30.2