]> code.citadel.org Git - citadel.git/blobdiff - citadel/citserver.c
* There is now a dedicated thread for doing database checkpoints.
[citadel.git] / citadel / citserver.c
index edc26d9d4c7023c566bf2cb9b8d476108f4ab829..85f593641318e9bfdc56e7f1c72cf0ea5401ce6d 100644 (file)
@@ -101,7 +101,7 @@ void master_startup(void) {
        check_ref_counts();
 
        lprintf(CTDL_INFO, "Creating base rooms (if necessary)\n");
-       create_room(BASEROOM,           0, "", 0, 1, 0, VIEW_BBS);
+       create_room(config.c_baseroom,  0, "", 0, 1, 0, VIEW_BBS);
        create_room(AIDEROOM,           3, "", 0, 1, 0, VIEW_BBS);
        create_room(SYSCONFIGROOM,      3, "", 0, 1, 0, VIEW_BBS);
        create_room(config.c_twitroom,  0, "", 0, 1, 0, VIEW_BBS);
@@ -148,6 +148,14 @@ void master_cleanup(int exitcode) {
                (*fcn->h_function_pointer)();
        }
 
+       /* Shut down the indexer thread */
+       lprintf(CTDL_INFO, "Waiting for the indexer thread to shut down\n");
+       pthread_join(indexer_thread_tid, NULL);
+
+       /* Shut down the checkpoint thread */
+       lprintf(CTDL_INFO, "Waiting for the checkpoint thread to shut down\n");
+       pthread_join(checkpoint_thread_tid, NULL);
+
        /* Close databases */
        lprintf(CTDL_INFO, "Closing databases\n");
        close_databases();
@@ -170,33 +178,16 @@ void master_cleanup(int exitcode) {
 
 
 /*
- * Terminate a session and remove its context data structure.
+ * Terminate a session.
  */
 void RemoveContext (struct CitContext *con)
 {
        if (con==NULL) {
-               lprintf(CTDL_ERR, "WARNING: RemoveContext() called with NULL!\n");
+               lprintf(CTDL_ERR,
+                       "WARNING: RemoveContext() called with NULL!\n");
                return;
        }
-       lprintf(CTDL_DEBUG, "RemoveContext() called\n");
-
-       /* Remove the context from the global context list.  This needs
-        * to get done FIRST to avoid concurrency problems.  It is *vitally*
-        * important to keep num_sessions accurate!!
-        */
-       lprintf(CTDL_DEBUG, "Removing context for session %d\n", con->cs_pid);
-       begin_critical_section(S_SESSION_TABLE);
-       if (con->prev) {
-               con->prev->next = con->next;
-       }
-       else {
-               ContextList = con->next;
-       }
-       if (con->next) {
-               con->next->prev = con->prev;
-       }
-       --num_sessions;
-       end_critical_section(S_SESSION_TABLE);
+       lprintf(CTDL_DEBUG, "RemoveContext() session %d\n", con->cs_pid);
 
        /* Run any cleanup routines registered by loadable modules.
         * Note: We have to "become_session()" because the cleanup functions
@@ -210,18 +201,12 @@ void RemoveContext (struct CitContext *con)
        lprintf(CTDL_DEBUG, "Calling logout(%d)\n", con->cs_pid);
        logout(con);
 
-       unlink(con->temp);
        lprintf(CTDL_NOTICE, "[%3d] Session ended.\n", con->cs_pid);
 
        /* If the client is still connected, blow 'em away. */
        lprintf(CTDL_DEBUG, "Closing socket %d\n", con->client_socket);
        close(con->client_socket);
 
-       /* This is where we used to check for scheduled shutdowns. */
-
-       /* Free up the memory used by this context */
-       free(con);
-
        lprintf(CTDL_DEBUG, "Done with RemoveContext()\n");
 }
 
@@ -240,7 +225,7 @@ void cmd_info(void) {
        cprintf("%s\n", config.c_fqdn);
        cprintf("%s\n", CITADEL);
        cprintf("%d\n", REV_LEVEL);
-       cprintf("%s\n", config.c_bbs_city);
+       cprintf("%s\n", config.c_site_location);
        cprintf("%s\n", config.c_sysadm);
        cprintf("%d\n", SERVER_TYPE);
        cprintf("%s\n", config.c_moreprompt);
@@ -295,8 +280,8 @@ void cmd_time(void)
  */
 int is_public_client(void)
 {
-       char buf[SIZ];
-       char addrbuf[SIZ];
+       char buf[1024];
+       char addrbuf[1024];
        FILE *fp;
        int i;
        struct stat statbuf;
@@ -321,7 +306,7 @@ int is_public_client(void)
                begin_critical_section(S_PUBLIC_CLIENTS);
                lprintf(CTDL_INFO, "Loading %s\n", PUBLIC_CLIENTS);
 
-               strcpy(public_clients, "127.0.0.1");
+               safestrncpy(public_clients, "127.0.0.1", sizeof public_clients);
                if (hostname_to_dotted_quad(addrbuf, config.c_fqdn) == 0) {
                        strcat(public_clients, "|");
                        strcat(public_clients, addrbuf);
@@ -351,7 +336,7 @@ int is_public_client(void)
        lprintf(CTDL_DEBUG, "Checking whether %s is a local or public client\n",
                CC->cs_addr);
        for (i=0; i<num_parms(public_clients); ++i) {
-               extract(addrbuf, public_clients, i);
+               extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
                if (!strcasecmp(CC->cs_addr, addrbuf)) {
                        lprintf(CTDL_DEBUG, "... yes it is.\n");
                        return(1);
@@ -372,8 +357,8 @@ void cmd_iden(char *argbuf)
        int dev_code;
        int cli_code;
        int rev_level;
-       char desc[SIZ];
-       char from_host[SIZ];
+       char desc[128];
+       char from_host[128];
        struct in_addr addr;
        int do_lookup = 0;
 
@@ -385,11 +370,11 @@ void cmd_iden(char *argbuf)
        dev_code = extract_int(argbuf,0);
        cli_code = extract_int(argbuf,1);
        rev_level = extract_int(argbuf,2);
-       extract(desc,argbuf,3);
+       extract_token(desc, argbuf, 3, '|', sizeof desc);
 
        safestrncpy(from_host, config.c_fqdn, sizeof from_host);
        from_host[sizeof from_host - 1] = 0;
-       if (num_parms(argbuf)>=5) extract(from_host,argbuf,4);
+       if (num_parms(argbuf)>=5) extract_token(from_host, argbuf, 4, '|', sizeof from_host);
 
        CC->cs_clientdev = dev_code;
        CC->cs_clienttyp = cli_code;
@@ -432,24 +417,22 @@ void cmd_iden(char *argbuf)
 void cmd_mesg(char *mname)
 {
        FILE *mfp;
-       char targ[SIZ];
-       char buf[SIZ];
-       char buf2[SIZ];
+       char targ[256];
+       char buf[256];
+       char buf2[256];
        char *dirs[2];
 
-       extract(buf,mname,0);
+       extract_token(buf, mname, 0, '|', sizeof buf);
 
-       dirs[0]=malloc(64);
-       dirs[1]=malloc(64);
-       strcpy(dirs[0],"messages");
-       strcpy(dirs[1],"help");
+       dirs[0] = strdup("messages");
+       dirs[1] = strdup("help");
        snprintf(buf2, sizeof buf2, "%s.%d.%d", buf, CC->cs_clientdev, CC->cs_clienttyp);
-       mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+       mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
        if (strlen(targ) == 0) {
                snprintf(buf2, sizeof buf2, "%s.%d", buf, CC->cs_clientdev);
-               mesg_locate(targ,sizeof targ,buf2,2,(const char **)dirs);
+               mesg_locate(targ, sizeof targ, buf2, 2, (const char **)dirs);
                if (strlen(targ) == 0) {
-                       mesg_locate(targ,sizeof targ,buf,2,(const char **)dirs);
+                       mesg_locate(targ, sizeof targ, buf, 2, (const char **)dirs);
                }       
        }
        free(dirs[0]);
@@ -468,7 +451,7 @@ void cmd_mesg(char *mname)
        }
        cprintf("%d %s\n",LISTING_FOLLOWS,buf);
 
-       while (fgets(buf, (SIZ-1), mfp)!=NULL) {
+       while (fgets(buf, (sizeof buf - 1), mfp) != NULL) {
                buf[strlen(buf)-1] = 0;
                do_help_subst(buf);
                cprintf("%s\n",buf);
@@ -485,8 +468,8 @@ void cmd_mesg(char *mname)
 void cmd_emsg(char *mname)
 {
        FILE *mfp;
-       char targ[SIZ];
-       char buf[SIZ];
+       char targ[256];
+       char buf[256];
        char *dirs[2];
        int a;
 
@@ -494,16 +477,14 @@ void cmd_emsg(char *mname)
 
        if (CtdlAccessCheck(ac_aide)) return;
 
-       extract(buf,mname,0);
+       extract_token(buf, mname, 0, '|', sizeof buf);
        for (a=0; a<strlen(buf); ++a) {         /* security measure */
                if (buf[a] == '/') buf[a] = '.';
        }
 
-       dirs[0]=malloc(64);
-       dirs[1]=malloc(64);
-       strcpy(dirs[0],"messages");
-       strcpy(dirs[1],"help");
-       mesg_locate(targ,sizeof targ,buf,2,(const char**)dirs);
+       dirs[0] = strdup("messages");
+       dirs[1] = strdup("help");
+       mesg_locate(targ, sizeof targ, buf, 2, (const char**)dirs);
        free(dirs[0]);
        free(dirs[1]);
 
@@ -787,13 +768,12 @@ void begin_session(struct CitContext *con)
        strcpy(con->lastcmdname, "    ");
        strcpy(con->cs_clientname, "(unknown)");
        strcpy(con->curr_user, NLI);
-       strcpy(con->net_node,"");
+       strcpy(con->net_node, "");
        strcpy(con->fake_username, "");
        strcpy(con->fake_postname, "");
        strcpy(con->fake_hostname, "");
        strcpy(con->fake_roomname, "");
        generate_nonce(con);
-       safestrncpy(con->temp, tmpnam(NULL), sizeof con->temp);
        safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
        safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
        con->cs_host[sizeof con->cs_host - 1] = 0;
@@ -843,7 +823,7 @@ void citproto_begin_session() {
  * This loop recognizes all server commands.
  */
 void do_command_loop(void) {
-       char cmdbuf[SIZ];
+       char cmdbuf[1024];
 
        time(&CC->lastcmd);
        memset(cmdbuf, 0, sizeof cmdbuf); /* Clear it, just in case */
@@ -873,8 +853,7 @@ void do_command_loop(void) {
           && (strncasecmp(cmdbuf, "PEXP", 4))
           && (strncasecmp(cmdbuf, "GEXP", 4)) ) {
                strcpy(CC->lastcmdname, "    ");
-               safestrncpy(CC->lastcmdname, cmdbuf, 
-                       sizeof(CC->lastcmdname) );
+               safestrncpy(CC->lastcmdname, cmdbuf, sizeof(CC->lastcmdname));
                time(&CC->lastidle);
        }
                
@@ -885,11 +864,11 @@ void do_command_loop(void) {
           CC->cs_flags &= ~CS_POSTING;
        }
                   
-       if (!strncasecmp(cmdbuf,"NOOP",4)) {
+       if (!strncasecmp(cmdbuf, "NOOP", 4)) {
                cprintf("%d%cok\n", CIT_OK, CtdlCheckExpress() );
        }
        
-       else if (!strncasecmp(cmdbuf,"QNOP",4)) {
+       else if (!strncasecmp(cmdbuf, "QNOP", 4)) {
                /* do nothing, this command returns no response */
        }