Moar cleanup
[citadel.git] / citadel / citserver.c
index 9832b781276932dbab8d01c4bee2e1ae96c4effc..59dc31443f72ec494c2be44c38c4b51a21264402 100644 (file)
  * 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
@@ -49,10 +52,12 @@ void cit_backtrace(void)
        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
@@ -78,12 +83,13 @@ void cit_oneline_backtrace(void)
                                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.
  */
@@ -98,10 +104,12 @@ void cit_panic_backtrace(int SigNum)
        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
@@ -185,9 +193,9 @@ void master_startup(void) {
 
 
 /*
- * 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;
 
@@ -225,11 +233,13 @@ void master_cleanup(int exitcode) {
        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);
 }
 
 
@@ -373,69 +383,6 @@ void citproto_begin_admin_session() {
 }
 
 
-
-
-/*
- * 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.
  */