public
Description: Phusion Passenger (mod_rails)
Homepage: http://www.modrails.com/
Clone URL: git://github.com/FooBarWidget/passenger.git
Search Repo:
Click here to lend your support to: passenger and make a donation at www.pledgie.com !
Make sure that Passenger is properly initialized even after a graceful 
restart. Fixes issues #37 (and possibly #36 as well).
Hongli Lai (Phusion) (author)
Thu Apr 24 02:40:33 -0700 2008
commit  179aeaaaecc4801a8f7d61ca9de27a50ada3f936
tree    b43f756acb2f3d11405194d6f2d054c21ef99183
parent  f3180b430b34cb0a70278c2dfc3c951ef888d32d
...
548
549
550
 
 
551
552
553
554
555
 
 
556
557
558
 
 
 
 
 
 
 
 
 
 
559
560
561
562
563
564
565
566
567
568
 
569
570
571
...
616
617
618
 
 
619
620
621
...
548
549
550
551
552
553
554
555
556
 
557
558
559
 
 
560
561
562
563
564
565
566
567
568
569
570
 
 
 
 
 
 
 
 
 
571
572
573
574
...
619
620
621
622
623
624
625
626
0
@@ -548,24 +548,27 @@
0
 static int
0
 init_module(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
0
   /*
0
+ * The Apache initialization process has the following properties:
0
+ *
0
    * 1. Apache on Unix calls the post_config hook twice, once before detach() and once
0
    * after. On Windows it never calls detach().
0
    * 2. When Apache is compiled to use DSO modules, the modules are unloaded between the
0
    * two post_config hook calls.
0
- * 3. On Unix, if the -X commandline option is given, detach() will not be called.
0
+ * 3. On Unix, if the -X commandline option is given (the 'DEBUG' config is set),
0
+ * detach() will not be called.
0
    *
0
- * Because of these 3 issues (and especially #2), we only want to intialize the second
0
- * time the post_config hook is called.
0
+ * The Passenger initialization process is pretty expensive because a spawn server has
0
+ * to be started, so we'll want to avoid initializing twice because of property #2.
0
+ *
0
+ * The most straightforward solution is to initialize Passenger the second time
0
+ * post_config is called. But unfortunately, that doesn't work if the Passenger
0
+ * module is loaded after a graceful restart. There also doesn't seem to be any
0
+ * good hooks that we can use to avoid double initialization.
0
+ *
0
+ * So as a hack, we check whether Apache has already been daemonized, by checking
0
+ * whether ppid() returns 1.
0
    */
0
- void *firstInitCall = NULL;
0
- apr_pool_t *processPool = s->process->pool;
0
-
0
- apr_pool_userdata_get(&firstInitCall, "mod_passenger", processPool);
0
- if (firstInitCall == NULL) {
0
- apr_pool_userdata_set((const void *) 1, "mod_passenger",
0
- apr_pool_cleanup_null, processPool);
0
- return OK;
0
- } else {
0
+ if (getppid() == 1 || ap_exists_config_define("DEBUG")) {
0
     try {
0
       hooks = new Hooks(pconf, plog, ptemp, s);
0
       apr_pool_cleanup_register(pconf, NULL,
0
@@ -616,6 +619,8 @@
0
       hooks = NULL;
0
       return DECLINED;
0
     }
0
+ } else {
0
+ return OK;
0
   }
0
 }
0
 

Comments

    No one has commented yet.