}
}
+/*
+ * Grab a lock on the session, so other threads don't try to access
+ * the pipes at the same time.
+ */
+static void lock_session(struct wc_session *session) {
+ printf("Locking session %d...\n", session->session_id);
+ pthread_mutex_lock(&session->critter);
+ printf(" ...got lock\n");
+ }
+
+/*
+ * Let go of the lock.
+ */
+static void unlock_session(struct wc_session *session) {
+ printf("Unlocking.\n");
+ pthread_mutex_unlock(&session->critter);
+ }
+
extern const char *defaulthost;
extern const char *defaultport;
for (sptr=SessionList; sptr!=NULL; sptr=sptr->next) {
if (sptr->session_id == desired_session) {
TheSession = sptr;
+ lock_session(TheSession);
}
}
pthread_mutex_unlock(&MasterCritter);
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();
fflush(stdout); fflush(stdin);
if (f==0) {
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]);
execlp("./webcit", "webcit", str_session, defaulthost,
defaultport, NULL);
printf("HTTP/1.0 404 WebCit Failure\n\n");
printf("<BODY>execlp() failed</BODY></HTML>\n");
exit(0);
}
- pthread_mutex_unlock(&MasterCritter);
+ /* Close the ends of the pipes that we're not using */
+ close(TheSession->inpipe[0]);
+ close(TheSession->outpipe[1]);
}
- /*
- * Grab a lock on the session, so other threads don't try to access
- * the pipes at the same time.
- */
- printf("Locking session %d...\n", TheSession->session_id);
- pthread_mutex_lock(&TheSession->critter);
- printf(" ...got lock\n");
-
/*
* Send the request to the appropriate session...
*/
printf(" Closing socket\n");
close(sock);
- /*
- * Let go of the lock
- */
- printf("Unlocking.\n");
- pthread_mutex_unlock(&TheSession->critter);
-
-
+ unlock_session(TheSession);
/*
* If the last response included a "close session" directive,
printf("Removing session.\n");
pthread_mutex_lock(&MasterCritter);
+ lock_session(TheSession);
+
if (SessionList==TheSession) {
SessionList = SessionList->next;
}
}
}
}
-
+
+ close(TheSession->inpipe[1]);
+ close(TheSession->outpipe[0]);
+ unlock_session(TheSession);
free(TheSession);
pthread_mutex_unlock(&MasterCritter);
}
-
+ free(req);
/*
* The thread handling this HTTP connection is now finished.
-/*
- * Attach to a Citadel server
- */
-void attach_to_server(int argc, char **argv)
-{
- if (argc==1) {
- server_is_local = 1;
- serv_sock = connectsock("localhost","citadel","tcp");
- }
- if (argc==2) {
- serv_sock = connectsock(argv[1],"citadel","tcp");
- if ( (!strcmp(argv[1],"localhost"))
- || (!strcmp(argv[1],"127.0.0.1")) ) server_is_local = 1;
- }
- if (argc>=3) serv_sock = connectsock(argv[1],argv[2],"tcp");
-
- if (serv_sock < 0) exit(errno);
- }
-
-
/*
* send binary to server
*/