* GNU General Public License for more details.
*/
+#include <stdlib.h>
+#include <unistd.h>
#include <stdio.h>
+#include <sys/stat.h>
#include "sysdep.h"
#include <time.h>
#if HAVE_BACKTRACE
size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
strings = backtrace_symbols(stack_frames, size);
for (i = 0; i < size; i++) {
- if (strings != NULL)
- syslog(LOG_ALERT, "%s %s\n", p, strings[i]);
- else
- syslog(LOG_ALERT, "%s %p\n", p, stack_frames[i]);
+ if (strings != NULL) {
+ syslog(LOG_DEBUG, "citserver: %s %s", p, strings[i]);
+ }
+ else {
+ syslog(LOG_DEBUG, "citserver: %s %p", p, stack_frames[i]);
+ }
}
free(strings);
#endif
StrBufAppendPrintf(Buf, "%p : ", stack_frames[i]);
}
free(strings);
- syslog(LOG_ALERT, "%s %s\n", IOSTR, ChrPtr(Buf));
+ syslog(LOG_DEBUG, "citserver: %s %s", IOSTR, ChrPtr(Buf));
FreeStrBuf(&Buf);
}
#endif
}
+
/*
* print the actual stack frame.
*/
size = backtrace(stack_frames, sizeof(stack_frames) / sizeof(void*));
strings = backtrace_symbols(stack_frames, size);
for (i = 0; i < size; i++) {
- if (strings != NULL)
- syslog(LOG_ALERT, "%s\n", strings[i]);
- else
- syslog(LOG_ALERT, "%p\n", stack_frames[i]);
+ if (strings != NULL) {
+ syslog(LOG_DEBUG, "%s", strings[i]);
+ }
+ else {
+ syslog(LOG_DEBUG, "%p", stack_frames[i]);
+ }
}
free(strings);
#endif
/*
- * Cleanup routine to be called when the server is shutting down.
+ * Cleanup routine to be called when the server is shutting down. Returns the needed exit code.
*/
-void master_cleanup(int exitcode) {
+int master_cleanup(int exitcode) {
struct CleanupFunctionHook *fcn;
static int already_cleaning_up = 0;
syslog(LOG_NOTICE, "citserver: Exiting with status %d\n", exitcode);
fflush(stdout); fflush(stderr);
- if (restart_server != 0)
- exit(1);
- if ((running_as_daemon != 0) && ((exitcode == 0) ))
+ if (restart_server != 0) {
+ exitcode = 1;
+ }
+ else if ((running_as_daemon != 0) && ((exitcode == 0) )) {
exitcode = CTDLEXIT_SHUTDOWN;
- exit(exitcode);
+ }
+ return(exitcode);
}
}
-
-
-/*
- * This loop recognizes all server commands.
- */
-void do_command_loop(void) {
- char cmdbuf[SIZ];
-
- time(&CC->lastcmd);
- memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
- if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
- syslog(LOG_ERR, "Citadel client disconnected: ending session.\n");
- CC->kill_me = KILLME_CLIENT_DISCONNECTED;
- return;
- }
-
- /* Log the server command, but don't show passwords... */
- if ( (strncasecmp(cmdbuf, "PASS", 4)) && (strncasecmp(cmdbuf, "SETP", 4)) ) {
- syslog(LOG_INFO, "[%d][%s(%ld)] %s",
- CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
- );
- }
- else {
- syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
- CC->cs_pid, CC->curr_user, CC->user.usernum
- );
- }
-
- buffer_output();
-
- /*
- * Let other clients see the last command we executed, and
- * update the idle time, but not NOOP, QNOP, PEXP, GEXP, RWHO, or TIME.
- */
- if ( (strncasecmp(cmdbuf, "NOOP", 4))
- && (strncasecmp(cmdbuf, "QNOP", 4))
- && (strncasecmp(cmdbuf, "PEXP", 4))
- && (strncasecmp(cmdbuf, "GEXP", 4))
- && (strncasecmp(cmdbuf, "RWHO", 4))
- && (strncasecmp(cmdbuf, "TIME", 4)) ) {
- strcpy(CC->lastcmdname, " ");
- safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
- time(&CC->lastidle);
- }
-
- if ((strncasecmp(cmdbuf, "ENT0", 4))
- && (strncasecmp(cmdbuf, "MESG", 4))
- && (strncasecmp(cmdbuf, "MSGS", 4)))
- {
- CC->cs_flags &= ~CS_POSTING;
- }
-
- if (!DLoader_Exec_Cmd(cmdbuf)) {
- cprintf("%d Unrecognized or unsupported command.\n", ERROR + CMD_NOT_SUPPORTED);
- }
-
- unbuffer_output();
-
- /* Run any after-each-command routines registered by modules */
- PerformSessionHooks(EVT_CMD);
-}
-
-
/*
* This loop performs all asynchronous functions.
*/