]> code.citadel.org Git - citadel.git/blobdiff - citadel/sysdep.c
* Temporary hack to ig_tcp_server() to listen on an arbitrary port if the
[citadel.git] / citadel / sysdep.c
index 0cd19053a53ab064009324bbe667c9e225ca615b..6bde9f3961d93b173dd2d96490dd4630a8f9f4a8 100644 (file)
@@ -285,7 +285,16 @@ int ig_tcp_server(int port_number, int queue_len)
 
        if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
                lprintf(1, "citserver: Can't bind: %s\n", strerror(errno));
-               return(-1);
+               sin.sin_port = 0;
+               if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
+                       lprintf(1, "citserver: Can't bind: %s\n",
+                               strerror(errno));
+                       return(-1);
+               }
+               else {
+                       lprintf(1, "bind to alternate port %d ok\n",
+                               htons(sin.sin_port) );
+               }
        }
 
        if (listen(s, queue_len) < 0) {
@@ -880,8 +889,12 @@ int main(int argc, char **argv)
 }
 
 
-
-
+/*
+ * Bind a thread to a context.
+ */
+inline void become_session(struct CitContext *which_con) {
+       pthread_setspecific(MyConKey, (void *)which_con );
+}
 
 
 
@@ -974,12 +987,10 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
                                                SO_REUSEADDR,
                                                &i, sizeof(i));
 
-                                       pthread_setspecific(MyConKey,
-                                               (void *)con);
+                                       become_session(con);
                                        begin_session(con);
                                        serviceptr->h_greeting_function();
-                                       pthread_setspecific(MyConKey,
-                                               (void *)NULL);
+                                       become_session(NULL);
                                        con->state = CON_IDLE;
                                        goto SETUP_FD;
                                }
@@ -1021,9 +1032,9 @@ SETUP_FD: memcpy(&readfds, &masterfds, sizeof(fd_set) );
 
                        /* We're bound to a session, now do *one* command */
                        if (bind_me != NULL) {
-                               pthread_setspecific(MyConKey, (void *)bind_me);
+                               become_session(bind_me);
                                CC->h_command_function();
-                               pthread_setspecific(MyConKey, (void *)NULL);
+                               become_session(NULL);
                                bind_me->state = CON_IDLE;
                                if (bind_me->kill_me == 1) {
                                        RemoveContext(bind_me);