#include "housekeeping.h"
#include "tools.h"
#include "serv_crypto.h"
+#include "serv_fulltext.h"
#ifdef HAVE_SYS_SELECT_H
#include <sys/select.h>
time_t last_purge = 0; /* Last dead session purge */
static int num_threads = 0; /* Current number of threads */
int num_sessions = 0; /* Current number of sessions */
+pthread_t indexer_thread_tid;
+pthread_t checkpoint_thread_tid;
int syslog_facility = (-1);
int enable_syslog = 0;
* Initialize a new context and place it in the list. The session number
* used to be the PID (which is why it's called cs_pid), but that was when we
* had one process per session. Now we just assign them sequentially, starting
- * at 1 (don't change it to 0 because masterCC uses 0) and re-using them when
- * sessions terminate.
+ * at 1 (don't change it to 0 because masterCC uses 0).
*/
struct CitContext *CreateNewContext(void) {
struct CitContext *me;
return;
}
- if (CC->redirect_fp != NULL) {
- fwrite(buf, (size_t)nbytes, (size_t)1, CC->redirect_fp);
- return;
- }
-
#ifndef HAVE_TCP_BUFFERING
/* If we're buffering for later, do that now. */
if (CC->buffering) {
buf[i] = 0;
while ((strlen(buf)>0)&&(!isprint(buf[strlen(buf)-1])))
buf[strlen(buf)-1] = 0;
- if (retval < 0) strcpy(buf, "000");
+ if (retval < 0) safestrncpy(buf, "000", bufsize);
return(retval);
}
return;
}
- /* Our per-thread stacks need to be bigger than the default size, otherwise
- * the MIME parser crashes on FreeBSD, and the IMAP service crashes on
- * 64-bit Linux.
+ /* Our per-thread stacks need to be bigger than the default size,
+ * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+ * crashes on 64-bit Linux.
*/
- if ((ret = pthread_attr_setstacksize(&attr, 1024 * 1024))) {
- lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n", strerror(ret));
+ if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+ lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+ strerror(ret));
time_to_die = -1;
pthread_attr_destroy(&attr);
return;
}
+/*
+ * Create the indexer thread and begin its operation.
+ * Then create the checkpoint thread and begin its operation.
+ */
+void create_maintenance_threads(void) {
+ int ret;
+ pthread_attr_t attr;
+
+ if ((ret = pthread_attr_init(&attr))) {
+ lprintf(CTDL_EMERG, "pthread_attr_init: %s\n", strerror(ret));
+ time_to_die = -1;
+ return;
+ }
+
+ /* Our per-thread stacks need to be bigger than the default size,
+ * otherwise the MIME parser crashes on FreeBSD, and the IMAP service
+ * crashes on 64-bit Linux.
+ */
+ if ((ret = pthread_attr_setstacksize(&attr, THREADSTACKSIZE))) {
+ lprintf(CTDL_EMERG, "pthread_attr_setstacksize: %s\n",
+ strerror(ret));
+ time_to_die = -1;
+ pthread_attr_destroy(&attr);
+ return;
+ }
+
+ if ((ret = pthread_create(&indexer_thread_tid, &attr, indexer_thread, NULL) != 0)) {
+ lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
+ }
+
+ if ((ret = pthread_create(&checkpoint_thread_tid, &attr, checkpoint_thread, NULL) != 0)) {
+ lprintf(CTDL_ALERT, "Can't create thread: %s\n", strerror(ret));
+ }
+
+ pthread_attr_destroy(&attr);
+}
+
+
/*
* Purge all sessions which have the 'kill_me' flag set.
-/*
- * Redirect a session's output to a file.
- * This function may be called with a file handle.
- * Call with NULL to return output to its normal client socket.
- */
-void CtdlRedirectOutput(FILE *fp)
-{
- if (fp != NULL) CC->redirect_fp = fp;
- else CC->redirect_fp = NULL;
-}
-
-
/*
* masterCC is the context we use when not attached to a session. This
* function initializes it.