- printf("Creating a new session\n");
- locate_host(browser_host, sock);
- pthread_mutex_lock(&MasterCritter);
- TheSession = (struct wc_session *)
- malloc(sizeof(struct wc_session));
- TheSession->session_id = GenerateSessionID();
- pipe(TheSession->inpipe);
- pipe(TheSession->outpipe);
- pthread_mutex_init(&TheSession->critter, NULL);
- lock_session(TheSession);
- TheSession->next = SessionList;
- SessionList = TheSession;
- pthread_mutex_unlock(&MasterCritter);
- sprintf(str_session, "%d", TheSession->session_id);
- f = fork();
- if (f > 0)
- TheSession->webcit_pid = f;
-
- fflush(stdout);
- fflush(stdin);
- if (f == 0) {
-
- /* Hook stdio to the ends of the pipe we're using */
- dup2(TheSession->inpipe[0], 0);
- dup2(TheSession->outpipe[1], 1);
-
- /* Close the ends of the pipes that we're not using */
- close(TheSession->inpipe[1]);
- close(TheSession->outpipe[0]);
-
- /* Close the HTTP socket in this pid; don't need it */
- close(sock);
-
- /* Run the actual WebCit session */
- execlp("./webcit", "webcit", str_session, defaulthost,
- defaultport, browser_host, browser, NULL);
-
- /* Simple page to display if exec fails */
- printf("HTTP/1.0 404 WebCit Failure\n\n");
- printf("Server: %s\n", SERVER);
- printf("X-WebCit-Session: close\n");
- printf("Content-type: text/html\n");
- printf("Content-length: 76\n");
- printf("\n");
- printf("<HTML><HEAD><TITLE>Error</TITLE></HEAD><BODY>\n");
- printf("execlp() failed: %s</BODY></HTML>\n", strerror(errno));
- exit(0);
- } else {
- /* Close the ends of the pipes that we're not using */
- close(TheSession->inpipe[0]);
- close(TheSession->outpipe[1]);
+ lprintf(3, "Creating a new session\n");
+ TheSession = (struct wcsession *)
+ malloc(sizeof(struct wcsession));
+ memset(TheSession, 0, sizeof(struct wcsession));
+ TheSession->serv_sock = (-1);
+ TheSession->chat_sock = (-1);
+
+ /* If we're recreating a session that expired, it's best to give it the same
+ * session number that it had before. The client browser ought to pick up
+ * the new session number and start using it, but in some rare situations it
+ * doesn't, and that's a Bad Thing because it causes lots of spurious sessions
+ * to get created.
+ */
+ if (desired_session == 0) {
+ TheSession->wc_session = GenerateSessionID();