]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* Finished removing all the "dynamic session data" stuff in order to
[citadel.git] / citadel / sysdep.c
index 917cb16537285ab6a887ae39116fcd08d6419b9f..b571b8b478674dbc558c7c41d32f78a997f4d56e 100644 (file)
@@ -211,17 +211,18 @@ void init_sysdep(void) {
        sigaddset(&set, SIGQUIT);
        sigaddset(&set, SIGHUP);
        sigaddset(&set, SIGTERM);
-       sigaddset(&set, SIGSEGV);
-       sigaddset(&set, SIGILL);
-       sigaddset(&set, SIGBUS);
+       // sigaddset(&set, SIGSEGV);    commented out because
+       // sigaddset(&set, SIGILL);     we want core dumps
+       // sigaddset(&set, SIGBUS);
        sigprocmask(SIG_UNBLOCK, &set, NULL);
+
        signal(SIGINT, signal_cleanup);
        signal(SIGQUIT, signal_cleanup);
        signal(SIGHUP, signal_cleanup);
        signal(SIGTERM, signal_cleanup);
-       signal(SIGSEGV, signal_cleanup);
-       signal(SIGILL, signal_cleanup);
-       signal(SIGBUS, signal_cleanup);
+       // signal(SIGSEGV, signal_cleanup);     commented out because
+       // signal(SIGILL, signal_cleanup);      we want core dumps
+       // signal(SIGBUS, signal_cleanup);
 
        /*
         * Do not shut down the server on broken pipe signals, otherwise the
@@ -409,7 +410,8 @@ struct CitContext *MyContext(void) {
  * sessions terminate.
  */
 struct CitContext *CreateNewContext(void) {
-       struct CitContext *me, *ptr;
+       struct CitContext *me;
+       static int next_pid = 0;
 
        me = (struct CitContext *) malloc(sizeof(struct CitContext));
        if (me == NULL) {
@@ -430,42 +432,14 @@ struct CitContext *CreateNewContext(void) {
         * the list.
         */
        begin_critical_section(S_SESSION_TABLE);
-
-       if (ContextList == NULL) {
-               ContextList = me;
-               me->cs_pid = 1;
-               me->prev = NULL;
-               me->next = NULL;
-       }
-
-       else if (ContextList->cs_pid > 1) {
-               me->prev = NULL;
-               me->next = ContextList;
-               ContextList = me;
-               me->cs_pid = 1;
-       }
-
-       else {
-               for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
-                       if (ptr->next == NULL) {
-                               ptr->next = me;
-                               me->cs_pid = ptr->cs_pid + 1;
-                               me->prev = ptr;
-                               me->next = NULL;
-                               goto DONE;
-                       }
-                       else if (ptr->next->cs_pid > (ptr->cs_pid+1)) {
-                               me->prev = ptr;
-                               me->next = ptr->next;
-                               ptr->next->prev = me;
-                               ptr->next = me;
-                               me->cs_pid = ptr->cs_pid + 1;
-                               goto DONE;
-                       }
-               }
+       me->cs_pid = ++next_pid;
+       me->prev = NULL;
+       me->next = ContextList;
+       ContextList = me;
+       if (me->next != NULL) {
+               me->next->prev = me;
        }
-
-DONE:  ++num_sessions;
+       ++num_sessions;
        end_critical_section(S_SESSION_TABLE);
        return(me);
 }
@@ -548,7 +522,7 @@ void client_write(char *buf, int nbytes)
 
        if (CC->redirect_buffer != NULL) {
                if ((CC->redirect_len + nbytes + 2) >= CC->redirect_alloc) {
-                       CC->redirect_alloc = CC->redirect_alloc * 2;
+                       CC->redirect_alloc = (CC->redirect_alloc * 2) + nbytes;
                        CC->redirect_buffer = realloc(CC->redirect_buffer,
                                                CC->redirect_alloc);
                }
@@ -1030,12 +1004,7 @@ do_select:       force_purge = 0;
 
                        if (FD_ISSET(serviceptr->msock, &readfds)) {
                                ssock = accept(serviceptr->msock, NULL, 0);
-                               if (ssock < 0) {
-                                       lprintf(CTDL_CRIT,
-                                               "citserver: accept(): %s\n",
-                                               strerror(errno));
-                               }
-                               else {
+                               if (ssock >= 0) {
                                        lprintf(CTDL_DEBUG,
                                                "New client socket %d\n",
                                                ssock);