Include the server's startup time as one of the output parameters of the TIME command
[citadel.git] / citadel / citserver.c
index 86bd0687c9fe4caea3a9ca93aebccca24d3179d2..782f6a99b0c4acf112ef448c0afe25d2400f65d7 100644 (file)
@@ -172,11 +172,6 @@ void master_startup(void) {
 
        syslog(LOG_INFO, "Opening databases\n");
        open_databases();
-
-       ctdl_thread_internal_init_tsd();
-       
-       CtdlThreadAllocTSD();
-       
        check_ref_counts();
 
        syslog(LOG_INFO, "Creating base rooms (if necessary)\n");
@@ -201,6 +196,9 @@ void master_startup(void) {
        urandom = fopen("/dev/urandom", "r");
        if (urandom != NULL) {
                rv = fread(&seed, sizeof seed, 1, urandom);
+               if (rv == -1)
+                       syslog(LOG_EMERG, "failed to read random seed: %s\n", 
+                              strerror(errno));
                fclose(urandom);
        }
        else {
@@ -244,10 +242,6 @@ void master_cleanup(int exitcode) {
        syslog(LOG_INFO, "Closing databases\n");
        close_databases();
 
-#ifdef DEBUG_MEMORY_LEAKS
-       dump_heap();
-#endif
-
        /* If the operator requested a halt but not an exit, halt here. */
        if (shutdown_and_halt) {
                syslog(LOG_NOTICE, "citserver: Halting server without exiting.\n");
@@ -307,10 +301,10 @@ void cmd_info(char *cmdbuf) {
 
        cprintf("%s\n", config.c_default_cal_zone);
 
-       /* Output load averages */
-       cprintf("%f\n", CtdlThreadLoadAvg);
-       cprintf("%f\n", CtdlThreadWorkerAvg);
-       cprintf("%d\n", CtdlThreadGetCount());
+       /* thread load averages -- temporarily disabled during refactoring of this code */
+       cprintf("0\n");         /* load average */
+       cprintf("0\n");         /* worker average */
+       cprintf("0\n");         /* thread count */
 
        cprintf("1\n");         /* yes, Sieve mail filtering is supported */
        cprintf("%d\n", config.c_enable_fulltext);
@@ -352,9 +346,9 @@ void cmd_time(char *argbuf)
    
    /* timezone and daylight global variables are not portable. */
 #ifdef HAVE_STRUCT_TM_TM_GMTOFF
-   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst);
+   cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, tmp.tm_gmtoff, tmp.tm_isdst, server_startup_time);
 #else
-   cprintf("%d %ld|%ld|%d\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst);
+   cprintf("%d %ld|%ld|%d|%ld\n", CIT_OK, (long)tv, timezone, tmp.tm_isdst, server_startup_time);
 #endif
 }
 
@@ -449,7 +443,7 @@ int is_public_client(void)
        for (i=0; i<num_parms(public_clients); ++i) {
                extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
                if (!strcasecmp(CC->cs_addr, addrbuf)) {
-                       syslog(LOG_DEBUG, "... yes it is.\n");
+                       syslog(LOG_DEBUG, "... yes its local.\n");
                        return(1);
                }
        }
@@ -661,7 +655,7 @@ void GenerateRoomDisplay(char *real_room,
        if (viewed->room.QRflags & QR_PRIVATE) {
                CtdlRoomAccess(&viewed->room, &viewer->user, &ra, NULL);
                if ( (ra & UA_KNOWN) == 0) {
-                       strcpy(real_room, "<private room>");
+                       strcpy(real_room, " ");
                }
        }
 
@@ -791,7 +785,7 @@ void cmd_ipgm(char *argbuf)
                sleep(5);
                cprintf("%d Authentication failed.\n", ERROR + PASSWORD_REQUIRED);
                syslog(LOG_ERR, "Warning: ipgm authentication failed.\n");
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_AUTHFAILED;
        }
 }
 
@@ -825,8 +819,8 @@ void cmd_down(char *argbuf) {
        {
                cprintf(Reply, CIT_OK + SERVER_SHUTTING_DOWN); 
        }
-       CC->kill_me = 1; /* Even the DOWN command has to follow correct proceedure when disconecting */
-       CtdlThreadStopAll();
+       CC->kill_me = KILLME_SERVER_SHUTTING_DOWN;
+       server_shutting_down = 1;
 }
 
 
@@ -838,7 +832,7 @@ void cmd_halt(char *argbuf) {
        if (CtdlAccessCheck(ac_aide)) return;
 
        cprintf("%d Halting server.  Goodbye.\n", CIT_OK);
-       CtdlThreadStopAll();
+       server_shutting_down = 1;
        shutdown_and_halt = 1;
 }
 
@@ -896,9 +890,6 @@ void cmd_asyn(char *argbuf)
  */
 void begin_session(CitContext *con)
 {
-       socklen_t len;
-       struct sockaddr_in sin;
-
        /* 
         * Initialize some variables specific to our context.
         */
@@ -923,7 +914,6 @@ void begin_session(CitContext *con)
        safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
        con->cs_UDSclientUID = -1;
        con->cs_host[sizeof con->cs_host - 1] = 0;
-       len = sizeof sin;
        if (!CC->is_local_socket) {
                locate_host(con->cs_host, sizeof con->cs_host,
                        con->cs_addr, sizeof con->cs_addr,
@@ -994,7 +984,7 @@ void citproto_begin_session() {
                        ERROR + MAX_SESSIONS_EXCEEDED,
                        config.c_nodename, config.c_maxsessions
                );
-               CC->kill_me = 1;
+               CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
        }
        else {
                cprintf("%d %s Citadel server ready.\n", CIT_OK, config.c_nodename);
@@ -1003,6 +993,12 @@ void citproto_begin_session() {
 }
 
 
+void citproto_begin_admin_session() {
+       CC->internal_pgm = 1;
+       cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, config.c_nodename);
+}
+
+
 void cmd_noop(char *argbuf)
 {
        cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
@@ -1018,7 +1014,7 @@ void cmd_qnop(char *argbuf)
 void cmd_quit(char *argbuf)
 {
        cprintf("%d Goodbye.\n", CIT_OK);
-       CC->kill_me = 1;
+       CC->kill_me = KILLME_CLIENT_LOGGED_OUT;
 }
 
 
@@ -1035,25 +1031,25 @@ void cmd_lout(char *argbuf)
  */
 void do_command_loop(void) {
        char cmdbuf[SIZ];
-       const char *old_name = NULL;
-       
-       old_name = CtdlThreadName("do_command_loop");
        
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
        if (client_getln(cmdbuf, sizeof cmdbuf) < 1) {
-               syslog(LOG_ERR, "Client disconnected: ending session.\n");
-               CC->kill_me = 1;
-               CtdlThreadName(old_name);
+               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, "CtdlCommand [%s] [%s] %s\n", CTDLUSERIP, CC->curr_user, cmdbuf);
+               syslog(LOG_INFO, "[%d][%s(%ld)] %s",
+                       CC->cs_pid, CC->curr_user, CC->user.usernum, cmdbuf
+               );
        }
        else {
-               syslog(LOG_INFO, "CtdlCommand [%s] [%s] <password command hidden from log>\n", CTDLUSERIP, CC->curr_user);
+               syslog(LOG_INFO, "[%d][%s(%ld)] <password command hidden from log>",
+                       CC->cs_pid, CC->curr_user, CC->user.usernum
+               );
        }
 
        buffer_output();
@@ -1073,8 +1069,6 @@ void do_command_loop(void) {
                time(&CC->lastidle);
        }
        
-       CtdlThreadName(cmdbuf);
-               
        if ((strncasecmp(cmdbuf, "ENT0", 4))
           && (strncasecmp(cmdbuf, "MESG", 4))
           && (strncasecmp(cmdbuf, "MSGS", 4)))
@@ -1090,7 +1084,6 @@ void do_command_loop(void) {
 
        /* Run any after-each-command routines registered by modules */
        PerformSessionHooks(EVT_CMD);
-       CtdlThreadName(old_name);
 }