void master_cleanup(int exitcode) {
struct CleanupFunctionHook *fcn;
static int already_cleaning_up = 0;
+ int i;
if (already_cleaning_up) while(1) sleep(1);
already_cleaning_up = 1;
#endif
/* Now go away. */
- lprintf(CTDL_NOTICE, "citserver: Exiting with status %d.\n", exitcode);
+ lprintf(CTDL_NOTICE, "citserver: Exiting with status %d\n", exitcode);
fflush(stdout); fflush(stderr);
+
exit(exitcode);
}
fflush(stdout);
#ifdef HAVE_OPENSSL
- /* ...don't try to shut down a connection on a dead socket?
- SSL_shutdown(ipc->ssl);
- */
-
SSL_free(ipc->ssl);
ipc->ssl = NULL;
#endif
shutdown(ipc->sock, 2);
ipc->sock = -1;
-
- /* Hangup - let any children know as well */
- /* kill(0, SIGHUP); */
- /* This is disabled because it makes the setup program and other
- * users of sendcommand do really unhappy things. */
}
}
+void sendcommand_die(void) {
+ exit(0);
+}
+
/*
* main
fflush(stderr);
np_attach_to_server();
fflush(stderr);
+ setIPCDeathHook(sendcommand_die);
fprintf(stderr, "%s\n", cmd);
CtdlIPC_chat_send(ipc, cmd);
struct passwd *pw;
int drop_root_perms = 1;
size_t size;
-
+
/* initialize the master context */
InitializeMasterCC();
"This program is distributed under the terms of the GNU "
"General Public License.\n");
lprintf(CTDL_NOTICE, "\n");
+ lprintf(CTDL_DEBUG, "Called as: %s\n", argv[0]);
/* Load site-specific parameters, and set the ipgm secret */
lprintf(CTDL_INFO, "Loading citadel.config\n");
*/
void init_sysdep(void) {
int i;
+ sigset_t set;
/* Avoid vulnerabilities related to FD_SETSIZE if we can. */
#ifdef FD_SETSIZE
* The action for unexpected signals and exceptions should be to
* call signal_cleanup() to gracefully shut down the server.
*/
+ sigemptyset(&set);
+ sigaddset(&set, SIGINT);
+ sigaddset(&set, SIGQUIT);
+ sigaddset(&set, SIGHUP);
+ sigaddset(&set, SIGTERM);
+ sigaddset(&set, SIGSEGV);
+ sigprocmask(SIG_UNBLOCK, &set, NULL);
signal(SIGINT, signal_cleanup);
signal(SIGQUIT, signal_cleanup);
signal(SIGHUP, signal_cleanup);