citadel
About: Citadel is an advanced messaging and collaboration system for groupware and BBS applications (preferred OS: Linux).
  Fossies Dox: citadel.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

serv_syscmds.c
Go to the documentation of this file.
1// System management commands for Citadel server
2//
3// Copyright (c) 1987-2021 by the citadel.org team
4//
5// This program is open source software; you can redistribute it and/or modify
6// it under the terms of the GNU General Public License, version 3.
7//
8// This program is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11// GNU General Public License for more details.
12
13#include <stdio.h>
14#include <libcitadel.h>
15
16#include "serv_extensions.h"
17#include "ctdl_module.h"
18
19
20// Shut down or restart the server
21void cmd_down(char *argbuf) {
22 char *Reply ="%d Shutting down server. Goodbye.\n";
23
24 if (CtdlAccessCheck(ac_aide)) return;
25
26 if (!IsEmptyStr(argbuf)) {
27 int state = CIT_OK;
28 restart_server = extract_int(argbuf, 0);
29
30 if (restart_server > 0) {
31 Reply = "%d citserver will now shut down and automatically restart.\n";
32 }
33 cprintf(Reply, state);
34 }
35 else {
37 }
40}
41
42
43// Halt the server without exiting the server process.
44void cmd_halt(char *argbuf) {
45 if (CtdlAccessCheck(ac_aide)) return;
46
47 cprintf("%d Halting server. Goodbye.\n", CIT_OK);
50}
51
52
53// Schedule or cancel a server shutdown
54void cmd_scdn(char *argbuf) {
55 int new_state;
56 int state = CIT_OK;
57 char *Reply = "%d %d\n";
58
59 if (CtdlAccessCheck(ac_aide)) return;
60
61 new_state = extract_int(argbuf, 0);
62 if ((new_state == 2) || (new_state == 3)) {
64 restart_server = extract_int(argbuf, 0);
65 new_state -= 2;
66 }
67 if ((new_state == 0) || (new_state == 1)) {
68 ScheduledShutdown = new_state;
69 }
70 cprintf(Reply, state, ScheduledShutdown);
71}
72
73
74// ****************************************************************************
75// * MODULE INITIALIZATION STUFF *
76// ****************************************************************************
77
79{
80 if (!threading) {
81 CtdlRegisterProtoHook(cmd_down, "DOWN", "perform a server shutdown");
82 CtdlRegisterProtoHook(cmd_halt, "HALT", "halt the server without exiting the server process");
83 CtdlRegisterProtoHook(cmd_scdn, "SCDN", "schedule or cancel a server shutdown");
84 }
85 // return our id for the log
86 return "syscmd";
87}
int ScheduledShutdown
Definition: citserver.c:26
#define CC
Definition: context.h:140
int CtdlAccessCheck(int)
Definition: user_ops.c:387
@ ac_aide
Definition: ctdl_module.h:246
void CtdlRegisterProtoHook(void(*handler)(char *), char *cmd, char *desc)
#define CTDL_MODULE_INIT(module_name)
Definition: ctdl_module.h:50
#define CIT_OK
Definition: ipcdef.h:6
#define SERVER_SHUTTING_DOWN
Definition: ipcdef.h:19
void cmd_down(char *argbuf)
Definition: serv_syscmds.c:21
void cmd_scdn(char *argbuf)
Definition: serv_syscmds.c:54
void cmd_halt(char *argbuf)
Definition: serv_syscmds.c:44
@ KILLME_SERVER_SHUTTING_DOWN
Definition: server.h:92
void cprintf(const char *format,...)
Definition: sysdep.c:381
volatile int restart_server
Definition: sysdep.c:47
volatile int shutdown_and_halt
Definition: sysdep.c:46
int server_shutting_down
Definition: threads.c:31