#include <pwd.h>
#include <pthread.h>
#include <sys/stat.h>
-#include <signal.h>
#include <sys/un.h>
+#include <signal.h>
+#include <setjmp.h>
+#include <stropts.h>
/*
* Actual definitions of config globals
API_VAR_EXPORT const char *ap_scoreboard_fname=NULL;
static int num_daemons=0;
static int curr_child_num=0;
-static int socket_num=0;
static int workers_may_exit = 0;
static int requests_this_child;
static int num_listenfds = 0;
-static ap_socket_t **listenfds;
+static apr_socket_t **listenfds;
+static jmp_buf jmpbuffer;
struct child_info_t {
uid_t uid;
gid_t gid;
- char *name; /* The extention for this socket. "uig:gid" */
- int num;
int sd;
};
-struct socket_info_t {
- const char *sname; /* The servername */
- int cnum; /* The socket number */
-};
-
typedef struct {
- const char *sockname;
+ const char *sockname; /* The base name for the socket */
+ const char *fullsockname; /* socket base name + extension */
+ int sd; /* The socket descriptor */
+ int sd2; /* The socket descriptor */
} perchild_server_conf;
typedef struct child_info_t child_info_t;
-typedef struct socket_info_t socket_info_t;
/* Tables used to determine the user and group each child process should
* run as. The hash table is used to correlate a server name with a child
* process.
*/
static child_info_t child_info_table[HARD_SERVER_LIMIT];
-static ap_hash_t *socket_info_table = NULL;
+static int thread_socket_table[HARD_THREAD_LIMIT];
struct ap_ctable ap_child_table[HARD_SERVER_LIMIT];
module MODULE_VAR_EXPORT mpm_perchild_module;
-static ap_file_t *pipe_of_death_in = NULL;
-static ap_file_t *pipe_of_death_out = NULL;
+static apr_file_t *pipe_of_death_in = NULL;
+static apr_file_t *pipe_of_death_out = NULL;
static pthread_mutex_t pipe_of_death_mutex;
/* *Non*-shared http_main globals... */
int raise_sigstop_flags;
#endif
-static ap_pool_t *pconf; /* Pool for config stuff */
-static ap_pool_t *pchild; /* Pool for httpd child stuff */
-static ap_pool_t *thread_pool_parent; /* Parent of per-thread pools */
+static apr_pool_t *pconf; /* Pool for config stuff */
+static apr_pool_t *pchild; /* Pool for httpd child stuff */
+static apr_pool_t *thread_pool_parent; /* Parent of per-thread pools */
static pthread_mutex_t thread_pool_parent_mutex;
static int child_num;
#define SAFE_ACCEPT(stmt) APR_SUCCESS
#else
#define SAFE_ACCEPT(stmt) (stmt)
-static ap_lock_t *process_accept_mutex;
+static apr_lock_t *process_accept_mutex;
#endif /* NO_SERIALIZED_ACCEPT */
static const char *lock_fname;
static pthread_mutex_t thread_accept_mutex = PTHREAD_MUTEX_INITIALIZER;
static void clean_child_exit(int code)
{
if (pchild) {
- ap_destroy_pool(pchild);
+ apr_destroy_pool(pchild);
}
exit(code);
}
static void sig_coredump(int sig)
{
chdir(ap_coredump_dir);
- ap_signal(sig, SIG_DFL);
+ apr_signal(sig, SIG_DFL);
kill(getpid(), sig);
/* At this point we've got sig blocked, because we're still inside
* the signal handler. When we leave the signal handler it will
restart_pending = 1;
is_graceful = graceful;
if (is_graceful) {
- ap_kill_cleanup(pconf, NULL, ap_cleanup_shared_mem);
+ apr_kill_cleanup(pconf, NULL, ap_cleanup_shared_mem);
}
}
ap_log_error(APLOG_MARK, APLOG_WARNING, errno, ap_server_conf, "sigaction(SIGWINCH)");
#else
if (!one_process) {
- ap_signal(SIGSEGV, sig_coredump);
+ apr_signal(SIGSEGV, sig_coredump);
#ifdef SIGBUS
- ap_signal(SIGBUS, sig_coredump);
+ apr_signal(SIGBUS, sig_coredump);
#endif /* SIGBUS */
#ifdef SIGABORT
- ap_signal(SIGABORT, sig_coredump);
+ apr_signal(SIGABORT, sig_coredump);
#endif /* SIGABORT */
#ifdef SIGABRT
- ap_signal(SIGABRT, sig_coredump);
+ apr_signal(SIGABRT, sig_coredump);
#endif /* SIGABRT */
#ifdef SIGILL
- ap_signal(SIGILL, sig_coredump);
+ apr_signal(SIGILL, sig_coredump);
#endif /* SIGILL */
#ifdef SIGXCPU
- ap_signal(SIGXCPU, SIG_DFL);
+ apr_signal(SIGXCPU, SIG_DFL);
#endif /* SIGXCPU */
#ifdef SIGXFSZ
- ap_signal(SIGXFSZ, SIG_DFL);
+ apr_signal(SIGXFSZ, SIG_DFL);
#endif /* SIGXFSZ */
}
- ap_signal(SIGTERM, sig_term);
+ apr_signal(SIGTERM, sig_term);
#ifdef SIGHUP
- ap_signal(SIGHUP, restart);
+ apr_signal(SIGHUP, restart);
#endif /* SIGHUP */
#ifdef SIGWINCH
- ap_signal(SIGWINCH, restart);
+ apr_signal(SIGWINCH, restart);
#endif /* SIGWINCH */
#ifdef SIGPIPE
- ap_signal(SIGPIPE, SIG_IGN);
+ apr_signal(SIGPIPE, SIG_IGN);
#endif /* SIGPIPE */
#endif
* Child process main loop.
*/
-static void process_socket(ap_pool_t *p, ap_socket_t *sock, long conn_id)
+static void process_socket(apr_pool_t *p, apr_socket_t *sock, long conn_id)
{
BUFF *conn_io;
conn_rec *current_conn;
ap_iol *iol;
int csd;
- ap_status_t rv;
+ apr_status_t rv;
+ int thread_num = conn_id % HARD_THREAD_LIMIT;
- if ((rv = ap_get_os_sock(&csd, sock)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "ap_get_os_sock");
+ if ((rv = apr_get_os_sock(&csd, sock)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, NULL, "apr_get_os_sock");
}
if (csd >= FD_SETSIZE) {
"to rebuild Apache with a larger FD_SETSIZE "
"(currently %d)",
csd, FD_SETSIZE);
- ap_close_socket(sock);
+ apr_close_socket(sock);
return;
}
- ap_sock_disable_nagle(csd);
+ if (thread_socket_table[thread_num] < 0) {
+ ap_sock_disable_nagle(sock);
+ }
iol = ap_iol_attach_socket(p, sock);
conn_io = ap_bcreate(p, B_RDWR);
ap_bpush_iol(conn_io, iol);
if (!workers_may_exit) {
int ret;
char pipe_read_char;
- ap_ssize_t n = 1;
+ apr_ssize_t n = 1;
- ret = ap_recv(listenfds[0], &pipe_read_char, &n);
- if (ap_canonical_error(ret) == APR_EAGAIN) {
+ ret = apr_recv(listenfds[0], &pipe_read_char, &n);
+ if (apr_canonical_error(ret) == APR_EAGAIN) {
/* It lost the lottery. It must continue to suffer
* through a life of servitude. */
}
static void *worker_thread(void *arg)
{
- ap_socket_t *csd = NULL;
- ap_pool_t *tpool; /* Pool for this thread */
- ap_pool_t *ptrans; /* Pool for per-transaction stuff */
- ap_socket_t *sd = NULL;
+ apr_socket_t *csd = NULL;
+ apr_pool_t *tpool; /* Pool for this thread */
+ apr_pool_t *ptrans; /* Pool for per-transaction stuff */
+ apr_socket_t *sd = NULL;
int srv;
int curr_pollfd, last_pollfd = 0;
int thread_just_started = 1;
int thread_num = *((int *) arg);
long conn_id = child_num * HARD_THREAD_LIMIT + thread_num;
- ap_pollfd_t *pollset;
+ apr_pollfd_t *pollset;
int n;
- ap_status_t rv;
+ apr_status_t rv;
pthread_mutex_lock(&thread_pool_parent_mutex);
- ap_create_pool(&tpool, thread_pool_parent);
+ apr_create_pool(&tpool, thread_pool_parent);
pthread_mutex_unlock(&thread_pool_parent_mutex);
- ap_create_pool(&ptrans, tpool);
+ apr_create_pool(&ptrans, tpool);
- ap_setup_poll(&pollset, num_listenfds+1, tpool);
- for(n=0 ; n <= num_listenfds ; ++n)
- ap_add_poll_socket(pollset, listenfds[n], APR_POLLIN);
+ apr_setup_poll(&pollset, num_listenfds+1, tpool);
+ for(n=0 ; n <= num_listenfds ; ++n) {
+ apr_add_poll_socket(pollset, listenfds[n], APR_POLLIN);
+ }
while (!workers_may_exit) {
workers_may_exit |= (max_requests_per_child != 0) && (requests_this_child <= 0);
pthread_mutex_unlock(&thread_accept_mutex);
break;
}
- if ((rv = SAFE_ACCEPT(ap_lock(process_accept_mutex)))
+ if ((rv = SAFE_ACCEPT(apr_lock(process_accept_mutex)))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
- "ap_lock failed. Attempting to shutdown "
+ "apr_lock failed. Attempting to shutdown "
"process gracefully.");
workers_may_exit = 1;
}
while (!workers_may_exit) {
- ap_int16_t event;
- srv = ap_poll(pollset, &n, -1);
+ apr_int16_t event;
+ srv = apr_poll(pollset, &n, -1);
if (srv != APR_SUCCESS) {
- if (ap_canonical_error(srv) == APR_EINTR) {
+ if (apr_canonical_error(srv) == APR_EINTR) {
continue;
}
- /* ap_poll() will only return errors in catastrophic
+ /* apr_poll() will only return errors in catastrophic
* circumstances. Let's try exiting gracefully, for now. */
ap_log_error(APLOG_MARK, APLOG_ERR, srv, (const server_rec *)
- ap_server_conf, "ap_poll: (listen)");
+ ap_server_conf, "apr_poll: (listen)");
workers_may_exit = 1;
}
if (workers_may_exit) break;
- ap_get_revents(&event, listenfds[0], pollset);
+ apr_get_revents(&event, listenfds[0], pollset);
if (event & APR_POLLIN) {
/* A process got a signal on the shutdown pipe. Check if we're
* the lucky process to die. */
check_pipe_of_death();
continue;
}
+
+ apr_get_revents(&event, listenfds[1], pollset);
+ if (event & APR_POLLIN || event & APR_POLLOUT) {
+ /* This request is from another child in our current process.
+ * We should set a flag here, and then below we will read
+ * two bytes (the socket number and the NULL byte.
+ */
+ thread_socket_table[thread_num] = -2;
+ goto got_from_other_child;
+ }
if (num_listenfds == 1) {
sd = ap_listeners->sd;
curr_pollfd = 1;
}
/* XXX: Should we check for POLLERR? */
- ap_get_revents(&event, listenfds[curr_pollfd], pollset);
+ apr_get_revents(&event, listenfds[curr_pollfd], pollset);
if (event & APR_POLLIN) {
last_pollfd = curr_pollfd;
sd = listenfds[curr_pollfd];
}
got_fd:
if (!workers_may_exit) {
- if ((rv = ap_accept(&csd, sd, ptrans)) != APR_SUCCESS) {
- ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, "ap_accept");
+ if ((rv = apr_accept(&csd, sd, ptrans)) != APR_SUCCESS) {
+ ap_log_error(APLOG_MARK, APLOG_ERR, rv, ap_server_conf, "apr_accept");
}
- if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex)))
+ if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
- "ap_unlock failed. Attempting to shutdown "
+ "apr_unlock failed. Attempting to shutdown "
"process gracefully.");
workers_may_exit = 1;
}
}
}
pthread_mutex_unlock(&idle_thread_count_mutex);
- process_socket(ptrans, csd, conn_id);
+ got_from_other_child:
+ if (thread_socket_table[thread_num] == -2) {
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ char sockname[80];
+ struct iovec iov;
+ int ret, sd, dp;
+
+ iov.iov_base = sockname;
+ iov.iov_len = 80;
+
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ cmsg = apr_palloc(ptrans, sizeof(*cmsg) + sizeof(sd));
+ cmsg->cmsg_len = sizeof(*cmsg) + sizeof(sd);
+ msg.msg_control = cmsg;
+ msg.msg_controllen = cmsg->cmsg_len;
+ msg.msg_flags = 0;
+
+ ret = recvmsg(child_info_table[child_num].sd, &msg, 0);
+
+ memcpy(&dp, CMSG_DATA(cmsg), sizeof(dp));
+
+ thread_socket_table[thread_num] = dp;
+ apr_put_os_sock(&csd, &child_info_table[child_num].sd, ptrans);
+ }
+ if (setjmp(jmpbuffer) != 1) {
+ process_socket(ptrans, csd, conn_id);
+ }
+ else {
+ thread_socket_table[thread_num] = -1;
+ }
requests_this_child--;
} else {
- if ((rv = SAFE_ACCEPT(ap_unlock(process_accept_mutex)))
+ if ((rv = SAFE_ACCEPT(apr_unlock(process_accept_mutex)))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
- "ap_unlock failed. Attempting to shutdown "
+ "apr_unlock failed. Attempting to shutdown "
"process gracefully.");
workers_may_exit = 1;
}
pthread_mutex_unlock(&idle_thread_count_mutex);
break;
}
- ap_clear_pool(ptrans);
+ apr_clear_pool(ptrans);
}
pthread_mutex_lock(&thread_pool_parent_mutex);
- ap_destroy_pool(tpool);
+ apr_destroy_pool(tpool);
pthread_mutex_unlock(&thread_pool_parent_mutex);
pthread_mutex_lock(&worker_thread_count_mutex);
worker_thread_count--;
return 0;
}
-static int create_child_socket(int child_num, ap_pool_t *p)
-{
- struct sockaddr_un unix_addr;
- mode_t omask;
- int rc;
- int sd;
- perchild_server_conf *sconf = (perchild_server_conf *)
- ap_get_module_config(ap_server_conf->module_config, &mpm_perchild_module);
- int len = strlen(sconf->sockname) + strlen(child_info_table[child_num].name) + 3;
- char *socket_name = ap_palloc(p, len);
-
- ap_snprintf(socket_name, len, "%s.%s", sconf->sockname, child_info_table[child_num].name);
- if (unlink(socket_name) < 0 &&
- errno != ENOENT) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
- "Couldn't unlink unix domain socket %s",
- socket_name);
- /* Just a warning; don't bail out */
- }
-
- if ((sd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
- "Couldn't create unix domain socket");
- return -1;
- }
-
- memset(&unix_addr, 0, sizeof(unix_addr));
- unix_addr.sun_family = AF_UNIX;
- strcpy(unix_addr.sun_path, socket_name);
-
- omask = umask(0077); /* so that only Apache can use socket */
- rc = bind(sd, (struct sockaddr *)&unix_addr, sizeof(unix_addr));
- umask(omask); /* can't fail, so can't clobber errno */
- if (rc < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
- "Couldn't bind unix domain socket %s",
- socket_name);
- return -1;
- }
-
- if (listen(sd, DEFAULT_PERCHILD_LISTENBACKLOG) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
- "Couldn't listen on unix domain socket");
- return -1;
- }
-
- if (!geteuid()) {
- if (chown(socket_name, unixd_config.user_id, -1) < 0) {
- ap_log_error(APLOG_MARK, APLOG_ERR, errno, ap_server_conf,
- "Couldn't change owner of unix domain socket %s",
- socket_name);
- return -1;
- }
- }
- return sd;
-}
-
static void child_main(int child_num_arg)
{
sigset_t sig_mask;
int signal_received;
int i;
ap_listen_rec *lr;
- ap_status_t rv;
- int sd;
+ apr_status_t rv;
my_pid = getpid();
child_num = child_num_arg;
- ap_create_pool(&pchild, pconf);
+ apr_create_pool(&pchild, pconf);
/*stuff to do before we switch id's, so we have permissions.*/
- rv = SAFE_ACCEPT(ap_child_init_lock(&process_accept_mutex, lock_fname,
+ rv = SAFE_ACCEPT(apr_child_init_lock(&process_accept_mutex, lock_fname,
pchild));
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, ap_server_conf,
/* Set up the pollfd array, num_listenfds + 1 for the pipe and 1 for
* the child socket.
*/
- listenfds = ap_pcalloc(pchild, sizeof(*listenfds) * (num_listenfds + 2));
+ listenfds = apr_pcalloc(pchild, sizeof(*listenfds) * (num_listenfds + 2));
#if APR_FILES_AS_SOCKETS
- ap_socket_from_file(&listenfds[0], pipe_of_death_in);
+ apr_socket_from_file(&listenfds[0], pipe_of_death_in);
#endif
+
/* The child socket */
- ap_put_os_sock(&listenfds[1], &sd, pchild);
+ apr_put_os_sock(&listenfds[1], &child_info_table[child_num].sd, pchild);
+
num_listenfds++;
for (lr = ap_listeners, i = 2; i <= num_listenfds; lr = lr->next, ++i)
listenfds[i]=lr->sd;
for (i = 0; i < max_threads; i++) {
worker_thread_free_ids[i] = i;
}
- ap_create_pool(&thread_pool_parent, pchild);
+ apr_create_pool(&thread_pool_parent, pchild);
pthread_mutex_init(&thread_pool_parent_mutex, NULL);
pthread_mutex_init(&idle_thread_count_mutex, NULL);
pthread_mutex_init(&worker_thread_count_mutex, NULL);
RAISE_SIGSTOP(MAKE_CHILD);
/* XXX - For an unthreaded server, a signal handler will be necessary
- ap_signal(SIGTERM, just_die);
+ apr_signal(SIGTERM, just_die);
*/
child_main(slot);
static void server_main_loop(int remaining_children_to_start)
{
int child_slot;
- ap_wait_t status;
- ap_proc_t pid;
+ apr_wait_t status;
+ apr_proc_t pid;
int i;
while (!restart_pending && !shutdown_pending) {
}
#if APR_HAS_OTHER_CHILD
}
- else if (ap_reap_other_child(&pid, status) == 0) {
+ else if (apr_reap_other_child(&pid, status) == 0) {
/* handled */
#endif
}
}
}
-int ap_mpm_run(ap_pool_t *_pconf, ap_pool_t *plog, server_rec *s)
+int ap_mpm_run(apr_pool_t *_pconf, apr_pool_t *plog, server_rec *s)
{
int remaining_children_to_start;
int i;
- ap_status_t rv;
- ap_ssize_t one = 1;
+ apr_status_t rv;
+ apr_ssize_t one = 1;
pconf = _pconf;
ap_server_conf = s;
- if ((rv = ap_create_pipe(&pipe_of_death_in, &pipe_of_death_out, pconf))
+ if ((rv = apr_create_pipe(&pipe_of_death_in, &pipe_of_death_out, pconf))
!= APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv,
(const server_rec*) ap_server_conf,
- "ap_create_pipe (pipe_of_death)");
+ "apr_create_pipe (pipe_of_death)");
exit(1);
}
- if ((rv = ap_set_pipe_timeout(pipe_of_death_in, 0)) != APR_SUCCESS) {
+ if ((rv = apr_set_pipe_timeout(pipe_of_death_in, 0)) != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_ERR, rv,
(const server_rec*) ap_server_conf,
- "ap_set_pipe_timeout (pipe_of_death)");
+ "apr_set_pipe_timeout (pipe_of_death)");
exit(1);
}
ap_server_conf = s;
}
ap_log_pid(pconf, ap_pid_fname);
- /* Create all of the sockets for the child processes. */
- for (i = 0; i <= socket_num; i++) {
- int sd;
- int j;
-
- sd = create_child_socket(i, pchild);
-
- for(j = i; ;) {
- if (child_info_table[j].num == i) {
- child_info_table[j].sd = sd;
- j++;
- }
- else {
- break;
- }
- }
- if (j >= num_daemons) {
- break;
- }
- }
-
/* Initialize cross-process accept lock */
- lock_fname = ap_psprintf(_pconf, "%s.%u",
+ lock_fname = apr_psprintf(_pconf, "%s.%u",
ap_server_root_relative(_pconf, lock_fname),
my_pid);
- rv = SAFE_ACCEPT(ap_create_lock(&process_accept_mutex, APR_MUTEX,
+ rv = SAFE_ACCEPT(apr_create_lock(&process_accept_mutex, APR_MUTEX,
APR_CROSS_PROCESS, lock_fname, _pconf));
if (rv != APR_SUCCESS) {
ap_log_error(APLOG_MARK, APLOG_EMERG, rv, s,
}
/* we've been told to restart */
- ap_signal(SIGHUP, SIG_IGN);
+ apr_signal(SIGHUP, SIG_IGN);
if (one_process) {
/* not worth thinking about */
}
/* give the children the signal to die */
for (i = 0; i < num_daemons;) {
- if ((rv = ap_write(pipe_of_death_out, &char_of_death, &one)) != APR_SUCCESS) {
- if (ap_canonical_error(rv) == APR_EINTR) continue;
+ if ((rv = apr_write(pipe_of_death_out, &char_of_death, &one)) != APR_SUCCESS) {
+ if (apr_canonical_error(rv) == APR_EINTR) continue;
ap_log_error(APLOG_MARK, APLOG_WARNING, rv, ap_server_conf,
"write pipe_of_death");
}
return 0;
}
-static void perchild_pre_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp)
+static void perchild_pre_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp)
{
static int restart_num = 0;
int no_detach = 0;
is_graceful = 0;
if (!one_process && !no_detach) {
- ap_detach();
+ apr_detach();
}
my_pid = getpid();
max_requests_per_child = DEFAULT_MAX_REQUESTS_PER_CHILD;
ap_perchild_set_maintain_connection_status(1);
curr_child_num = 0;
- socket_num = 0;
- ap_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
+ apr_cpystrn(ap_coredump_dir, ap_server_root, sizeof(ap_coredump_dir));
for (i = 0; i < HARD_SERVER_LIMIT; i++) {
child_info_table[i].uid = -1;
child_info_table[i].gid = -1;
- child_info_table[i].name = NULL;
- child_info_table[i].num = -1;
+ child_info_table[i].sd = -1;
+ }
+ for (i = 0; i < HARD_THREAD_LIMIT; i++) {
+ thread_socket_table[i] = -1;
}
}
-static void perchild_post_config(ap_pool_t *p, ap_pool_t *plog, ap_pool_t *ptemp, server_rec *s)
+static int pass_request(request_rec *r)
+{
+ apr_socket_t *thesock = ap_iol_get_socket(r->connection->client->iol);
+ struct msghdr msg;
+ struct cmsghdr *cmsg;
+ int sfd;
+ struct iovec iov;
+ char *foo = r->connection->client->inbase;
+ int len = r->connection->client->inptr - r->connection->client->inbase;
+ perchild_server_conf *sconf = (perchild_server_conf *)
+ ap_get_module_config(r->server->module_config,
+ &mpm_perchild_module);
+
+ apr_get_os_sock(&sfd, thesock);
+
+ iov.iov_base = (char *)sconf->fullsockname;
+ iov.iov_len = strlen(sconf->fullsockname) + 1;
+
+ msg.msg_name = NULL;
+ msg.msg_namelen = 0;
+ msg.msg_iov = &iov;
+ msg.msg_iovlen = 1;
+
+ cmsg = apr_palloc(r->pool, sizeof(*cmsg) + sizeof(sfd));
+ cmsg->cmsg_len = sizeof(*cmsg) + sizeof(int);
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+
+ memcpy(CMSG_DATA(cmsg), &sfd, sizeof(sfd));
+
+ msg.msg_control = cmsg;
+ msg.msg_controllen = cmsg->cmsg_len;
+ msg.msg_flags=0;
+
+ if (sendmsg(sconf->sd2, &msg, 0) == -1) {
+ apr_destroy_pool(r->pool);
+ return -1;
+ }
+
+ write(sconf->sd2, foo, len);
+
+ apr_destroy_pool(r->pool);
+ return 1;
+}
+
+static char *make_perchild_socket(const char *fullsockname, int sd[2])
+{
+ socketpair(PF_UNIX, SOCK_STREAM, 0, sd);
+ return NULL;
+}
+
+
+static void perchild_post_config(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s)
{
int i;
+ server_rec *sr;
+ perchild_server_conf *sconf;
+ int def_sd[2];
+
+ def_sd[0] = -1;
+ def_sd[1] = -1;
+
+ for (sr = s; sr; sr = sr->next) {
+ sconf = (perchild_server_conf *)ap_get_module_config(sr->module_config,
+ &mpm_perchild_module);
+
+ if (sconf->sd == -1) {
+ sconf->fullsockname = apr_pstrcat(sr->process->pool,
+ sconf->sockname, ".DEFAULT", NULL);
+ if (def_sd[0] == -1) {
+ if (!make_perchild_socket(sconf->fullsockname, def_sd)) {
+ /* log error */
+ }
+ }
+ sconf->sd = def_sd[0];
+ sconf->sd2 = def_sd[1];
+ }
+ }
for (i = 0; i < num_daemons; i++) {
- if (child_info_table[i].name == NULL) {
- child_info_table[i].name = ap_pstrdup(p, "DEFAULT");
- child_info_table[i].num = socket_num;
+ if (child_info_table[i].uid == -1) {
+ child_info_table[i].sd = def_sd[0];
}
}
}
static int perchild_post_read(request_rec *r)
{
- const char *hostname = ap_table_get(r->headers_in, "Host");
- char *process_num;
- int num;
+ int thread_num = r->connection->id % HARD_THREAD_LIMIT;
+ perchild_server_conf *sconf = (perchild_server_conf *)
+ ap_get_module_config(r->server->module_config,
+ &mpm_perchild_module);
+
+ if (thread_socket_table[thread_num] != -1) {
+ apr_socket_t *csd = NULL;
+ ap_iol *iol;
-fprintf(stderr, "In perchild_post_read\n");
- process_num = ap_hash_get(socket_info_table, hostname, 0);
- if (process_num) {
- num = atoi(process_num);
+ apr_put_os_sock(&csd, &thread_socket_table[thread_num],
+ r->connection->client->pool);
+ ap_sock_disable_nagle(thread_socket_table[thread_num]);
+ iol = ap_iol_attach_socket(r->connection->client->pool, csd);
+ ap_bpush_iol(r->connection->client, iol);
+ return OK;
}
else {
- num = -1;
- }
-
- if (num != child_num) {
- /* package the request and send it to another child */
-fprintf(stderr, "leaving DECLINED\n");
- return DECLINED;
+ if (sconf->sd != child_info_table[child_num].sd) {
+ if (pass_request(r) == -1) {
+ ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_NOERRNO, 0,
+ ap_server_conf, "Could not pass request to proper "
+ "child, request will not be honored.");
+ }
+ longjmp(jmpbuffer, 1);
+ }
+ return OK;
}
return OK;
}
static const char *set_coredumpdir (cmd_parms *cmd, void *dummy, const char *arg)
{
- ap_finfo_t finfo;
+ apr_finfo_t finfo;
const char *fname;
const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
if (err != NULL) {
}
fname = ap_server_root_relative(cmd->pool, arg);
- if ((ap_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) ||
+ if ((apr_stat(&finfo, fname, cmd->pool) != APR_SUCCESS) ||
(finfo.filetype != APR_DIR)) {
- return ap_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
+ return apr_pstrcat(cmd->pool, "CoreDumpDirectory ", fname,
" does not exist or is not a directory", NULL);
}
- ap_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
+ apr_cpystrn(ap_coredump_dir, fname, sizeof(ap_coredump_dir));
return NULL;
}
ug->uid = atoi(u);
ug->gid = atoi(g);
- ug->name = ap_pstrcat(cmd->pool, u, ":", g, NULL);
- ug->num = socket_num;
}
- socket_num++;
return NULL;
}
-static const char *set_socket_name(cmd_parms *cmd, void *dummy, const char *arg)
-{
- server_rec *s = cmd->server;
- perchild_server_conf *conf = (perchild_server_conf *)
- ap_get_module_config(s->module_config, &mpm_perchild_module);
-
- conf->sockname = ap_server_root_relative(cmd->pool, arg);
- return NULL;
-}
-
-static ap_status_t cleanup_hash(void *dptr)
-{
- socket_info_table = NULL;
- return APR_SUCCESS;
-}
-
static const char *assign_childuid(cmd_parms *cmd, void *dummy, const char *uid,
const char *gid)
{
- char *socketname = ap_pstrcat(cmd->pool, uid, ":", gid, NULL);
- if (socket_info_table == NULL) {
- socket_info_table = ap_make_hash(cmd->pool);
- ap_register_cleanup(cmd->pool, socket_info_table, cleanup_hash, NULL);
+ int i;
+ int u = atoi(uid);
+ int g = atoi(gid);
+ const char *errstr;
+ int socks[2];
+ perchild_server_conf *sconf = (perchild_server_conf *)
+ ap_get_module_config(cmd->server->module_config,
+ &mpm_perchild_module);
+
+ sconf->fullsockname = apr_pstrcat(cmd->pool, sconf->sockname, ".", uid, ":", gid, NULL);
+
+ if ((errstr = make_perchild_socket(sconf->fullsockname, socks))) {
+ return errstr;
}
- ap_hash_set(socket_info_table, cmd->server->server_hostname, 0, socketname);
+
+ sconf->sd = socks[0];
+ sconf->sd2 = socks[1];
+
+ for (i = 0; i < num_daemons; i++) {
+ if (u == child_info_table[i].uid && g == child_info_table[i].gid) {
+ child_info_table[i].sd = sconf->sd;
+ }
+ }
+
return NULL;
}
"Specify a User and Group for a specific child process."),
AP_INIT_TAKE2("AssignUserID", assign_childuid, NULL, RSRC_CONF,
"Tie a virtual host to a specific child process."),
-AP_INIT_TAKE1("ChildSockName", set_socket_name, NULL, RSRC_CONF,
- "the base name of the socket to use for communication between "
- "child processes. The actual socket will be "
- "basename.childnum"),
{ NULL }
};
-static void *perchild_create_config(ap_pool_t *p, server_rec *s)
+static void *perchild_create_config(apr_pool_t *p, server_rec *s)
{
perchild_server_conf *c =
- (perchild_server_conf *) ap_pcalloc(p, sizeof(perchild_server_conf));
+ (perchild_server_conf *) apr_pcalloc(p, sizeof(perchild_server_conf));
- c->sockname = ap_server_root_relative(p, DEFAULT_PERCHILD_SOCKET);
+ c->sd = -1;
return c;
}
NULL, /* merge per-directory config structures */
perchild_create_config, /* create per-server config structure */
NULL, /* merge per-server config structures */
- perchild_cmds, /* command ap_table_t */
+ perchild_cmds, /* command apr_table_t */
NULL, /* handlers */
perchild_hooks /* register_hooks */
};