/*
- * Create an interface to lprintf that follows the coding convention.
- * This is here until such time as we have replaced all calls to lprintf with CtdlLogPrintf
+ * CtdlLogPrintf() ... Write logging information
*/
-
-void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...)
-{
+void CtdlLogPrintf(enum LogLevel loglevel, const char *format, ...) {
va_list arg_ptr;
va_start(arg_ptr, format);
- vlprintf(loglevel, format, arg_ptr);
+ vCtdlLogPrintf(loglevel, format, arg_ptr);
va_end(arg_ptr);
}
-
-/*
- * lprintf() ... Write logging information
- */
-void lprintf(enum LogLevel loglevel, const char *format, ...) {
- va_list arg_ptr;
- va_start(arg_ptr, format);
- vlprintf(loglevel, format, arg_ptr);
- va_end(arg_ptr);
-}
-
-void vlprintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
+void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
{
char buf[SIZ], buf2[SIZ];
volatile int running_as_daemon = 0;
static RETSIGTYPE signal_cleanup(int signum) {
- CtdlLogPrintf(CTDL_DEBUG, "Caught signal %d; shutting down.\n", signum);
#ifdef THREADS_USESIGNALS
if (CT)
- {
- CtdlLogPrintf(CTDL_DEBUG, "Thread \"%s\" caught signal %d.\n", CT->name, signum);
CT->signal = signum;
- }
else
#endif
+ {
+ CtdlLogPrintf(CTDL_DEBUG, "Caught signal %d; shutting down.\n", signum);
exit_signal = signum;
+ }
}
}
+struct CitContext *CtdlGetContextArray(int *count)
+{
+ int nContexts, i;
+ struct CitContext *nptr, *cptr;
+
+ nContexts = num_sessions;
+ nptr = malloc(sizeof(struct CitContext) * nContexts);
+ if (!nptr)
+ return NULL;
+ begin_critical_section(S_SESSION_TABLE);
+ for (cptr = ContextList, i=0; cptr != NULL && i < nContexts; cptr = cptr->next, i++)
+ memcpy(&nptr[i], cptr, sizeof (struct CitContext));
+ end_critical_section (S_SESSION_TABLE);
+
+ *count = i;
+ return nptr;
+}
+
/*
* The following functions implement output buffering. If the kernel supplies
* native TCP buffering (Linux & *BSD), use that; otherwise, emulate it with
/*
* client_write() ... Send binary data to the client.
*/
-void client_write(char *buf, int nbytes)
+int client_write(char *buf, int nbytes)
{
int bytes_written = 0;
int retval;
memcpy(&Ctx->redirect_buffer[Ctx->redirect_len], buf, nbytes);
Ctx->redirect_len += nbytes;
Ctx->redirect_buffer[Ctx->redirect_len] = 0;
- return;
+ return 0;
}
#ifndef HAVE_TCP_BUFFERING
Ctx->buffer_len += nbytes;
Ctx->output_buffer = realloc(Ctx->output_buffer, Ctx->buffer_len);
memcpy(&Ctx->output_buffer[old_buffer_len], buf, nbytes);
- return;
+ return 0;
}
#endif
#ifdef HAVE_OPENSSL
if (Ctx->redirect_ssl) {
client_write_ssl(buf, nbytes);
- return;
+ return 0;
}
#endif
strerror(errno), errno);
cit_backtrace();
Ctx->kill_me = 1;
- return;
+ return -1;
}
}
cit_backtrace();
// CtdlLogPrintf(CTDL_DEBUG, "Tried to send: %s", &buf[bytes_written]);
Ctx->kill_me = 1;
- return;
+ return -1;
}
bytes_written = bytes_written + retval;
}
+ return 0;
}
retval = select( (fd)+1,
&rfds, NULL, NULL, &tv);
+ if (retval < 0)
+ {
+ if (errno == EINTR)
+ {
+ CtdlLogPrintf(CTDL_DEBUG, "Interrupted select().\n");
+ CC->kill_me = 1;
+ return (-1);
+ }
+ }
if (FD_ISSET(fd, &rfds) == 0) {
return(0);
rem = ptr->next;
--num_sessions;
- lprintf(CTDL_DEBUG, "Purging session %d\n", ptr->cs_pid);
+ CtdlLogPrintf(CTDL_DEBUG, "Purging session %d\n", ptr->cs_pid);
RemoveContext(ptr);
free (ptr);
ptr = rem;
-
-
/*
* Bind a thread to a context. (It's inline merely to speed things up.)
*/
tv.tv_usec = 0;
retval = CtdlThreadSelect(highest + 1, &readfds, NULL, NULL, &tv);
}
-
- if (CtdlThreadCheckStop()) return(NULL);
+ else
+ return NULL;
/* Now figure out who made this select() unblock.
* First, check for an error or exit condition.
if (errno != EINTR) {
CtdlLogPrintf(CTDL_EMERG, "Exiting (%s)\n", strerror(errno));
CtdlThreadStopAll();
- } else if (!CtdlThreadCheckStop()) {
- CtdlLogPrintf(CTDL_DEBUG, "Interrupted select.\n");
+ } else {
+ CtdlLogPrintf(CTDL_DEBUG, "Interrupted CtdlThreadSelect.\n");
+ if (CtdlThreadCheckStop()) return(NULL);
goto do_select;
}
}
else if(retval == 0) {
+ if (CtdlThreadCheckStop()) return(NULL);
goto SKIP_SELECT;
}
/* Next, check to see if it's a new client connecting