/*
* $Id$
*
- * Citadel/UX "system dependent" stuff.
+ * Citadel "system dependent" stuff.
* See copyright.txt for copyright information.
*
* Here's where we (hopefully) have most parts of the Citadel server that
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 */
-static int rescan[2]; /* The rescan pipe */
pthread_t initial_thread; /* tid for main() thread */
* log data sent through this function. BE CAREFUL!
*/
void lprintf(enum LogLevel loglevel, const char *format, ...) {
- va_list arg_ptr;
+ va_list arg_ptr;
char buf[SIZ];
- va_start(arg_ptr, format);
- vsnprintf(buf, sizeof(buf), format, arg_ptr);
- va_end(arg_ptr);
+ va_start(arg_ptr, format);
+ vsnprintf(buf, sizeof(buf), format, arg_ptr);
+ va_end(arg_ptr);
if (syslog_facility >= 0) {
if (loglevel <= verbosity) {
* socket breaks.
*/
signal(SIGPIPE, SIG_IGN);
-
- /*
- * Set up the rescan pipe. When a session goes idle, it writes a
- * single byte to this pipe to wake up the thread calling select(),
- * which tells it to rescan the list of session sockets.
- */
- if (pipe(rescan) != 0) {
- lprintf(CTDL_EMERG, "Cannot create rescan pipe: %s\n",
- strerror(errno));
- abort();
- }
}
* a TCP port. The server shuts down if the bind fails.
*
*/
-int ig_tcp_server(int port_number, int queue_len)
+int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
{
struct sockaddr_in sin;
int s, i;
memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons((u_short)port_number);
+ if (ip_addr == NULL) {
+ sin.sin_addr.s_addr = INADDR_ANY;
+ }
+ else {
+ sin.sin_addr.s_addr = inet_addr(ip_addr);
+ }
+
+ if (sin.sin_addr.s_addr == INADDR_NONE) {
+ sin.sin_addr.s_addr = INADDR_ANY;
+ }
s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
/*
* buffer_output() ... tell client_write to buffer all output until
- * instructed to dump it all out later
+ * instructed to dump it all out later
*/
void buffer_output(void) {
if (CC->buffering == 0) {
/*
* cprintf() ... Send formatted printable data to the client. It is
- * implemented in terms of client_write() but remains in
- * sysdep.c in case we port to somewhere without va_args...
+ * implemented in terms of client_write() but remains in
+ * sysdep.c in case we port to somewhere without va_args...
*/
void cprintf(const char *format, ...) {
- va_list arg_ptr;
- char buf[SIZ];
+ va_list arg_ptr;
+ char buf[SIZ];
- va_start(arg_ptr, format);
- if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
+ va_start(arg_ptr, format);
+ if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
buf[sizeof buf - 2] = '\n';
client_write(buf, strlen(buf));
va_end(arg_ptr);
do_select: force_purge = 0;
bind_me = NULL; /* Which session shall we handle? */
- /* Initialize the fdset. Start with the rescan pipe. */
+ /* Initialize the fdset. */
FD_ZERO(&readfds);
- FD_SET(rescan[0], &readfds);
- highest = rescan[0] + 1;
+ highest = 0;
begin_critical_section(S_SESSION_TABLE);
for (ptr = ContextList; ptr != NULL; ptr = ptr->next) {
if (!time_to_die) {
tv.tv_sec = 1; /* wake up every second if no input */
tv.tv_usec = 0;
- /*
- * Avoid the "thundering herd" problem by letting only
- * one thread select() at a time.
- */
- begin_critical_section(S_I_WANNA_SELECT);
retval = select(highest + 1, &readfds, NULL, NULL, &tv);
- end_critical_section(S_I_WANNA_SELECT);
}
else {
break;
serviceptr->h_greeting_function();
become_session(NULL);
con->state = CON_IDLE;
-
- /* Wake up the currently blocking select() by
- * writing a dummy byte to the rescan pipe.
- */
- write(rescan[1], &i, 1);
goto do_select;
}
}
}
if (time_to_die) {
- end_critical_section(S_I_WANNA_SELECT);
break;
}
- /* If the rescan pipe went active, read a dummy byte from it */
- if (FD_ISSET(rescan[0], &readfds)) {
- read(rescan[0], &i, 1);
- goto do_select;
- }
-
/* It must be a client socket. Find a context that has data
* waiting on its socket *and* is in the CON_IDLE state. Any
* active sockets other than our chosen one are marked as
force_purge = CC->kill_me;
become_session(NULL);
bind_me->state = CON_IDLE;
-
- /* Wake up the currently blocking select() by writing
- * a dummy byte to the rescan pipe.
- */
- write(rescan[1], &i, 1);
}
dead_session_purge(force_purge);