0
#ifdef INSIDE_MOD_RAILS
0
+#include "DispatcherBucket.h"
0
file_exists(apr_pool_t *pool, const char *filename) {
0
@@ -35,10 +38,85 @@ verify_rails_dir(apr_pool_t *pool, const char *dir) {
0
return file_exists(pool, apr_pstrcat(pool, dir, "/../config/environment.rb", NULL));
0
mod_rails_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *base_server) {
0
- ap_add_version_component(p, "mod_rails/" MOD_RAILS_VERSION);
0
+ socketpair(AF_UNIX, SOCK_STREAM, 0, fds);
0
+ apr_snprintf(fd_string, sizeof(fd_string), "%d", fds[1]);
0
+ execlp("ruby", "ruby", "/home/hongli/Projects/mod_rails/lib/mod_rails/spawn_manager.rb", fd_string, NULL);
0
+ } else if (pid == -1) {
0
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "mod_rails: Unable to fork a process: %s", strerror(errno));
0
+ } else if (pid == -1) {
0
+ ap_log_error(APLOG_MARK, APLOG_STARTUP, 0, NULL, "mod_rails: Unable to fork a process: %s", strerror(errno));
0
+ waitpid(pid, NULL, 0);
0
+ ap_add_version_component(p, "mod_rails/" MOD_RAILS_VERSION);
0
+spawn_instance(int pipes[2]) {
0
+ execlp("ruby", "ruby", "/home/hongli/Projects/mod_rails/handler_demo.rb", NULL);
0
+ waitpid(pid, NULL, 0);
0
+debug(const char *format, ...) {
0
+ int size = apr_vsnprintf(message, sizeof(message), format, ap);
0
+ FILE *f = fopen("/dev/pts/2", "w");
0
+ fwrite(message, 1, size, f);
0
@@ -69,10 +147,29 @@ mod_rails_handle_request(request_rec *r) {
0
- apr_snprintf(message, sizeof(message), "mod_rails: file=%s, uri=%s, root=%s", r->filename, r->uri, rails_dir);
0
- log_debug(APLOG_MARK, r, message);
0
+ apr_bucket_brigade *bb;
0
+ bb = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
0
+ write(p[1], &x, sizeof(x));
0
+ debug("hooks: %d, %d\n", p[0], p[1]);
0
+ b = dispatcher_bucket_create(r->pool, p[0], r->server->timeout, r->connection->bucket_alloc);
0
+ APR_BRIGADE_INSERT_TAIL(bb, b);
0
+ b = apr_bucket_eos_create(r->connection->bucket_alloc);
0
+ APR_BRIGADE_INSERT_TAIL(bb, b);
0
+ ap_scan_script_header_err_brigade(r, bb, NULL);
0
+ ap_pass_brigade(r->output_filters, bb);
Comments
No one has commented yet.