rockdog-passenger 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (805) hide show
  1. data/DEVELOPERS.TXT +89 -0
  2. data/INSTALL +4 -0
  3. data/LICENSE +355 -0
  4. data/README +38 -0
  5. data/Rakefile +627 -0
  6. data/benchmark/ApplicationPool.cpp +52 -0
  7. data/benchmark/DummyRequestHandler.cpp +101 -0
  8. data/benchmark/accept_vs_socketpair_vs_named_pipes.rb +126 -0
  9. data/benchmark/dispatcher.rb +42 -0
  10. data/benchmark/overhead_of_password_checking.rb +81 -0
  11. data/benchmark/socket_connections_vs_persistent_pipe.rb +99 -0
  12. data/benchmark/unix_sockets_vs_pipes.rb +83 -0
  13. data/bin/passenger-config +40 -0
  14. data/bin/passenger-install-apache2-module +352 -0
  15. data/bin/passenger-make-enterprisey +78 -0
  16. data/bin/passenger-memory-stats +291 -0
  17. data/bin/passenger-spawn-server +53 -0
  18. data/bin/passenger-status +71 -0
  19. data/bin/passenger-stress-test +339 -0
  20. data/debian/compat +1 -0
  21. data/debian/control +21 -0
  22. data/debian/postinst +24 -0
  23. data/debian/prerm +2 -0
  24. data/doc/ApplicationPool algorithm.txt +398 -0
  25. data/doc/Architectural overview.txt +339 -0
  26. data/doc/Doxyfile +241 -0
  27. data/doc/Security of user switching support.txt +197 -0
  28. data/doc/Users guide.txt +2237 -0
  29. data/doc/definitions.h +5 -0
  30. data/doc/images/by_sa.png +0 -0
  31. data/doc/images/icons/README +5 -0
  32. data/doc/images/icons/callouts/1.png +0 -0
  33. data/doc/images/icons/callouts/10.png +0 -0
  34. data/doc/images/icons/callouts/11.png +0 -0
  35. data/doc/images/icons/callouts/12.png +0 -0
  36. data/doc/images/icons/callouts/13.png +0 -0
  37. data/doc/images/icons/callouts/14.png +0 -0
  38. data/doc/images/icons/callouts/15.png +0 -0
  39. data/doc/images/icons/callouts/2.png +0 -0
  40. data/doc/images/icons/callouts/3.png +0 -0
  41. data/doc/images/icons/callouts/4.png +0 -0
  42. data/doc/images/icons/callouts/5.png +0 -0
  43. data/doc/images/icons/callouts/6.png +0 -0
  44. data/doc/images/icons/callouts/7.png +0 -0
  45. data/doc/images/icons/callouts/8.png +0 -0
  46. data/doc/images/icons/callouts/9.png +0 -0
  47. data/doc/images/icons/caution.png +0 -0
  48. data/doc/images/icons/example.png +0 -0
  49. data/doc/images/icons/home.png +0 -0
  50. data/doc/images/icons/important.png +0 -0
  51. data/doc/images/icons/next.png +0 -0
  52. data/doc/images/icons/note.png +0 -0
  53. data/doc/images/icons/prev.png +0 -0
  54. data/doc/images/icons/tip.png +0 -0
  55. data/doc/images/icons/up.png +0 -0
  56. data/doc/images/icons/warning.png +0 -0
  57. data/doc/images/passenger_architecture.png +0 -0
  58. data/doc/images/passenger_architecture.svg +401 -0
  59. data/doc/images/phusion_banner.png +0 -0
  60. data/doc/images/spawn_server_architecture.png +0 -0
  61. data/doc/images/spawn_server_architecture.svg +655 -0
  62. data/doc/images/typical_isolated_web_application.png +0 -0
  63. data/doc/images/typical_isolated_web_application.svg +213 -0
  64. data/doc/template/horo.rb +613 -0
  65. data/ext/apache2/Application.h +526 -0
  66. data/ext/apache2/ApplicationPool.h +199 -0
  67. data/ext/apache2/ApplicationPoolServer.h +777 -0
  68. data/ext/apache2/ApplicationPoolServerExecutable.cpp +627 -0
  69. data/ext/apache2/Bucket.cpp +150 -0
  70. data/ext/apache2/Bucket.h +45 -0
  71. data/ext/apache2/Configuration.cpp +720 -0
  72. data/ext/apache2/Configuration.h +327 -0
  73. data/ext/apache2/DummySpawnManager.h +103 -0
  74. data/ext/apache2/Exceptions.h +240 -0
  75. data/ext/apache2/Hooks.cpp +1195 -0
  76. data/ext/apache2/Hooks.h +40 -0
  77. data/ext/apache2/LICENSE-CNRI.TXT +79 -0
  78. data/ext/apache2/Logging.cpp +60 -0
  79. data/ext/apache2/Logging.h +117 -0
  80. data/ext/apache2/MessageChannel.h +604 -0
  81. data/ext/apache2/SpawnManager.h +546 -0
  82. data/ext/apache2/StandardApplicationPool.h +817 -0
  83. data/ext/apache2/Utils.cpp +322 -0
  84. data/ext/apache2/Utils.h +365 -0
  85. data/ext/apache2/mod_passenger.c +33 -0
  86. data/ext/boost/LICENSE.TXT +23 -0
  87. data/ext/boost/VERSION.TXT +1 -0
  88. data/ext/boost/algorithm/string/case_conv.hpp +176 -0
  89. data/ext/boost/algorithm/string/compare.hpp +199 -0
  90. data/ext/boost/algorithm/string/concept.hpp +83 -0
  91. data/ext/boost/algorithm/string/config.hpp +28 -0
  92. data/ext/boost/algorithm/string/constants.hpp +36 -0
  93. data/ext/boost/algorithm/string/detail/case_conv.hpp +112 -0
  94. data/ext/boost/algorithm/string/detail/find_format.hpp +193 -0
  95. data/ext/boost/algorithm/string/detail/find_format_all.hpp +263 -0
  96. data/ext/boost/algorithm/string/detail/find_format_store.hpp +71 -0
  97. data/ext/boost/algorithm/string/detail/finder.hpp +646 -0
  98. data/ext/boost/algorithm/string/detail/formatter.hpp +94 -0
  99. data/ext/boost/algorithm/string/detail/replace_storage.hpp +159 -0
  100. data/ext/boost/algorithm/string/detail/sequence.hpp +200 -0
  101. data/ext/boost/algorithm/string/detail/util.hpp +106 -0
  102. data/ext/boost/algorithm/string/erase.hpp +844 -0
  103. data/ext/boost/algorithm/string/find_format.hpp +269 -0
  104. data/ext/boost/algorithm/string/finder.hpp +270 -0
  105. data/ext/boost/algorithm/string/formatter.hpp +103 -0
  106. data/ext/boost/algorithm/string/replace.hpp +928 -0
  107. data/ext/boost/algorithm/string/sequence_traits.hpp +193 -0
  108. data/ext/boost/algorithm/string/yes_no_type.hpp +33 -0
  109. data/ext/boost/assert.hpp +50 -0
  110. data/ext/boost/bind.hpp +1689 -0
  111. data/ext/boost/bind/arg.hpp +62 -0
  112. data/ext/boost/bind/bind_cc.hpp +117 -0
  113. data/ext/boost/bind/bind_mf_cc.hpp +227 -0
  114. data/ext/boost/bind/bind_template.hpp +345 -0
  115. data/ext/boost/bind/mem_fn_cc.hpp +103 -0
  116. data/ext/boost/bind/mem_fn_template.hpp +1020 -0
  117. data/ext/boost/bind/placeholders.hpp +68 -0
  118. data/ext/boost/bind/storage.hpp +475 -0
  119. data/ext/boost/call_traits.hpp +24 -0
  120. data/ext/boost/checked_delete.hpp +69 -0
  121. data/ext/boost/concept/assert.hpp +46 -0
  122. data/ext/boost/concept/detail/concept_def.hpp +51 -0
  123. data/ext/boost/concept/detail/concept_undef.hpp +5 -0
  124. data/ext/boost/concept/detail/general.hpp +66 -0
  125. data/ext/boost/concept/detail/has_constraints.hpp +48 -0
  126. data/ext/boost/concept/usage.hpp +43 -0
  127. data/ext/boost/concept_check.hpp +988 -0
  128. data/ext/boost/config.hpp +70 -0
  129. data/ext/boost/config/abi/borland_prefix.hpp +27 -0
  130. data/ext/boost/config/abi/borland_suffix.hpp +12 -0
  131. data/ext/boost/config/abi/msvc_prefix.hpp +8 -0
  132. data/ext/boost/config/abi/msvc_suffix.hpp +8 -0
  133. data/ext/boost/config/abi_prefix.hpp +25 -0
  134. data/ext/boost/config/abi_suffix.hpp +26 -0
  135. data/ext/boost/config/auto_link.hpp +368 -0
  136. data/ext/boost/config/compiler/borland.hpp +209 -0
  137. data/ext/boost/config/compiler/comeau.hpp +59 -0
  138. data/ext/boost/config/compiler/common_edg.hpp +62 -0
  139. data/ext/boost/config/compiler/compaq_cxx.hpp +19 -0
  140. data/ext/boost/config/compiler/digitalmars.hpp +67 -0
  141. data/ext/boost/config/compiler/gcc.hpp +149 -0
  142. data/ext/boost/config/compiler/gcc_xml.hpp +30 -0
  143. data/ext/boost/config/compiler/greenhills.hpp +28 -0
  144. data/ext/boost/config/compiler/hp_acc.hpp +95 -0
  145. data/ext/boost/config/compiler/intel.hpp +162 -0
  146. data/ext/boost/config/compiler/kai.hpp +35 -0
  147. data/ext/boost/config/compiler/metrowerks.hpp +111 -0
  148. data/ext/boost/config/compiler/mpw.hpp +51 -0
  149. data/ext/boost/config/compiler/pgi.hpp +25 -0
  150. data/ext/boost/config/compiler/sgi_mipspro.hpp +28 -0
  151. data/ext/boost/config/compiler/sunpro_cc.hpp +98 -0
  152. data/ext/boost/config/compiler/vacpp.hpp +60 -0
  153. data/ext/boost/config/compiler/visualc.hpp +191 -0
  154. data/ext/boost/config/no_tr1/complex.hpp +28 -0
  155. data/ext/boost/config/no_tr1/functional.hpp +28 -0
  156. data/ext/boost/config/no_tr1/memory.hpp +28 -0
  157. data/ext/boost/config/no_tr1/utility.hpp +28 -0
  158. data/ext/boost/config/platform/aix.hpp +33 -0
  159. data/ext/boost/config/platform/amigaos.hpp +15 -0
  160. data/ext/boost/config/platform/beos.hpp +26 -0
  161. data/ext/boost/config/platform/bsd.hpp +73 -0
  162. data/ext/boost/config/platform/cygwin.hpp +51 -0
  163. data/ext/boost/config/platform/hpux.hpp +84 -0
  164. data/ext/boost/config/platform/irix.hpp +31 -0
  165. data/ext/boost/config/platform/linux.hpp +98 -0
  166. data/ext/boost/config/platform/macos.hpp +78 -0
  167. data/ext/boost/config/platform/qnxnto.hpp +31 -0
  168. data/ext/boost/config/platform/solaris.hpp +21 -0
  169. data/ext/boost/config/platform/win32.hpp +58 -0
  170. data/ext/boost/config/posix_features.hpp +95 -0
  171. data/ext/boost/config/requires_threads.hpp +92 -0
  172. data/ext/boost/config/select_compiler_config.hpp +115 -0
  173. data/ext/boost/config/select_platform_config.hpp +90 -0
  174. data/ext/boost/config/select_stdlib_config.hpp +68 -0
  175. data/ext/boost/config/stdlib/dinkumware.hpp +106 -0
  176. data/ext/boost/config/stdlib/libcomo.hpp +46 -0
  177. data/ext/boost/config/stdlib/libstdcpp3.hpp +73 -0
  178. data/ext/boost/config/stdlib/modena.hpp +30 -0
  179. data/ext/boost/config/stdlib/msl.hpp +59 -0
  180. data/ext/boost/config/stdlib/roguewave.hpp +153 -0
  181. data/ext/boost/config/stdlib/sgi.hpp +111 -0
  182. data/ext/boost/config/stdlib/stlport.hpp +201 -0
  183. data/ext/boost/config/stdlib/vacpp.hpp +18 -0
  184. data/ext/boost/config/suffix.hpp +566 -0
  185. data/ext/boost/config/user.hpp +124 -0
  186. data/ext/boost/cstdint.hpp +448 -0
  187. data/ext/boost/date_time/adjust_functors.hpp +178 -0
  188. data/ext/boost/date_time/c_time.hpp +91 -0
  189. data/ext/boost/date_time/compiler_config.hpp +149 -0
  190. data/ext/boost/date_time/constrained_value.hpp +98 -0
  191. data/ext/boost/date_time/date.hpp +197 -0
  192. data/ext/boost/date_time/date_clock_device.hpp +77 -0
  193. data/ext/boost/date_time/date_defs.hpp +26 -0
  194. data/ext/boost/date_time/date_duration.hpp +147 -0
  195. data/ext/boost/date_time/date_duration_types.hpp +269 -0
  196. data/ext/boost/date_time/date_facet.hpp +775 -0
  197. data/ext/boost/date_time/date_format_simple.hpp +159 -0
  198. data/ext/boost/date_time/date_formatting.hpp +127 -0
  199. data/ext/boost/date_time/date_formatting_limited.hpp +121 -0
  200. data/ext/boost/date_time/date_formatting_locales.hpp +233 -0
  201. data/ext/boost/date_time/date_generator_formatter.hpp +263 -0
  202. data/ext/boost/date_time/date_generator_parser.hpp +329 -0
  203. data/ext/boost/date_time/date_generators.hpp +509 -0
  204. data/ext/boost/date_time/date_iterator.hpp +101 -0
  205. data/ext/boost/date_time/date_names_put.hpp +320 -0
  206. data/ext/boost/date_time/date_parsing.hpp +299 -0
  207. data/ext/boost/date_time/dst_rules.hpp +391 -0
  208. data/ext/boost/date_time/filetime_functions.hpp +78 -0
  209. data/ext/boost/date_time/format_date_parser.hpp +731 -0
  210. data/ext/boost/date_time/gregorian/conversion.hpp +73 -0
  211. data/ext/boost/date_time/gregorian/formatters.hpp +162 -0
  212. data/ext/boost/date_time/gregorian/formatters_limited.hpp +81 -0
  213. data/ext/boost/date_time/gregorian/greg_calendar.hpp +47 -0
  214. data/ext/boost/date_time/gregorian/greg_date.hpp +135 -0
  215. data/ext/boost/date_time/gregorian/greg_day.hpp +57 -0
  216. data/ext/boost/date_time/gregorian/greg_day_of_year.hpp +38 -0
  217. data/ext/boost/date_time/gregorian/greg_duration.hpp +38 -0
  218. data/ext/boost/date_time/gregorian/greg_duration_types.hpp +34 -0
  219. data/ext/boost/date_time/gregorian/greg_month.hpp +105 -0
  220. data/ext/boost/date_time/gregorian/greg_weekday.hpp +66 -0
  221. data/ext/boost/date_time/gregorian/greg_year.hpp +53 -0
  222. data/ext/boost/date_time/gregorian/greg_ymd.hpp +33 -0
  223. data/ext/boost/date_time/gregorian/gregorian.hpp +38 -0
  224. data/ext/boost/date_time/gregorian/gregorian_io.hpp +777 -0
  225. data/ext/boost/date_time/gregorian/gregorian_types.hpp +109 -0
  226. data/ext/boost/date_time/gregorian/parsers.hpp +91 -0
  227. data/ext/boost/date_time/gregorian_calendar.hpp +70 -0
  228. data/ext/boost/date_time/gregorian_calendar.ipp +219 -0
  229. data/ext/boost/date_time/int_adapter.hpp +507 -0
  230. data/ext/boost/date_time/iso_format.hpp +303 -0
  231. data/ext/boost/date_time/locale_config.hpp +31 -0
  232. data/ext/boost/date_time/microsec_time_clock.hpp +205 -0
  233. data/ext/boost/date_time/parse_format_base.hpp +29 -0
  234. data/ext/boost/date_time/period.hpp +377 -0
  235. data/ext/boost/date_time/period_formatter.hpp +196 -0
  236. data/ext/boost/date_time/period_parser.hpp +196 -0
  237. data/ext/boost/date_time/posix_time/conversion.hpp +93 -0
  238. data/ext/boost/date_time/posix_time/date_duration_operators.hpp +114 -0
  239. data/ext/boost/date_time/posix_time/posix_time.hpp +39 -0
  240. data/ext/boost/date_time/posix_time/posix_time_config.hpp +178 -0
  241. data/ext/boost/date_time/posix_time/posix_time_duration.hpp +82 -0
  242. data/ext/boost/date_time/posix_time/posix_time_io.hpp +246 -0
  243. data/ext/boost/date_time/posix_time/posix_time_system.hpp +68 -0
  244. data/ext/boost/date_time/posix_time/posix_time_types.hpp +55 -0
  245. data/ext/boost/date_time/posix_time/ptime.hpp +65 -0
  246. data/ext/boost/date_time/posix_time/time_formatters.hpp +289 -0
  247. data/ext/boost/date_time/posix_time/time_parsers.hpp +44 -0
  248. data/ext/boost/date_time/posix_time/time_period.hpp +29 -0
  249. data/ext/boost/date_time/special_defs.hpp +25 -0
  250. data/ext/boost/date_time/special_values_formatter.hpp +96 -0
  251. data/ext/boost/date_time/special_values_parser.hpp +159 -0
  252. data/ext/boost/date_time/string_convert.hpp +33 -0
  253. data/ext/boost/date_time/string_parse_tree.hpp +278 -0
  254. data/ext/boost/date_time/strings_from_facet.hpp +123 -0
  255. data/ext/boost/date_time/time.hpp +190 -0
  256. data/ext/boost/date_time/time_clock.hpp +83 -0
  257. data/ext/boost/date_time/time_defs.hpp +33 -0
  258. data/ext/boost/date_time/time_duration.hpp +281 -0
  259. data/ext/boost/date_time/time_facet.hpp +1263 -0
  260. data/ext/boost/date_time/time_formatting_streams.hpp +119 -0
  261. data/ext/boost/date_time/time_iterator.hpp +52 -0
  262. data/ext/boost/date_time/time_parsing.hpp +321 -0
  263. data/ext/boost/date_time/time_resolution_traits.hpp +140 -0
  264. data/ext/boost/date_time/time_system_counted.hpp +254 -0
  265. data/ext/boost/date_time/time_system_split.hpp +213 -0
  266. data/ext/boost/date_time/wrapping_int.hpp +163 -0
  267. data/ext/boost/date_time/year_month_day.hpp +45 -0
  268. data/ext/boost/detail/atomic_count.hpp +124 -0
  269. data/ext/boost/detail/atomic_count_gcc.hpp +68 -0
  270. data/ext/boost/detail/atomic_count_gcc_x86.hpp +84 -0
  271. data/ext/boost/detail/atomic_count_pthreads.hpp +96 -0
  272. data/ext/boost/detail/atomic_count_solaris.hpp +59 -0
  273. data/ext/boost/detail/atomic_count_sync.hpp +57 -0
  274. data/ext/boost/detail/atomic_count_win32.hpp +63 -0
  275. data/ext/boost/detail/bad_weak_ptr.hpp +59 -0
  276. data/ext/boost/detail/call_traits.hpp +164 -0
  277. data/ext/boost/detail/endian.hpp +73 -0
  278. data/ext/boost/detail/indirect_traits.hpp +487 -0
  279. data/ext/boost/detail/iterator.hpp +494 -0
  280. data/ext/boost/detail/lcast_precision.hpp +184 -0
  281. data/ext/boost/detail/limits.hpp +449 -0
  282. data/ext/boost/detail/reference_content.hpp +141 -0
  283. data/ext/boost/detail/shared_count.hpp +375 -0
  284. data/ext/boost/detail/sp_counted_base.hpp +81 -0
  285. data/ext/boost/detail/sp_counted_base_acc_ia64.hpp +150 -0
  286. data/ext/boost/detail/sp_counted_base_cw_ppc.hpp +170 -0
  287. data/ext/boost/detail/sp_counted_base_cw_x86.hpp +158 -0
  288. data/ext/boost/detail/sp_counted_base_gcc_ia64.hpp +157 -0
  289. data/ext/boost/detail/sp_counted_base_gcc_ppc.hpp +181 -0
  290. data/ext/boost/detail/sp_counted_base_gcc_sparc.hpp +166 -0
  291. data/ext/boost/detail/sp_counted_base_gcc_x86.hpp +173 -0
  292. data/ext/boost/detail/sp_counted_base_nt.hpp +107 -0
  293. data/ext/boost/detail/sp_counted_base_pt.hpp +135 -0
  294. data/ext/boost/detail/sp_counted_base_solaris.hpp +113 -0
  295. data/ext/boost/detail/sp_counted_base_sync.hpp +151 -0
  296. data/ext/boost/detail/sp_counted_base_w32.hpp +130 -0
  297. data/ext/boost/detail/sp_counted_impl.hpp +231 -0
  298. data/ext/boost/detail/sp_typeinfo.hpp +83 -0
  299. data/ext/boost/detail/workaround.hpp +202 -0
  300. data/ext/boost/enable_shared_from_this.hpp +73 -0
  301. data/ext/boost/function.hpp +66 -0
  302. data/ext/boost/function/detail/function_iterate.hpp +16 -0
  303. data/ext/boost/function/detail/maybe_include.hpp +267 -0
  304. data/ext/boost/function/detail/prologue.hpp +25 -0
  305. data/ext/boost/function/function_base.hpp +762 -0
  306. data/ext/boost/function/function_template.hpp +969 -0
  307. data/ext/boost/function_equal.hpp +28 -0
  308. data/ext/boost/get_pointer.hpp +29 -0
  309. data/ext/boost/implicit_cast.hpp +29 -0
  310. data/ext/boost/integer_traits.hpp +236 -0
  311. data/ext/boost/io/ios_state.hpp +431 -0
  312. data/ext/boost/io_fwd.hpp +67 -0
  313. data/ext/boost/is_placeholder.hpp +31 -0
  314. data/ext/boost/iterator.hpp +59 -0
  315. data/ext/boost/iterator/detail/config_def.hpp +135 -0
  316. data/ext/boost/iterator/detail/config_undef.hpp +25 -0
  317. data/ext/boost/iterator/detail/enable_if.hpp +86 -0
  318. data/ext/boost/iterator/detail/facade_iterator_category.hpp +200 -0
  319. data/ext/boost/iterator/detail/minimum_category.hpp +116 -0
  320. data/ext/boost/iterator/interoperable.hpp +50 -0
  321. data/ext/boost/iterator/iterator_adaptor.hpp +366 -0
  322. data/ext/boost/iterator/iterator_categories.hpp +188 -0
  323. data/ext/boost/iterator/iterator_facade.hpp +879 -0
  324. data/ext/boost/iterator/iterator_traits.hpp +92 -0
  325. data/ext/boost/iterator/reverse_iterator.hpp +69 -0
  326. data/ext/boost/iterator/transform_iterator.hpp +188 -0
  327. data/ext/boost/lexical_cast.hpp +1205 -0
  328. data/ext/boost/limits.hpp +146 -0
  329. data/ext/boost/mem_fn.hpp +389 -0
  330. data/ext/boost/mpl/always.hpp +39 -0
  331. data/ext/boost/mpl/and.hpp +60 -0
  332. data/ext/boost/mpl/apply.hpp +225 -0
  333. data/ext/boost/mpl/apply_fwd.hpp +107 -0
  334. data/ext/boost/mpl/apply_wrap.hpp +200 -0
  335. data/ext/boost/mpl/arg.hpp +131 -0
  336. data/ext/boost/mpl/arg_fwd.hpp +28 -0
  337. data/ext/boost/mpl/assert.hpp +370 -0
  338. data/ext/boost/mpl/aux_/adl_barrier.hpp +48 -0
  339. data/ext/boost/mpl/aux_/arg_typedef.hpp +31 -0
  340. data/ext/boost/mpl/aux_/arity.hpp +39 -0
  341. data/ext/boost/mpl/aux_/arity_spec.hpp +67 -0
  342. data/ext/boost/mpl/aux_/common_name_wknd.hpp +34 -0
  343. data/ext/boost/mpl/aux_/config/adl.hpp +40 -0
  344. data/ext/boost/mpl/aux_/config/arrays.hpp +30 -0
  345. data/ext/boost/mpl/aux_/config/bind.hpp +33 -0
  346. data/ext/boost/mpl/aux_/config/compiler.hpp +64 -0
  347. data/ext/boost/mpl/aux_/config/ctps.hpp +30 -0
  348. data/ext/boost/mpl/aux_/config/dtp.hpp +46 -0
  349. data/ext/boost/mpl/aux_/config/eti.hpp +47 -0
  350. data/ext/boost/mpl/aux_/config/gcc.hpp +23 -0
  351. data/ext/boost/mpl/aux_/config/has_apply.hpp +32 -0
  352. data/ext/boost/mpl/aux_/config/has_xxx.hpp +33 -0
  353. data/ext/boost/mpl/aux_/config/integral.hpp +38 -0
  354. data/ext/boost/mpl/aux_/config/intel.hpp +21 -0
  355. data/ext/boost/mpl/aux_/config/lambda.hpp +32 -0
  356. data/ext/boost/mpl/aux_/config/msvc.hpp +21 -0
  357. data/ext/boost/mpl/aux_/config/msvc_typename.hpp +26 -0
  358. data/ext/boost/mpl/aux_/config/nttp.hpp +41 -0
  359. data/ext/boost/mpl/aux_/config/overload_resolution.hpp +29 -0
  360. data/ext/boost/mpl/aux_/config/pp_counter.hpp +26 -0
  361. data/ext/boost/mpl/aux_/config/preprocessor.hpp +39 -0
  362. data/ext/boost/mpl/aux_/config/static_constant.hpp +25 -0
  363. data/ext/boost/mpl/aux_/config/ttp.hpp +41 -0
  364. data/ext/boost/mpl/aux_/config/use_preprocessed.hpp +19 -0
  365. data/ext/boost/mpl/aux_/config/workaround.hpp +19 -0
  366. data/ext/boost/mpl/aux_/full_lambda.hpp +350 -0
  367. data/ext/boost/mpl/aux_/has_apply.hpp +32 -0
  368. data/ext/boost/mpl/aux_/has_type.hpp +23 -0
  369. data/ext/boost/mpl/aux_/include_preprocessed.hpp +42 -0
  370. data/ext/boost/mpl/aux_/integral_wrapper.hpp +93 -0
  371. data/ext/boost/mpl/aux_/lambda_arity_param.hpp +25 -0
  372. data/ext/boost/mpl/aux_/lambda_support.hpp +169 -0
  373. data/ext/boost/mpl/aux_/msvc_never_true.hpp +34 -0
  374. data/ext/boost/mpl/aux_/na.hpp +95 -0
  375. data/ext/boost/mpl/aux_/na_assert.hpp +34 -0
  376. data/ext/boost/mpl/aux_/na_fwd.hpp +31 -0
  377. data/ext/boost/mpl/aux_/na_spec.hpp +175 -0
  378. data/ext/boost/mpl/aux_/nested_type_wknd.hpp +48 -0
  379. data/ext/boost/mpl/aux_/nttp_decl.hpp +35 -0
  380. data/ext/boost/mpl/aux_/preprocessed/gcc/and.hpp +69 -0
  381. data/ext/boost/mpl/aux_/preprocessed/gcc/apply.hpp +169 -0
  382. data/ext/boost/mpl/aux_/preprocessed/gcc/apply_fwd.hpp +52 -0
  383. data/ext/boost/mpl/aux_/preprocessed/gcc/apply_wrap.hpp +84 -0
  384. data/ext/boost/mpl/aux_/preprocessed/gcc/arg.hpp +123 -0
  385. data/ext/boost/mpl/aux_/preprocessed/gcc/bind.hpp +561 -0
  386. data/ext/boost/mpl/aux_/preprocessed/gcc/bind_fwd.hpp +52 -0
  387. data/ext/boost/mpl/aux_/preprocessed/gcc/full_lambda.hpp +558 -0
  388. data/ext/boost/mpl/aux_/preprocessed/gcc/or.hpp +69 -0
  389. data/ext/boost/mpl/aux_/preprocessed/gcc/placeholders.hpp +105 -0
  390. data/ext/boost/mpl/aux_/preprocessed/gcc/quote.hpp +123 -0
  391. data/ext/boost/mpl/aux_/preprocessed/gcc/template_arity.hpp +101 -0
  392. data/ext/boost/mpl/aux_/preprocessor/def_params_tail.hpp +105 -0
  393. data/ext/boost/mpl/aux_/preprocessor/enum.hpp +62 -0
  394. data/ext/boost/mpl/aux_/preprocessor/filter_params.hpp +28 -0
  395. data/ext/boost/mpl/aux_/preprocessor/params.hpp +65 -0
  396. data/ext/boost/mpl/aux_/preprocessor/sub.hpp +65 -0
  397. data/ext/boost/mpl/aux_/static_cast.hpp +27 -0
  398. data/ext/boost/mpl/aux_/template_arity.hpp +189 -0
  399. data/ext/boost/mpl/aux_/template_arity_fwd.hpp +23 -0
  400. data/ext/boost/mpl/aux_/type_wrapper.hpp +47 -0
  401. data/ext/boost/mpl/aux_/value_wknd.hpp +89 -0
  402. data/ext/boost/mpl/aux_/yes_no.hpp +58 -0
  403. data/ext/boost/mpl/bind.hpp +547 -0
  404. data/ext/boost/mpl/bind_fwd.hpp +99 -0
  405. data/ext/boost/mpl/bool.hpp +39 -0
  406. data/ext/boost/mpl/bool_fwd.hpp +33 -0
  407. data/ext/boost/mpl/eval_if.hpp +71 -0
  408. data/ext/boost/mpl/has_xxx.hpp +272 -0
  409. data/ext/boost/mpl/identity.hpp +45 -0
  410. data/ext/boost/mpl/if.hpp +135 -0
  411. data/ext/boost/mpl/int.hpp +22 -0
  412. data/ext/boost/mpl/int_fwd.hpp +27 -0
  413. data/ext/boost/mpl/integral_c.hpp +51 -0
  414. data/ext/boost/mpl/integral_c_fwd.hpp +32 -0
  415. data/ext/boost/mpl/integral_c_tag.hpp +26 -0
  416. data/ext/boost/mpl/lambda.hpp +29 -0
  417. data/ext/boost/mpl/lambda_fwd.hpp +57 -0
  418. data/ext/boost/mpl/limits/arity.hpp +21 -0
  419. data/ext/boost/mpl/logical.hpp +21 -0
  420. data/ext/boost/mpl/next.hpp +19 -0
  421. data/ext/boost/mpl/next_prior.hpp +49 -0
  422. data/ext/boost/mpl/not.hpp +51 -0
  423. data/ext/boost/mpl/or.hpp +61 -0
  424. data/ext/boost/mpl/placeholders.hpp +100 -0
  425. data/ext/boost/mpl/protect.hpp +55 -0
  426. data/ext/boost/mpl/quote.hpp +140 -0
  427. data/ext/boost/mpl/size_t.hpp +25 -0
  428. data/ext/boost/mpl/size_t_fwd.hpp +28 -0
  429. data/ext/boost/mpl/void.hpp +76 -0
  430. data/ext/boost/mpl/void_fwd.hpp +26 -0
  431. data/ext/boost/next_prior.hpp +51 -0
  432. data/ext/boost/non_type.hpp +27 -0
  433. data/ext/boost/noncopyable.hpp +36 -0
  434. data/ext/boost/none.hpp +28 -0
  435. data/ext/boost/none_t.hpp +24 -0
  436. data/ext/boost/operators.hpp +943 -0
  437. data/ext/boost/optional.hpp +18 -0
  438. data/ext/boost/optional/optional.hpp +922 -0
  439. data/ext/boost/optional/optional_fwd.hpp +22 -0
  440. data/ext/boost/preprocessor/arithmetic/add.hpp +51 -0
  441. data/ext/boost/preprocessor/arithmetic/dec.hpp +288 -0
  442. data/ext/boost/preprocessor/arithmetic/inc.hpp +288 -0
  443. data/ext/boost/preprocessor/arithmetic/sub.hpp +50 -0
  444. data/ext/boost/preprocessor/array/data.hpp +28 -0
  445. data/ext/boost/preprocessor/array/elem.hpp +29 -0
  446. data/ext/boost/preprocessor/array/size.hpp +28 -0
  447. data/ext/boost/preprocessor/cat.hpp +35 -0
  448. data/ext/boost/preprocessor/comma_if.hpp +17 -0
  449. data/ext/boost/preprocessor/config/config.hpp +70 -0
  450. data/ext/boost/preprocessor/control/detail/while.hpp +536 -0
  451. data/ext/boost/preprocessor/control/expr_iif.hpp +31 -0
  452. data/ext/boost/preprocessor/control/if.hpp +30 -0
  453. data/ext/boost/preprocessor/control/iif.hpp +34 -0
  454. data/ext/boost/preprocessor/control/while.hpp +312 -0
  455. data/ext/boost/preprocessor/debug/error.hpp +33 -0
  456. data/ext/boost/preprocessor/detail/auto_rec.hpp +293 -0
  457. data/ext/boost/preprocessor/detail/check.hpp +48 -0
  458. data/ext/boost/preprocessor/detail/is_binary.hpp +30 -0
  459. data/ext/boost/preprocessor/empty.hpp +17 -0
  460. data/ext/boost/preprocessor/enum.hpp +17 -0
  461. data/ext/boost/preprocessor/enum_params.hpp +17 -0
  462. data/ext/boost/preprocessor/facilities/empty.hpp +21 -0
  463. data/ext/boost/preprocessor/facilities/identity.hpp +23 -0
  464. data/ext/boost/preprocessor/identity.hpp +17 -0
  465. data/ext/boost/preprocessor/inc.hpp +17 -0
  466. data/ext/boost/preprocessor/iterate.hpp +17 -0
  467. data/ext/boost/preprocessor/iteration/detail/bounds/lower1.hpp +99 -0
  468. data/ext/boost/preprocessor/iteration/detail/bounds/upper1.hpp +99 -0
  469. data/ext/boost/preprocessor/iteration/detail/iter/forward1.hpp +1342 -0
  470. data/ext/boost/preprocessor/iteration/iterate.hpp +82 -0
  471. data/ext/boost/preprocessor/list/adt.hpp +73 -0
  472. data/ext/boost/preprocessor/list/append.hpp +40 -0
  473. data/ext/boost/preprocessor/list/detail/fold_left.hpp +279 -0
  474. data/ext/boost/preprocessor/list/detail/fold_right.hpp +277 -0
  475. data/ext/boost/preprocessor/list/fold_left.hpp +303 -0
  476. data/ext/boost/preprocessor/list/fold_right.hpp +40 -0
  477. data/ext/boost/preprocessor/list/for_each_i.hpp +65 -0
  478. data/ext/boost/preprocessor/list/reverse.hpp +40 -0
  479. data/ext/boost/preprocessor/list/transform.hpp +49 -0
  480. data/ext/boost/preprocessor/logical/and.hpp +30 -0
  481. data/ext/boost/preprocessor/logical/bitand.hpp +38 -0
  482. data/ext/boost/preprocessor/logical/bool.hpp +288 -0
  483. data/ext/boost/preprocessor/logical/compl.hpp +36 -0
  484. data/ext/boost/preprocessor/punctuation/comma.hpp +21 -0
  485. data/ext/boost/preprocessor/punctuation/comma_if.hpp +31 -0
  486. data/ext/boost/preprocessor/repeat.hpp +17 -0
  487. data/ext/boost/preprocessor/repetition/detail/for.hpp +536 -0
  488. data/ext/boost/preprocessor/repetition/enum.hpp +66 -0
  489. data/ext/boost/preprocessor/repetition/enum_binary_params.hpp +54 -0
  490. data/ext/boost/preprocessor/repetition/enum_params.hpp +41 -0
  491. data/ext/boost/preprocessor/repetition/for.hpp +306 -0
  492. data/ext/boost/preprocessor/repetition/repeat.hpp +825 -0
  493. data/ext/boost/preprocessor/repetition/repeat_from_to.hpp +87 -0
  494. data/ext/boost/preprocessor/seq/elem.hpp +304 -0
  495. data/ext/boost/preprocessor/seq/enum.hpp +288 -0
  496. data/ext/boost/preprocessor/seq/for_each_i.hpp +61 -0
  497. data/ext/boost/preprocessor/seq/seq.hpp +44 -0
  498. data/ext/boost/preprocessor/seq/size.hpp +548 -0
  499. data/ext/boost/preprocessor/slot/detail/def.hpp +49 -0
  500. data/ext/boost/preprocessor/slot/detail/shared.hpp +247 -0
  501. data/ext/boost/preprocessor/slot/slot.hpp +32 -0
  502. data/ext/boost/preprocessor/stringize.hpp +33 -0
  503. data/ext/boost/preprocessor/tuple/eat.hpp +57 -0
  504. data/ext/boost/preprocessor/tuple/elem.hpp +385 -0
  505. data/ext/boost/preprocessor/tuple/rem.hpp +72 -0
  506. data/ext/boost/preprocessor/tuple/to_list.hpp +62 -0
  507. data/ext/boost/range/as_literal.hpp +131 -0
  508. data/ext/boost/range/begin.hpp +132 -0
  509. data/ext/boost/range/config.hpp +54 -0
  510. data/ext/boost/range/const_iterator.hpp +64 -0
  511. data/ext/boost/range/detail/common.hpp +117 -0
  512. data/ext/boost/range/detail/implementation_help.hpp +99 -0
  513. data/ext/boost/range/detail/sfinae.hpp +77 -0
  514. data/ext/boost/range/detail/str_types.hpp +38 -0
  515. data/ext/boost/range/difference_type.hpp +29 -0
  516. data/ext/boost/range/distance.hpp +34 -0
  517. data/ext/boost/range/empty.hpp +34 -0
  518. data/ext/boost/range/end.hpp +131 -0
  519. data/ext/boost/range/functions.hpp +27 -0
  520. data/ext/boost/range/iterator.hpp +72 -0
  521. data/ext/boost/range/iterator_range.hpp +643 -0
  522. data/ext/boost/range/mutable_iterator.hpp +64 -0
  523. data/ext/boost/range/rbegin.hpp +65 -0
  524. data/ext/boost/range/rend.hpp +65 -0
  525. data/ext/boost/range/reverse_iterator.hpp +40 -0
  526. data/ext/boost/range/size.hpp +36 -0
  527. data/ext/boost/range/size_type.hpp +78 -0
  528. data/ext/boost/range/value_type.hpp +34 -0
  529. data/ext/boost/ref.hpp +178 -0
  530. data/ext/boost/shared_ptr.hpp +619 -0
  531. data/ext/boost/src/pthread/exceptions.cpp +146 -0
  532. data/ext/boost/src/pthread/once.cpp +51 -0
  533. data/ext/boost/src/pthread/thread.cpp +709 -0
  534. data/ext/boost/src/pthread/timeconv.inl +130 -0
  535. data/ext/boost/src/tss_null.cpp +34 -0
  536. data/ext/boost/src/win32/exceptions.cpp +124 -0
  537. data/ext/boost/src/win32/thread.cpp +629 -0
  538. data/ext/boost/src/win32/timeconv.inl +130 -0
  539. data/ext/boost/src/win32/tss_dll.cpp +72 -0
  540. data/ext/boost/src/win32/tss_pe.cpp +269 -0
  541. data/ext/boost/static_assert.hpp +122 -0
  542. data/ext/boost/thread.hpp +21 -0
  543. data/ext/boost/thread/condition.hpp +16 -0
  544. data/ext/boost/thread/condition_variable.hpp +21 -0
  545. data/ext/boost/thread/detail/config.hpp +94 -0
  546. data/ext/boost/thread/detail/move.hpp +33 -0
  547. data/ext/boost/thread/detail/platform.hpp +71 -0
  548. data/ext/boost/thread/exceptions.hpp +109 -0
  549. data/ext/boost/thread/locks.hpp +589 -0
  550. data/ext/boost/thread/mutex.hpp +21 -0
  551. data/ext/boost/thread/once.hpp +29 -0
  552. data/ext/boost/thread/pthread/condition_variable.hpp +184 -0
  553. data/ext/boost/thread/pthread/condition_variable_fwd.hpp +66 -0
  554. data/ext/boost/thread/pthread/mutex.hpp +211 -0
  555. data/ext/boost/thread/pthread/once.hpp +85 -0
  556. data/ext/boost/thread/pthread/pthread_mutex_scoped_lock.hpp +50 -0
  557. data/ext/boost/thread/pthread/recursive_mutex.hpp +249 -0
  558. data/ext/boost/thread/pthread/thread.hpp +339 -0
  559. data/ext/boost/thread/pthread/thread_data.hpp +102 -0
  560. data/ext/boost/thread/pthread/timespec.hpp +28 -0
  561. data/ext/boost/thread/pthread/tss.hpp +103 -0
  562. data/ext/boost/thread/recursive_mutex.hpp +21 -0
  563. data/ext/boost/thread/thread.hpp +22 -0
  564. data/ext/boost/thread/thread_time.hpp +46 -0
  565. data/ext/boost/thread/tss.hpp +18 -0
  566. data/ext/boost/thread/xtime.hpp +88 -0
  567. data/ext/boost/throw_exception.hpp +46 -0
  568. data/ext/boost/token_functions.hpp +621 -0
  569. data/ext/boost/token_iterator.hpp +128 -0
  570. data/ext/boost/tokenizer.hpp +98 -0
  571. data/ext/boost/type.hpp +18 -0
  572. data/ext/boost/type_traits/add_const.hpp +47 -0
  573. data/ext/boost/type_traits/add_pointer.hpp +72 -0
  574. data/ext/boost/type_traits/add_reference.hpp +89 -0
  575. data/ext/boost/type_traits/alignment_of.hpp +100 -0
  576. data/ext/boost/type_traits/broken_compiler_spec.hpp +117 -0
  577. data/ext/boost/type_traits/composite_traits.hpp +29 -0
  578. data/ext/boost/type_traits/config.hpp +76 -0
  579. data/ext/boost/type_traits/conversion_traits.hpp +17 -0
  580. data/ext/boost/type_traits/detail/bool_trait_def.hpp +173 -0
  581. data/ext/boost/type_traits/detail/bool_trait_undef.hpp +27 -0
  582. data/ext/boost/type_traits/detail/cv_traits_impl.hpp +97 -0
  583. data/ext/boost/type_traits/detail/false_result.hpp +28 -0
  584. data/ext/boost/type_traits/detail/ice_and.hpp +35 -0
  585. data/ext/boost/type_traits/detail/ice_eq.hpp +36 -0
  586. data/ext/boost/type_traits/detail/ice_not.hpp +31 -0
  587. data/ext/boost/type_traits/detail/ice_or.hpp +34 -0
  588. data/ext/boost/type_traits/detail/is_function_ptr_helper.hpp +220 -0
  589. data/ext/boost/type_traits/detail/is_mem_fun_pointer_impl.hpp +817 -0
  590. data/ext/boost/type_traits/detail/size_t_trait_def.hpp +58 -0
  591. data/ext/boost/type_traits/detail/size_t_trait_undef.hpp +16 -0
  592. data/ext/boost/type_traits/detail/template_arity_spec.hpp +31 -0
  593. data/ext/boost/type_traits/detail/type_trait_def.hpp +61 -0
  594. data/ext/boost/type_traits/detail/type_trait_undef.hpp +19 -0
  595. data/ext/boost/type_traits/detail/yes_no_type.hpp +26 -0
  596. data/ext/boost/type_traits/function_traits.hpp +236 -0
  597. data/ext/boost/type_traits/has_nothrow_copy.hpp +39 -0
  598. data/ext/boost/type_traits/has_trivial_copy.hpp +49 -0
  599. data/ext/boost/type_traits/ice.hpp +20 -0
  600. data/ext/boost/type_traits/integral_constant.hpp +53 -0
  601. data/ext/boost/type_traits/intrinsics.hpp +153 -0
  602. data/ext/boost/type_traits/is_abstract.hpp +144 -0
  603. data/ext/boost/type_traits/is_arithmetic.hpp +43 -0
  604. data/ext/boost/type_traits/is_array.hpp +90 -0
  605. data/ext/boost/type_traits/is_class.hpp +128 -0
  606. data/ext/boost/type_traits/is_const.hpp +142 -0
  607. data/ext/boost/type_traits/is_convertible.hpp +418 -0
  608. data/ext/boost/type_traits/is_enum.hpp +180 -0
  609. data/ext/boost/type_traits/is_float.hpp +27 -0
  610. data/ext/boost/type_traits/is_function.hpp +95 -0
  611. data/ext/boost/type_traits/is_integral.hpp +73 -0
  612. data/ext/boost/type_traits/is_member_function_pointer.hpp +134 -0
  613. data/ext/boost/type_traits/is_member_pointer.hpp +114 -0
  614. data/ext/boost/type_traits/is_pod.hpp +135 -0
  615. data/ext/boost/type_traits/is_pointer.hpp +160 -0
  616. data/ext/boost/type_traits/is_reference.hpp +116 -0
  617. data/ext/boost/type_traits/is_same.hpp +103 -0
  618. data/ext/boost/type_traits/is_scalar.hpp +55 -0
  619. data/ext/boost/type_traits/is_union.hpp +49 -0
  620. data/ext/boost/type_traits/is_void.hpp +33 -0
  621. data/ext/boost/type_traits/is_volatile.hpp +131 -0
  622. data/ext/boost/type_traits/remove_const.hpp +78 -0
  623. data/ext/boost/type_traits/remove_cv.hpp +61 -0
  624. data/ext/boost/type_traits/remove_pointer.hpp +43 -0
  625. data/ext/boost/type_traits/remove_reference.hpp +50 -0
  626. data/ext/boost/type_traits/type_with_alignment.hpp +288 -0
  627. data/ext/boost/utility.hpp +19 -0
  628. data/ext/boost/utility/addressof.hpp +58 -0
  629. data/ext/boost/utility/base_from_member.hpp +87 -0
  630. data/ext/boost/utility/compare_pointees.hpp +68 -0
  631. data/ext/boost/utility/enable_if.hpp +119 -0
  632. data/ext/boost/visit_each.hpp +29 -0
  633. data/ext/boost/weak_ptr.hpp +188 -0
  634. data/lib/rake/cplusplus.rb +43 -0
  635. data/lib/rake/extensions.rb +175 -0
  636. data/lib/rake/gempackagetask.rb +99 -0
  637. data/lib/rake/packagetask.rb +186 -0
  638. data/lib/rake/rdoctask.rb +209 -0
  639. data/man/passenger-config.1 +29 -0
  640. data/man/passenger-make-enterprisey.8 +23 -0
  641. data/man/passenger-memory-stats.8 +33 -0
  642. data/man/passenger-status.8 +43 -0
  643. data/man/passenger-stress-test.1 +43 -0
  644. data/misc/copy_boost_headers.rb +102 -0
  645. data/misc/find_owner_pipe_leaks.rb +121 -0
  646. data/misc/render_error_pages.rb +108 -0
  647. data/test/ApplicationPoolServerTest.cpp +74 -0
  648. data/test/ApplicationPoolServer_ApplicationPoolTest.cpp +31 -0
  649. data/test/ApplicationPoolTest.cpp +634 -0
  650. data/test/CxxTestMain.cpp +25 -0
  651. data/test/MessageChannelTest.cpp +312 -0
  652. data/test/SpawnManagerTest.cpp +64 -0
  653. data/test/StandardApplicationPoolTest.cpp +25 -0
  654. data/test/UtilsTest.cpp +238 -0
  655. data/test/config.yml.example +21 -0
  656. data/test/integration_tests.rb +791 -0
  657. data/test/ruby/abstract_server_spec.rb +17 -0
  658. data/test/ruby/application_spec.rb +43 -0
  659. data/test/ruby/message_channel_spec.rb +170 -0
  660. data/test/ruby/rack/application_spawner_spec.rb +41 -0
  661. data/test/ruby/rails/application_spawner_spec.rb +148 -0
  662. data/test/ruby/rails/framework_spawner_spec.rb +130 -0
  663. data/test/ruby/rails/minimal_spawner_spec.rb +74 -0
  664. data/test/ruby/rails/spawner_error_handling_spec.rb +52 -0
  665. data/test/ruby/rails/spawner_privilege_lowering_spec.rb +97 -0
  666. data/test/ruby/spawn_manager_spec.rb +189 -0
  667. data/test/ruby/spawn_server_spec.rb +26 -0
  668. data/test/ruby/utils_spec.rb +67 -0
  669. data/test/stub/apache2/httpd.conf.erb +79 -0
  670. data/test/stub/apache2/mime.types +748 -0
  671. data/test/stub/garbage1.dat +0 -0
  672. data/test/stub/garbage2.dat +0 -0
  673. data/test/stub/garbage3.dat +0 -0
  674. data/test/stub/http_request.yml +23 -0
  675. data/test/stub/message_channel.rb +9 -0
  676. data/test/stub/message_channel_2.rb +10 -0
  677. data/test/stub/message_channel_3.rb +17 -0
  678. data/test/stub/minimal-railsapp/README +3 -0
  679. data/test/stub/minimal-railsapp/config/application.rb +0 -0
  680. data/test/stub/minimal-railsapp/config/environment.rb +3 -0
  681. data/test/stub/minimal-railsapp/vendor/rails/actionmailer/lib/action_mailer.rb +0 -0
  682. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_controller.rb +10 -0
  683. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_pack.rb +0 -0
  684. data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_view.rb +0 -0
  685. data/test/stub/minimal-railsapp/vendor/rails/activerecord/lib/active_record.rb +7 -0
  686. data/test/stub/minimal-railsapp/vendor/rails/activeresource/lib/active_resource.rb +0 -0
  687. data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support.rb +17 -0
  688. data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support/whiny_nil.rb +0 -0
  689. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/dispatcher.rb +0 -0
  690. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/initializer.rb +8 -0
  691. data/test/stub/minimal-railsapp/vendor/rails/railties/lib/ruby_version_check.rb +1 -0
  692. data/test/stub/rack/config.ru +4 -0
  693. data/test/stub/rack/public/rack.jpg +0 -0
  694. data/test/stub/rails_apps/foobar/app/controllers/application.rb +12 -0
  695. data/test/stub/rails_apps/foobar/app/controllers/bar_controller_1.rb +5 -0
  696. data/test/stub/rails_apps/foobar/app/controllers/bar_controller_2.rb +5 -0
  697. data/test/stub/rails_apps/foobar/app/controllers/foo_controller.rb +21 -0
  698. data/test/stub/rails_apps/foobar/app/helpers/application_helper.rb +3 -0
  699. data/test/stub/rails_apps/foobar/config/boot.rb +108 -0
  700. data/test/stub/rails_apps/foobar/config/database.yml +19 -0
  701. data/test/stub/rails_apps/foobar/config/environment.rb +59 -0
  702. data/test/stub/rails_apps/foobar/config/environments/development.rb +17 -0
  703. data/test/stub/rails_apps/foobar/config/environments/production.rb +18 -0
  704. data/test/stub/rails_apps/foobar/config/initializers/inflections.rb +10 -0
  705. data/test/stub/rails_apps/foobar/config/initializers/mime_types.rb +5 -0
  706. data/test/stub/rails_apps/foobar/config/routes.rb +35 -0
  707. data/test/stub/rails_apps/mycook/app/controllers/application.rb +12 -0
  708. data/test/stub/rails_apps/mycook/app/controllers/recipes_controller.rb +5 -0
  709. data/test/stub/rails_apps/mycook/app/controllers/uploads_controller.rb +11 -0
  710. data/test/stub/rails_apps/mycook/app/controllers/welcome_controller.rb +55 -0
  711. data/test/stub/rails_apps/mycook/app/helpers/application_helper.rb +3 -0
  712. data/test/stub/rails_apps/mycook/app/views/layouts/default.rhtml +26 -0
  713. data/test/stub/rails_apps/mycook/app/views/recipes/create.rhtml +13 -0
  714. data/test/stub/rails_apps/mycook/app/views/recipes/index.rhtml +3 -0
  715. data/test/stub/rails_apps/mycook/app/views/recipes/new.rhtml +8 -0
  716. data/test/stub/rails_apps/mycook/app/views/uploads/index.rhtml +1 -0
  717. data/test/stub/rails_apps/mycook/app/views/uploads/new.html.erb +8 -0
  718. data/test/stub/rails_apps/mycook/app/views/welcome/cached.rhtml +1 -0
  719. data/test/stub/rails_apps/mycook/app/views/welcome/index.rhtml +20 -0
  720. data/test/stub/rails_apps/mycook/config/boot.rb +108 -0
  721. data/test/stub/rails_apps/mycook/config/database.yml +19 -0
  722. data/test/stub/rails_apps/mycook/config/environment.rb +61 -0
  723. data/test/stub/rails_apps/mycook/config/environments/development.rb +18 -0
  724. data/test/stub/rails_apps/mycook/config/environments/production.rb +19 -0
  725. data/test/stub/rails_apps/mycook/config/initializers/inflections.rb +10 -0
  726. data/test/stub/rails_apps/mycook/config/initializers/mime_types.rb +5 -0
  727. data/test/stub/rails_apps/mycook/config/routes.rb +38 -0
  728. data/test/stub/rails_apps/mycook/log/useless.txt +1 -0
  729. data/test/stub/rails_apps/mycook/public/404.html +30 -0
  730. data/test/stub/rails_apps/mycook/public/422.html +30 -0
  731. data/test/stub/rails_apps/mycook/public/500.html +30 -0
  732. data/test/stub/rails_apps/mycook/public/dispatch.cgi +10 -0
  733. data/test/stub/rails_apps/mycook/public/dispatch.fcgi +24 -0
  734. data/test/stub/rails_apps/mycook/public/dispatch.rb +10 -0
  735. data/test/stub/rails_apps/mycook/public/favicon.ico +0 -0
  736. data/test/stub/rails_apps/mycook/public/images/angrywizard.gif +0 -0
  737. data/test/stub/rails_apps/mycook/public/images/cookbook.gif +0 -0
  738. data/test/stub/rails_apps/mycook/public/images/header.png +0 -0
  739. data/test/stub/rails_apps/mycook/public/images/rails.png +0 -0
  740. data/test/stub/rails_apps/mycook/public/javascripts/application.js +2 -0
  741. data/test/stub/rails_apps/mycook/public/javascripts/controls.js +963 -0
  742. data/test/stub/rails_apps/mycook/public/javascripts/dragdrop.js +972 -0
  743. data/test/stub/rails_apps/mycook/public/javascripts/effects.js +1120 -0
  744. data/test/stub/rails_apps/mycook/public/javascripts/prototype.js +4225 -0
  745. data/test/stub/rails_apps/mycook/public/robots.txt +5 -0
  746. data/test/stub/rails_apps/mycook/public/uploads.html +26 -0
  747. data/test/stub/rails_apps/mycook/public/welcome/cached.html +26 -0
  748. data/test/stub/rails_apps/mycook/tmp/cache/useless.txt +1 -0
  749. data/test/stub/rails_apps/mycook/tmp/pids/useless.txt +1 -0
  750. data/test/stub/rails_apps/mycook/tmp/sessions/useless.txt +1 -0
  751. data/test/stub/rails_apps/mycook/tmp/sockets/useless.txt +1 -0
  752. data/test/stub/railsapp/app/controllers/application.rb +12 -0
  753. data/test/stub/railsapp/app/controllers/bar_controller_1.rb +5 -0
  754. data/test/stub/railsapp/app/controllers/bar_controller_2.rb +5 -0
  755. data/test/stub/railsapp/app/controllers/foo_controller.rb +9 -0
  756. data/test/stub/railsapp/app/helpers/application_helper.rb +3 -0
  757. data/test/stub/railsapp/config/boot.rb +108 -0
  758. data/test/stub/railsapp/config/database.yml +19 -0
  759. data/test/stub/railsapp/config/environment.rb +59 -0
  760. data/test/stub/railsapp/config/environments/development.rb +18 -0
  761. data/test/stub/railsapp/config/environments/production.rb +19 -0
  762. data/test/stub/railsapp/config/initializers/inflections.rb +10 -0
  763. data/test/stub/railsapp/config/initializers/mime_types.rb +5 -0
  764. data/test/stub/railsapp/config/routes.rb +35 -0
  765. data/test/stub/railsapp/public/useless.txt +1 -0
  766. data/test/stub/railsapp2/app/controllers/application.rb +12 -0
  767. data/test/stub/railsapp2/app/controllers/foo_controller.rb +5 -0
  768. data/test/stub/railsapp2/app/helpers/application_helper.rb +3 -0
  769. data/test/stub/railsapp2/config/boot.rb +108 -0
  770. data/test/stub/railsapp2/config/database.yml +19 -0
  771. data/test/stub/railsapp2/config/environment.rb +59 -0
  772. data/test/stub/railsapp2/config/environments/development.rb +18 -0
  773. data/test/stub/railsapp2/config/environments/production.rb +19 -0
  774. data/test/stub/railsapp2/config/initializers/inflections.rb +10 -0
  775. data/test/stub/railsapp2/config/initializers/mime_types.rb +5 -0
  776. data/test/stub/railsapp2/config/routes.rb +35 -0
  777. data/test/stub/railsapp2/public/useless.txt +1 -0
  778. data/test/stub/spawn_server.rb +20 -0
  779. data/test/stub/upload_data.txt +494 -0
  780. data/test/stub/vendor_rails/minimal/README +1 -0
  781. data/test/stub/vendor_rails/minimal/actionmailer/lib/action_mailer.rb +0 -0
  782. data/test/stub/vendor_rails/minimal/actionpack/lib/action_controller.rb +19 -0
  783. data/test/stub/vendor_rails/minimal/actionpack/lib/action_pack.rb +0 -0
  784. data/test/stub/vendor_rails/minimal/actionpack/lib/action_view.rb +0 -0
  785. data/test/stub/vendor_rails/minimal/activerecord/lib/active_record.rb +7 -0
  786. data/test/stub/vendor_rails/minimal/activeresource/lib/active_resource.rb +0 -0
  787. data/test/stub/vendor_rails/minimal/activesupport/lib/active_support.rb +17 -0
  788. data/test/stub/vendor_rails/minimal/activesupport/lib/active_support/whiny_nil.rb +0 -0
  789. data/test/stub/vendor_rails/minimal/railties/lib/dispatcher.rb +0 -0
  790. data/test/stub/vendor_rails/minimal/railties/lib/initializer.rb +52 -0
  791. data/test/stub/vendor_rails/minimal/railties/lib/ruby_version_check.rb +1 -0
  792. data/test/stub/wsgi/passenger_wsgi.py +3 -0
  793. data/test/stub/wsgi/public/wsgi-snake.jpg +0 -0
  794. data/test/stub/zsfa/header.png +0 -0
  795. data/test/stub/zsfa/index.html +14 -0
  796. data/test/stub/zsfa/zsfa.png +0 -0
  797. data/test/support/apache2_controller.rb +246 -0
  798. data/test/support/config.rb +13 -0
  799. data/test/support/multipart.rb +62 -0
  800. data/test/support/run_rspec_tests.rb +10 -0
  801. data/test/support/test_helper.rb +94 -0
  802. data/test/support/tut.h +1234 -0
  803. data/test/support/tut_reporter.h +256 -0
  804. data/test/support/valgrind.h +2539 -0
  805. metadata +1342 -0
@@ -0,0 +1,1195 @@
1
+ /*
2
+ * Phusion Passenger - http://www.modrails.com/
3
+ * Copyright (C) 2008 Phusion
4
+ *
5
+ * Phusion Passenger is a trademark of Hongli Lai & Ninh Bui.
6
+ *
7
+ * This program is free software; you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation; version 2 of the License.
10
+ *
11
+ * This program is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ * GNU General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along
17
+ * with this program; if not, write to the Free Software Foundation, Inc.,
18
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
+ */
20
+ #include <boost/thread.hpp>
21
+
22
+ #include <sys/time.h>
23
+ #include <sys/resource.h>
24
+ #include <exception>
25
+ #include <cstdio>
26
+ #include <unistd.h>
27
+
28
+ #include "Hooks.h"
29
+ #include "Bucket.h"
30
+ #include "Configuration.h"
31
+ #include "Utils.h"
32
+ #include "Logging.h"
33
+ #include "ApplicationPoolServer.h"
34
+ #include "MessageChannel.h"
35
+ #include "DirectoryMapper.h"
36
+
37
+ // The Apache/APR headers *must* come after the Boost headers, otherwise
38
+ // compilation will fail on OpenBSD.
39
+ #include <ap_config.h>
40
+ #include <httpd.h>
41
+ #include <http_config.h>
42
+ #include <http_core.h>
43
+ #include <http_request.h>
44
+ #include <http_protocol.h>
45
+ #include <http_log.h>
46
+ #include <util_script.h>
47
+ #include <apr_pools.h>
48
+ #include <apr_strings.h>
49
+ #include <apr_lib.h>
50
+
51
+ using namespace std;
52
+ using namespace Passenger;
53
+
54
+ extern "C" module AP_MODULE_DECLARE_DATA passenger_module;
55
+
56
+
57
+ #define DEFAULT_RUBY_COMMAND "ruby"
58
+
59
+ /**
60
+ * If the HTTP client sends POST data larger than this value (in bytes),
61
+ * then the POST data will be fully saved into a temporary file, before
62
+ * allocating a Ruby web application session.
63
+ */
64
+ #define UPLOAD_ACCELERATION_THRESHOLD 1024 * 8
65
+
66
+
67
+ /**
68
+ * Apache hook functions, wrapped in a class.
69
+ *
70
+ * @ingroup Core
71
+ */
72
+ class Hooks {
73
+ private:
74
+ struct AprDestructable {
75
+ virtual ~AprDestructable() { }
76
+
77
+ static apr_status_t cleanup(void *p) {
78
+ delete (AprDestructable *) p;
79
+ return APR_SUCCESS;
80
+ }
81
+ };
82
+
83
+ struct RequestNote: public AprDestructable {
84
+ DirectoryMapper mapper;
85
+ DirConfig *config;
86
+ bool forwardToBackend;
87
+ const char *handlerBeforeModRewrite;
88
+ char *filenameBeforeModRewrite;
89
+ apr_filetype_e oldFileType;
90
+ const char *handlerBeforeModAutoIndex;
91
+
92
+ RequestNote(const DirectoryMapper &m)
93
+ : mapper(m) {
94
+ forwardToBackend = false;
95
+ filenameBeforeModRewrite = NULL;
96
+ }
97
+ };
98
+
99
+ struct ErrorReport: public AprDestructable {
100
+ virtual int report(request_rec *r) = 0;
101
+ };
102
+
103
+ struct ReportFileSystemError: public ErrorReport {
104
+ FileSystemException e;
105
+
106
+ ReportFileSystemError(const FileSystemException &ex): e(ex) { }
107
+
108
+ int report(request_rec *r) {
109
+ ap_set_content_type(r, "text/html; charset=UTF-8");
110
+ ap_rputs("<h1>Passenger error #2</h1>\n", r);
111
+ ap_rputs("An error occurred while trying to access '", r);
112
+ ap_rputs(ap_escape_html(r->pool, e.filename().c_str()), r);
113
+ ap_rputs("': ", r);
114
+ ap_rputs(ap_escape_html(r->pool, e.what()), r);
115
+ if (e.code() == EPERM) {
116
+ ap_rputs("<p>", r);
117
+ ap_rputs("Apache doesn't have read permissions to that file. ", r);
118
+ ap_rputs("Please fix the relevant file permissions.", r);
119
+ ap_rputs("</p>", r);
120
+ }
121
+ P_ERROR("A filesystem exception occured.\n" <<
122
+ " Message: " << e.what() << "\n" <<
123
+ " Backtrace:\n" << e.backtrace());
124
+ return OK;
125
+ }
126
+ };
127
+
128
+ enum Threeway { YES, NO, UNKNOWN };
129
+
130
+ ApplicationPoolServerPtr applicationPoolServer;
131
+ thread_specific_ptr<ApplicationPoolPtr> threadSpecificApplicationPool;
132
+ Threeway m_hasModRewrite, m_hasModDir, m_hasModAutoIndex;
133
+ CachedMultiFileStat *mstat;
134
+
135
+ inline DirConfig *getDirConfig(request_rec *r) {
136
+ return (DirConfig *) ap_get_module_config(r->per_dir_config, &passenger_module);
137
+ }
138
+
139
+ inline ServerConfig *getServerConfig(server_rec *s) {
140
+ return (ServerConfig *) ap_get_module_config(s->module_config, &passenger_module);
141
+ }
142
+
143
+ inline RequestNote *getRequestNote(request_rec *r) {
144
+ // The union is needed in order to be compliant with
145
+ // C99/C++'s strict aliasing rules. http://tinyurl.com/g5hgh
146
+ union {
147
+ RequestNote *note;
148
+ void *pointer;
149
+ } u;
150
+ u.note = 0;
151
+ apr_pool_userdata_get(&u.pointer, "Phusion Passenger", r->pool);
152
+ return u.note;
153
+ }
154
+
155
+ /**
156
+ * Returns a usable ApplicationPool object.
157
+ *
158
+ * When using the worker MPM and global queuing, deadlocks can occur, for
159
+ * the same reason described in ApplicationPoolServer::connect(). This
160
+ * method allows us to avoid this deadlock by making sure that each
161
+ * thread gets its own connection to the application pool server.
162
+ *
163
+ * It also checks whether the currently cached ApplicationPool object
164
+ * is disconnected (which can happen if an error previously occured).
165
+ * If so, it will reconnect to the ApplicationPool server.
166
+ */
167
+ ApplicationPoolPtr getApplicationPool() {
168
+ ApplicationPoolPtr *pool_ptr = threadSpecificApplicationPool.get();
169
+ if (pool_ptr == NULL) {
170
+ pool_ptr = new ApplicationPoolPtr(applicationPoolServer->connect());
171
+ threadSpecificApplicationPool.reset(pool_ptr);
172
+ } else if (!(*pool_ptr)->connected()) {
173
+ P_DEBUG("Reconnecting to ApplicationPool server");
174
+ *pool_ptr = applicationPoolServer->connect();
175
+ }
176
+ return *pool_ptr;
177
+ }
178
+
179
+ bool hasModRewrite() {
180
+ if (m_hasModRewrite == UNKNOWN) {
181
+ if (ap_find_linked_module("mod_rewrite.c")) {
182
+ m_hasModRewrite = YES;
183
+ } else {
184
+ m_hasModRewrite = NO;
185
+ }
186
+ }
187
+ return m_hasModRewrite == YES;
188
+ }
189
+
190
+ bool hasModDir() {
191
+ if (m_hasModDir == UNKNOWN) {
192
+ if (ap_find_linked_module("mod_dir.c")) {
193
+ m_hasModDir = YES;
194
+ } else {
195
+ m_hasModDir = NO;
196
+ }
197
+ }
198
+ return m_hasModDir == YES;
199
+ }
200
+
201
+ bool hasModAutoIndex() {
202
+ if (m_hasModAutoIndex == UNKNOWN) {
203
+ if (ap_find_linked_module("mod_autoindex.c")) {
204
+ m_hasModAutoIndex = YES;
205
+ } else {
206
+ m_hasModAutoIndex = NO;
207
+ }
208
+ }
209
+ return m_hasModAutoIndex == YES;
210
+ }
211
+
212
+ int reportDocumentRootDeterminationError(request_rec *r) {
213
+ ap_set_content_type(r, "text/html; charset=UTF-8");
214
+ ap_rputs("<h1>Passenger error #1</h1>\n", r);
215
+ ap_rputs("Cannot determine the document root for the current request.", r);
216
+ return OK;
217
+ }
218
+
219
+ int reportBusyException(request_rec *r) {
220
+ ap_custom_response(r, HTTP_SERVICE_UNAVAILABLE,
221
+ "This website is too busy right now. Please try again later.");
222
+ return HTTP_SERVICE_UNAVAILABLE;
223
+ }
224
+
225
+ /**
226
+ * Gather some information about the request and do some preparations. In this method,
227
+ * it will be determined whether the request URI should be served statically by Apache
228
+ * (in case of static assets or in case there's a page cache file available) or
229
+ * whether it should be forwarded to the backend application.
230
+ *
231
+ * The strategy is as follows:
232
+ *
233
+ * We check whether Phusion Passenger is enabled for this URI (A).
234
+ * If so, then we check whether the following situations are true:
235
+ * (B) There is a backend application defined for this URI.
236
+ * (C) r->filename already exists.
237
+ * (D) There is a page cache file for the URI.
238
+ *
239
+ * - If A is not true, or if B is not true, or if C is true, then won't do anything.
240
+ * Passenger will be disabled during the rest of this request.
241
+ * - If D is true, then we first transform r->filename to the page cache file's
242
+ * filename, and then we let Apache serve it statically.
243
+ * - If D is not true, then we forward the request to the backend application.
244
+ *
245
+ * @pre The (A) condition must be true.
246
+ * @param coreModuleWillBeRun Whether the core.c map_to_storage hook might be called after this.
247
+ * @return Whether the Passenger handler hook method should be run.
248
+ */
249
+ bool prepareRequest(request_rec *r, DirConfig *config, const char *filename, bool coreModuleWillBeRun = false) {
250
+ TRACE_POINT();
251
+ DirectoryMapper mapper(r, config, mstat, config->getStatThrottleRate());
252
+ try {
253
+ if (mapper.getBaseURI() == NULL) {
254
+ // (B) is not true.
255
+ return false;
256
+ }
257
+ } catch (const FileSystemException &e) {
258
+ /* DirectoryMapper tried to examine the filesystem in order
259
+ * to autodetect the application type (e.g. by checking whether
260
+ * environment.rb exists. But something went wrong, probably
261
+ * because of a permission problem. This usually
262
+ * means that the user is trying to deploy an application, but
263
+ * set the wrong permissions on the relevant folders.
264
+ * Later, in the handler hook, we inform the user about this
265
+ * problem so that he can either disable Phusion Passenger's
266
+ * autodetection routines, or fix the permissions.
267
+ */
268
+ apr_pool_userdata_set(new ReportFileSystemError(e),
269
+ "Phusion Passenger: error report",
270
+ ReportFileSystemError::cleanup,
271
+ r->pool);
272
+ return true;
273
+ }
274
+
275
+ /* Save some information for the hook methods that are called later.
276
+ * The existance of this note indicates that the URI belongs to a Phusion
277
+ * Passenger-served application.
278
+ */
279
+ RequestNote *note = new RequestNote(mapper);
280
+ note->config = config;
281
+ apr_pool_userdata_set(note, "Phusion Passenger", RequestNote::cleanup, r->pool);
282
+
283
+ try {
284
+ // (B) is true.
285
+ FileType fileType = getFileType(filename);
286
+ if (fileType == FT_REGULAR) {
287
+ // (C) is true.
288
+ return false;
289
+ }
290
+
291
+ // (C) is not true. Check whether (D) is true.
292
+ char *pageCacheFile;
293
+ /* Only GET requests may hit the page cache. This is
294
+ * important because of REST conventions, e.g.
295
+ * 'POST /foo' maps to 'FooController#create',
296
+ * while 'GET /foo' maps to 'FooController#index'.
297
+ * We wouldn't want our page caching support to interfere
298
+ * with that.
299
+ */
300
+ if (r->method_number == M_GET) {
301
+ if (fileType == FT_DIRECTORY) {
302
+ size_t len;
303
+
304
+ len = strlen(filename);
305
+ if (len > 0 && filename[len - 1] == '/') {
306
+ pageCacheFile = apr_pstrcat(r->pool, filename,
307
+ "index.html", NULL);
308
+ } else {
309
+ pageCacheFile = apr_pstrcat(r->pool, filename,
310
+ ".html", NULL);
311
+ }
312
+ } else {
313
+ pageCacheFile = apr_pstrcat(r->pool, filename,
314
+ ".html", NULL);
315
+ }
316
+ if (!fileExists(pageCacheFile)) {
317
+ pageCacheFile = NULL;
318
+ }
319
+ } else {
320
+ pageCacheFile = NULL;
321
+ }
322
+ if (pageCacheFile != NULL) {
323
+ // (D) is true.
324
+ r->filename = pageCacheFile;
325
+ r->canonical_filename = pageCacheFile;
326
+ if (!coreModuleWillBeRun) {
327
+ r->finfo.filetype = APR_NOFILE;
328
+ ap_set_content_type(r, "text/html");
329
+ ap_directory_walk(r);
330
+ ap_file_walk(r);
331
+ }
332
+ return false;
333
+ } else {
334
+ // (D) is not true.
335
+ note->forwardToBackend = true;
336
+ return true;
337
+ }
338
+ } catch (const FileSystemException &e) {
339
+ /* Something went wrong while accessing the directory in which
340
+ * r->filename lives. We already know that this URI belongs to
341
+ * a backend application, so this error probably means that the
342
+ * user set the wrong permissions for his 'public' folder. We
343
+ * don't let the handler hook run so that Apache can decide how
344
+ * to display the error.
345
+ */
346
+ return false;
347
+ }
348
+ }
349
+
350
+ /**
351
+ * Most of the high-level logic for forwarding a request to a backend application
352
+ * is contained in this method.
353
+ */
354
+ int handleRequest(request_rec *r) {
355
+ /* Check whether an error occured in prepareRequest() that should be reported
356
+ * to the browser.
357
+ */
358
+
359
+ // The union is needed in order to be compliant with
360
+ // C99/C++'s strict aliasing rules. http://tinyurl.com/g5hgh
361
+ union {
362
+ ErrorReport *errorReport;
363
+ void *pointer;
364
+ } u;
365
+
366
+ u.errorReport = 0;
367
+ apr_pool_userdata_get(&u.pointer, "Phusion Passenger: error report", r->pool);
368
+ if (u.errorReport != 0) {
369
+ return u.errorReport->report(r);
370
+ }
371
+
372
+ RequestNote *note = getRequestNote(r);
373
+ if (note == 0 || !note->forwardToBackend) {
374
+ return DECLINED;
375
+ } else if (r->handler != NULL && strcmp(r->handler, "redirect-handler") == 0) {
376
+ // mod_rewrite is at work.
377
+ return DECLINED;
378
+ }
379
+
380
+ TRACE_POINT();
381
+ DirConfig *config = note->config;
382
+ DirectoryMapper &mapper(note->mapper);
383
+
384
+ if (mapper.getPublicDirectory().empty()) {
385
+ return reportDocumentRootDeterminationError(r);
386
+ }
387
+
388
+ int httpStatus = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR);
389
+ if (httpStatus != OK) {
390
+ return httpStatus;
391
+ }
392
+
393
+ try {
394
+ this_thread::disable_interruption di;
395
+ this_thread::disable_syscall_interruption dsi;
396
+ apr_bucket_brigade *bb;
397
+ apr_bucket *b;
398
+ Application::SessionPtr session;
399
+ bool expectingUploadData;
400
+ shared_ptr<TempFile> uploadData;
401
+
402
+ expectingUploadData = ap_should_client_block(r);
403
+ if (expectingUploadData && atol(lookupHeader(r, "Content-Length"))
404
+ > UPLOAD_ACCELERATION_THRESHOLD) {
405
+ uploadData = receiveRequestBody(r);
406
+ }
407
+
408
+ UPDATE_TRACE_POINT();
409
+ try {
410
+ ServerConfig *sconfig = getServerConfig(r->server);
411
+ string appRoot(canonicalizePath(
412
+ config->getAppRoot(mapper.getPublicDirectory().c_str())
413
+ ));
414
+
415
+ session = getApplicationPool()->get(PoolOptions(
416
+ appRoot,
417
+ true,
418
+ sconfig->getDefaultUser(),
419
+ mapper.getEnvironment(),
420
+ config->getSpawnMethodString(),
421
+ mapper.getApplicationTypeString(),
422
+ config->frameworkSpawnerTimeout,
423
+ config->appSpawnerTimeout,
424
+ config->getMaxRequests(),
425
+ config->getMemoryLimit(),
426
+ config->usingGlobalQueue(),
427
+ config->getStatThrottleRate(),
428
+ config->getRestartDir()
429
+ ));
430
+ P_TRACE(3, "Forwarding " << r->uri << " to PID " << session->getPid());
431
+ } catch (const SpawnException &e) {
432
+ r->status = 500;
433
+ if (e.hasErrorPage()) {
434
+ ap_set_content_type(r, "text/html; charset=utf-8");
435
+ ap_rputs(e.getErrorPage().c_str(), r);
436
+ return OK;
437
+ } else {
438
+ throw;
439
+ }
440
+ } catch (const FileSystemException &e) {
441
+ /* The application root cannot be determined. This could
442
+ * happen if, for example, the user specified 'RailsBaseURI /foo'
443
+ * while there is no filesystem entry called "foo" in the virtual
444
+ * host's document root.
445
+ */
446
+ return ReportFileSystemError(e).report(r);
447
+ } catch (const BusyException &e) {
448
+ return reportBusyException(r);
449
+ }
450
+
451
+ UPDATE_TRACE_POINT();
452
+ session->setReaderTimeout(r->server->timeout / 1000);
453
+ session->setWriterTimeout(r->server->timeout / 1000);
454
+ sendHeaders(r, session, mapper.getBaseURI());
455
+ if (expectingUploadData) {
456
+ if (uploadData != NULL) {
457
+ sendRequestBody(r, session, uploadData);
458
+ uploadData.reset();
459
+ } else {
460
+ sendRequestBody(r, session);
461
+ }
462
+ }
463
+ session->shutdownWriter();
464
+
465
+ UPDATE_TRACE_POINT();
466
+ apr_file_t *readerPipe = NULL;
467
+ int reader = session->getStream();
468
+ pid_t backendPid = session->getPid();
469
+ apr_os_pipe_put(&readerPipe, &reader, r->pool);
470
+ apr_file_pipe_timeout_set(readerPipe, r->server->timeout);
471
+
472
+ bb = apr_brigade_create(r->connection->pool, r->connection->bucket_alloc);
473
+ b = passenger_bucket_create(session, readerPipe, r->connection->bucket_alloc);
474
+ session.reset();
475
+ APR_BRIGADE_INSERT_TAIL(bb, b);
476
+
477
+ b = apr_bucket_eos_create(r->connection->bucket_alloc);
478
+ APR_BRIGADE_INSERT_TAIL(bb, b);
479
+
480
+ // I know the size because I read util_script.c's source. :-(
481
+ char backendData[MAX_STRING_LEN];
482
+ int result = ap_scan_script_header_err_brigade(r, bb, backendData);
483
+ if (result == OK) {
484
+ // The API documentation for ap_scan_script_err_brigade() says it
485
+ // returns HTTP_OK on success, but it actually returns OK.
486
+
487
+ // Manually set the Status header because
488
+ // ap_scan_script_header_err_brigade() filters it
489
+ // out. Some broken HTTP clients depend on the
490
+ // Status header for retrieving the HTTP status.
491
+ if (!r->status_line && *r->status_line == '\0') {
492
+ r->status_line = apr_psprintf(r->pool,
493
+ "%d Unknown Status",
494
+ r->status);
495
+ }
496
+ apr_table_setn(r->headers_out, "Status", r->status_line);
497
+
498
+ ap_pass_brigade(r->output_filters, bb);
499
+ return OK;
500
+ } else if (backendData[0] == '\0') {
501
+ P_ERROR("Backend process " << backendPid <<
502
+ " did not return a valid HTTP response. It returned no data.");
503
+ apr_table_setn(r->err_headers_out, "Status", "500 Internal Server Error");
504
+ return HTTP_INTERNAL_SERVER_ERROR;
505
+ } else {
506
+ P_ERROR("Backend process " << backendPid <<
507
+ " did not return a valid HTTP response. It returned: [" <<
508
+ backendData << "]");
509
+ apr_table_setn(r->err_headers_out, "Status", "500 Internal Server Error");
510
+ return HTTP_INTERNAL_SERVER_ERROR;
511
+ }
512
+
513
+ } catch (const thread_interrupted &e) {
514
+ P_TRACE(3, "A system call was interrupted during an HTTP request. Apache "
515
+ "is probably restarting or shutting down. Backtrace:\n" <<
516
+ e.backtrace());
517
+ return HTTP_INTERNAL_SERVER_ERROR;
518
+
519
+ } catch (const tracable_exception &e) {
520
+ P_ERROR("Unexpected error in mod_passenger: " <<
521
+ e.what() << "\n" << " Backtrace:\n" << e.backtrace());
522
+ return HTTP_INTERNAL_SERVER_ERROR;
523
+
524
+ } catch (const exception &e) {
525
+ P_ERROR("Unexpected error in mod_passenger: " <<
526
+ e.what() << "\n" << " Backtrace: not available");
527
+ return HTTP_INTERNAL_SERVER_ERROR;
528
+
529
+ } catch (...) {
530
+ P_ERROR("An unexpected, unknown error occured in mod_passenger.");
531
+ throw;
532
+ }
533
+ }
534
+
535
+ /**
536
+ * Convert an HTTP header name to a CGI environment name.
537
+ */
538
+ char *http2env(apr_pool_t *p, const char *name) {
539
+ char *env_name = apr_pstrcat(p, "HTTP_", name, NULL);
540
+ char *cp;
541
+
542
+ for (cp = env_name + 5; *cp != 0; cp++) {
543
+ if (*cp == '-') {
544
+ *cp = '_';
545
+ } else {
546
+ *cp = apr_toupper(*cp);
547
+ }
548
+ }
549
+
550
+ return env_name;
551
+ }
552
+
553
+ char *lookupName(apr_table_t *t, const char *name) {
554
+ const apr_array_header_t *hdrs_arr = apr_table_elts(t);
555
+ apr_table_entry_t *hdrs = (apr_table_entry_t *) hdrs_arr->elts;
556
+ int i;
557
+
558
+ for (i = 0; i < hdrs_arr->nelts; ++i) {
559
+ if (hdrs[i].key == NULL) {
560
+ continue;
561
+ }
562
+ if (strcasecmp(hdrs[i].key, name) == 0) {
563
+ return hdrs[i].val;
564
+ }
565
+ }
566
+ return NULL;
567
+ }
568
+
569
+ char *lookupHeader(request_rec *r, const char *name) {
570
+ return lookupName(r->headers_in, name);
571
+ }
572
+
573
+ char *lookupEnv(request_rec *r, const char *name) {
574
+ return lookupName(r->subprocess_env, name);
575
+ }
576
+
577
+ void inline addHeader(apr_table_t *table, const char *name, const char *value) {
578
+ if (name != NULL && value != NULL) {
579
+ apr_table_addn(table, name, value);
580
+ }
581
+ }
582
+
583
+ apr_status_t sendHeaders(request_rec *r, Application::SessionPtr &session, const char *baseURI) {
584
+ apr_table_t *headers;
585
+ headers = apr_table_make(r->pool, 40);
586
+ if (headers == NULL) {
587
+ return APR_ENOMEM;
588
+ }
589
+
590
+ // Set standard CGI variables.
591
+ addHeader(headers, "SERVER_SOFTWARE", ap_get_server_version());
592
+ addHeader(headers, "SERVER_PROTOCOL", r->protocol);
593
+ addHeader(headers, "SERVER_NAME", ap_get_server_name(r));
594
+ addHeader(headers, "SERVER_ADMIN", r->server->server_admin);
595
+ addHeader(headers, "SERVER_ADDR", r->connection->local_ip);
596
+ addHeader(headers, "SERVER_PORT", apr_psprintf(r->pool, "%u", ap_get_server_port(r)));
597
+ addHeader(headers, "REMOTE_ADDR", r->connection->remote_ip);
598
+ addHeader(headers, "REMOTE_PORT", apr_psprintf(r->pool, "%d", r->connection->remote_addr->port));
599
+ addHeader(headers, "REMOTE_USER", r->user);
600
+ addHeader(headers, "REQUEST_METHOD", r->method);
601
+ addHeader(headers, "REQUEST_URI", r->unparsed_uri);
602
+ addHeader(headers, "QUERY_STRING", r->args ? r->args : "");
603
+ if (strcmp(baseURI, "/") != 0) {
604
+ addHeader(headers, "SCRIPT_NAME", baseURI);
605
+ }
606
+ addHeader(headers, "HTTPS", lookupEnv(r, "HTTPS"));
607
+ addHeader(headers, "CONTENT_TYPE", lookupHeader(r, "Content-type"));
608
+ addHeader(headers, "DOCUMENT_ROOT", ap_document_root(r));
609
+ addHeader(headers, "PATH_INFO", r->parsed_uri.path);
610
+
611
+ // Set HTTP headers.
612
+ const apr_array_header_t *hdrs_arr;
613
+ apr_table_entry_t *hdrs;
614
+ int i;
615
+
616
+ hdrs_arr = apr_table_elts(r->headers_in);
617
+ hdrs = (apr_table_entry_t *) hdrs_arr->elts;
618
+ for (i = 0; i < hdrs_arr->nelts; ++i) {
619
+ if (hdrs[i].key) {
620
+ addHeader(headers, http2env(r->pool, hdrs[i].key), hdrs[i].val);
621
+ }
622
+ }
623
+
624
+ // Add other environment variables.
625
+ const apr_array_header_t *env_arr;
626
+ apr_table_entry_t *env;
627
+
628
+ env_arr = apr_table_elts(r->subprocess_env);
629
+ env = (apr_table_entry_t*) env_arr->elts;
630
+ for (i = 0; i < env_arr->nelts; ++i) {
631
+ addHeader(headers, env[i].key, env[i].val);
632
+ }
633
+
634
+ // Now send the headers.
635
+ string buffer;
636
+
637
+ hdrs_arr = apr_table_elts(headers);
638
+ hdrs = (apr_table_entry_t*) hdrs_arr->elts;
639
+ buffer.reserve(1024 * 4);
640
+ for (i = 0; i < hdrs_arr->nelts; ++i) {
641
+ buffer.append(hdrs[i].key);
642
+ buffer.append(1, '\0');
643
+ buffer.append(hdrs[i].val);
644
+ buffer.append(1, '\0');
645
+ }
646
+
647
+ /*
648
+ * If the last header value is an empty string, then the buffer
649
+ * will end with "\0\0". For example, if 'SSLOptions +ExportCertData'
650
+ * is set, and there's no client certificate, and 'SSL_CLIENT_CERT'
651
+ * is the last header, then the buffer will end with:
652
+ *
653
+ * "SSL_CLIENT_CERT\0\0"
654
+ *
655
+ * The data in the buffer will be processed by the RequestHandler class,
656
+ * which is implemented in Ruby. But it uses Hash[*data.split("\0")] to
657
+ * unserialize the data. Unfortunately String#split will not transform
658
+ * the trailing "\0\0" into an empty string:
659
+ *
660
+ * "SSL_CLIENT_CERT\0\0".split("\0")
661
+ * # => desired result: ["SSL_CLIENT_CERT", ""]
662
+ * # => actual result: ["SSL_CLIENT_CERT"]
663
+ *
664
+ * When that happens, Hash[..] will raise an ArgumentError because
665
+ * data.split("\0") does not return an array with a length that is a
666
+ * multiple of 2.
667
+ *
668
+ * So here, we add a dummy header to prevent situations like that from
669
+ * happening.
670
+ */
671
+ buffer.append("_\0_\0", 4);
672
+
673
+ session->sendHeaders(buffer);
674
+ return APR_SUCCESS;
675
+ }
676
+
677
+ shared_ptr<TempFile> receiveRequestBody(request_rec *r) {
678
+ TRACE_POINT();
679
+ shared_ptr<TempFile> tempFile(new TempFile());
680
+ char buf[1024 * 32];
681
+ apr_off_t len;
682
+ size_t total_written = 0;
683
+
684
+ while ((len = ap_get_client_block(r, buf, sizeof(buf))) > 0) {
685
+ size_t written = 0;
686
+ do {
687
+ size_t ret = fwrite(buf, 1, len - written, tempFile->handle);
688
+ if (ret <= 0 || fflush(tempFile->handle) == EOF) {
689
+ int e = errno;
690
+ string message("An error occured while "
691
+ "buffering HTTP upload data to "
692
+ "a temporary file in ");
693
+ message.append(getTempDir());
694
+ if (e == ENOSPC) {
695
+ message.append(". Please make sure "
696
+ "that this directory has "
697
+ "enough disk space for "
698
+ "buffering file uploads, "
699
+ "or set the 'PassengerTempDir' "
700
+ "directive to a directory "
701
+ "that has enough disk space.");
702
+ throw RuntimeException(message);
703
+ } else {
704
+ throw SystemException(message, e);
705
+ }
706
+ }
707
+ written += ret;
708
+ } while (written < (size_t) len);
709
+ total_written += written;
710
+ }
711
+ if (len == -1) {
712
+ throw IOException("An error occurred while receiving HTTP upload data.");
713
+ }
714
+ if (ftell(tempFile->handle) != atol(lookupHeader(r, "Content-Length"))) {
715
+ throw IOException("The HTTP client sent incomplete upload data.");
716
+ }
717
+ return tempFile;
718
+ }
719
+
720
+ void sendRequestBody(request_rec *r, Application::SessionPtr &session, shared_ptr<TempFile> &uploadData) {
721
+ TRACE_POINT();
722
+ rewind(uploadData->handle);
723
+ P_DEBUG("File upload: Content-Length = " << lookupHeader(r, "Content-Length"));
724
+ while (!feof(uploadData->handle)) {
725
+ char buf[1024 * 32];
726
+ size_t size;
727
+
728
+ size = fread(buf, 1, sizeof(buf), uploadData->handle);
729
+
730
+ session->sendBodyBlock(buf, size);
731
+ }
732
+ }
733
+
734
+ void sendRequestBody(request_rec *r, Application::SessionPtr &session) {
735
+ char buf[1024 * 32];
736
+ apr_off_t len;
737
+
738
+ while ((len = ap_get_client_block(r, buf, sizeof(buf))) > 0) {
739
+ session->sendBodyBlock(buf, len);
740
+ }
741
+ if (len == -1) {
742
+ throw IOException("An error occurred while receiving HTTP upload data.");
743
+ }
744
+ }
745
+
746
+ public:
747
+ Hooks(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
748
+ passenger_config_merge_all_servers(pconf, s);
749
+ ServerConfig *config = getServerConfig(s);
750
+ Passenger::setLogLevel(config->logLevel);
751
+ m_hasModRewrite = UNKNOWN;
752
+ m_hasModDir = UNKNOWN;
753
+ m_hasModAutoIndex = UNKNOWN;
754
+ mstat = cached_multi_file_stat_new(1024);
755
+
756
+ P_DEBUG("Initializing Phusion Passenger...");
757
+ ap_add_version_component(pconf, "Phusion_Passenger/" PASSENGER_VERSION);
758
+
759
+ const char *ruby, *user;
760
+ string applicationPoolServerExe, spawnServer;
761
+
762
+ if (config->tempDir != NULL) {
763
+ setenv("TMPDIR", config->tempDir, 1);
764
+ } else {
765
+ unsetenv("TMPDIR");
766
+ }
767
+ /*
768
+ * As described in the comment in init_module, upon (re)starting
769
+ * Apache, the Hooks constructor is called twice. We unset
770
+ * PHUSION_PASSENGER_TMP before calling createPassengerTmpDir()
771
+ * because we want the temp directory's name to contain the PID
772
+ * of the process in which the Hooks constructor was called for
773
+ * the second time.
774
+ */
775
+ unsetenv("PHUSION_PASSENGER_TMP");
776
+ createPassengerTempDir();
777
+
778
+ ruby = (config->ruby != NULL) ? config->ruby : DEFAULT_RUBY_COMMAND;
779
+ if (config->userSwitching) {
780
+ user = "";
781
+ } else if (config->defaultUser != NULL) {
782
+ user = config->defaultUser;
783
+ } else {
784
+ user = "nobody";
785
+ }
786
+
787
+ if (config->root == NULL) {
788
+ throw ConfigurationException("The 'PassengerRoot' configuration option "
789
+ "is not specified. This option is required, so please specify it. "
790
+ "TIP: The correct value for this option was given to you by "
791
+ "'passenger-install-apache2-module'.");
792
+ }
793
+
794
+ spawnServer = findSpawnServer(config->root);
795
+ if (!fileExists(spawnServer.c_str())) {
796
+ string message("The Passenger spawn server script, '");
797
+ message.append(spawnServer);
798
+ message.append("', does not exist. Please check whether the 'PassengerRoot' "
799
+ "option is specified correctly.");
800
+ throw FileNotFoundException(message);
801
+ }
802
+ applicationPoolServerExe = findApplicationPoolServer(config->root);
803
+ if (!fileExists(applicationPoolServerExe.c_str())) {
804
+ string message("The Passenger application pool server, '");
805
+ message.append(applicationPoolServerExe);
806
+ message.append("', does not exist. Please check whether the 'PassengerRoot' "
807
+ "option is specified correctly.");
808
+ throw FileNotFoundException(message);
809
+ }
810
+
811
+ applicationPoolServer = ptr(
812
+ new ApplicationPoolServer(
813
+ applicationPoolServerExe, spawnServer, "",
814
+ ruby, user)
815
+ );
816
+
817
+ ApplicationPoolPtr pool(applicationPoolServer->connect());
818
+ pool->setMax(config->maxPoolSize);
819
+ pool->setMaxPerApp(config->maxInstancesPerApp);
820
+ pool->setMaxIdleTime(config->poolIdleTime);
821
+ }
822
+
823
+ ~Hooks() {
824
+ cached_multi_file_stat_free(mstat);
825
+ removeDirTree(getPassengerTempDir().c_str());
826
+ }
827
+
828
+ int prepareRequestWhenInHighPerformanceMode(request_rec *r) {
829
+ DirConfig *config = getDirConfig(r);
830
+ if (config->isEnabled() && config->highPerformanceMode()) {
831
+ if (prepareRequest(r, config, r->filename, true)) {
832
+ return OK;
833
+ } else {
834
+ return DECLINED;
835
+ }
836
+ } else {
837
+ return DECLINED;
838
+ }
839
+ }
840
+
841
+ /**
842
+ * This is the hook method for the map_to_storage hook. Apache's final map_to_storage hook
843
+ * method (defined in core.c) will do the following:
844
+ *
845
+ * If r->filename doesn't exist, then it will change the filename to the
846
+ * following form:
847
+ *
848
+ * A/B
849
+ *
850
+ * A is top-most directory that exists. B is the first filename piece that
851
+ * normally follows A. For example, suppose that a website's DocumentRoot
852
+ * is /website, on server http://test.com/. Suppose that there's also a
853
+ * directory /website/images.
854
+ *
855
+ * If we access: then r->filename will be:
856
+ * http://test.com/foo/bar /website/foo
857
+ * http://test.com/foo/bar/baz /website/foo
858
+ * http://test.com/images/foo/bar /website/images/foo
859
+ *
860
+ * We obviously don't want this to happen because it'll interfere with our page
861
+ * cache file search code. So here we save the original value of r->filename so
862
+ * that we can use it later.
863
+ */
864
+ int saveOriginalFilename(request_rec *r) {
865
+ apr_table_set(r->notes, "Phusion Passenger: original filename", r->filename);
866
+ return DECLINED;
867
+ }
868
+
869
+ int prepareRequestWhenNotInHighPerformanceMode(request_rec *r) {
870
+ DirConfig *config = getDirConfig(r);
871
+ if (config->isEnabled()) {
872
+ if (config->highPerformanceMode()) {
873
+ /* Preparations have already been done in the map_to_storage hook.
874
+ * Prevent other modules' fixups hooks from being run.
875
+ */
876
+ return OK;
877
+ } else {
878
+ // core.c's map_to_storage hook will transform the filename, as
879
+ // described by saveOriginalFilename(). Here we restore the
880
+ // original filename.
881
+ const char *filename = apr_table_get(r->notes, "Phusion Passenger: original filename");
882
+ if (filename == NULL) {
883
+ return DECLINED;
884
+ } else {
885
+ prepareRequest(r, config, filename);
886
+ return DECLINED;
887
+ }
888
+ }
889
+ } else {
890
+ return DECLINED;
891
+ }
892
+ }
893
+
894
+ /**
895
+ * The default .htaccess provided by on Rails on Rails (that is, before version 2.1.0)
896
+ * has the following mod_rewrite rules in it:
897
+ *
898
+ * RewriteEngine on
899
+ * RewriteRule ^$ index.html [QSA]
900
+ * RewriteRule ^([^.]+)$ $1.html [QSA]
901
+ * RewriteCond %{REQUEST_FILENAME} !-f
902
+ * RewriteRule ^(.*)$ dispatch.cgi [QSA,L]
903
+ *
904
+ * As a result, all requests that do not map to a filename will be redirected to
905
+ * dispatch.cgi (or dispatch.fcgi, if the user so specified). We don't want that
906
+ * to happen, so before mod_rewrite applies its rules, we save the current state.
907
+ * After mod_rewrite has applied its rules, undoRedirectionToDispatchCgi() will
908
+ * check whether mod_rewrite attempted to perform an internal redirection to
909
+ * dispatch.(f)cgi. If so, then it will revert the state to the way it was before
910
+ * mod_rewrite took place.
911
+ */
912
+ int saveStateBeforeRewriteRules(request_rec *r) {
913
+ RequestNote *note = getRequestNote(r);
914
+ if (note != 0 && hasModRewrite()) {
915
+ note->handlerBeforeModRewrite = r->handler;
916
+ note->filenameBeforeModRewrite = r->filename;
917
+ }
918
+ return DECLINED;
919
+ }
920
+
921
+ int undoRedirectionToDispatchCgi(request_rec *r) {
922
+ RequestNote *note = getRequestNote(r);
923
+ if (note == 0 || !hasModRewrite()) {
924
+ return DECLINED;
925
+ }
926
+
927
+ if (r->handler != NULL && strcmp(r->handler, "redirect-handler") == 0) {
928
+ // Check whether r->filename looks like "redirect:.../dispatch.(f)cgi"
929
+ size_t len = strlen(r->filename);
930
+ // 22 == strlen("redirect:/dispatch.cgi")
931
+ if (len >= 22 && memcmp(r->filename, "redirect:", 9) == 0
932
+ && (memcmp(r->filename + len - 13, "/dispatch.cgi", 13) == 0
933
+ || memcmp(r->filename + len - 14, "/dispatch.fcgi", 14) == 0)) {
934
+ if (note->filenameBeforeModRewrite != NULL) {
935
+ r->filename = note->filenameBeforeModRewrite;
936
+ r->canonical_filename = note->filenameBeforeModRewrite;
937
+ r->handler = note->handlerBeforeModRewrite;
938
+ }
939
+ }
940
+ }
941
+ return DECLINED;
942
+ }
943
+
944
+ /**
945
+ * mod_dir does the following:
946
+ * If r->filename is a directory, and the URI doesn't end with a slash,
947
+ * then it will redirect the browser to an URI with a slash. For example,
948
+ * if you go to http://foo.com/images, then it will redirect you to
949
+ * http://foo.com/images/.
950
+ *
951
+ * This behavior is undesired. Suppose that there is an ImagesController,
952
+ * and there's also a 'public/images' folder used for storing page cache
953
+ * files. Then we don't want mod_dir to perform the redirection.
954
+ *
955
+ * So in startBlockingModDir(), we temporarily change some fields in the
956
+ * request structure in order to block mod_dir. In endBlockingModDir() we
957
+ * revert those fields to their old value.
958
+ */
959
+ int startBlockingModDir(request_rec *r) {
960
+ RequestNote *note = getRequestNote(r);
961
+ if (note != 0 && hasModDir()) {
962
+ note->oldFileType = r->finfo.filetype;
963
+ r->finfo.filetype = APR_NOFILE;
964
+ }
965
+ return DECLINED;
966
+ }
967
+
968
+ int endBlockingModDir(request_rec *r) {
969
+ RequestNote *note = getRequestNote(r);
970
+ if (note != 0 && hasModDir()) {
971
+ r->finfo.filetype = note->oldFileType;
972
+ }
973
+ return DECLINED;
974
+ }
975
+
976
+ /**
977
+ * mod_autoindex will try to display a directory index for URIs that map to a directory.
978
+ * This is undesired because of page caching semantics. Suppose that a Rails application
979
+ * has an ImagesController which has page caching enabled, and thus also a 'public/images'
980
+ * directory. When the visitor visits /images we'll want the request to be forwarded to
981
+ * the Rails application, instead of displaying a directory index.
982
+ *
983
+ * So in this hook method, we temporarily change some fields in the request structure
984
+ * in order to block mod_autoindex. In endBlockingModAutoIndex(), we restore the request
985
+ * structure to its former state.
986
+ */
987
+ int startBlockingModAutoIndex(request_rec *r) {
988
+ RequestNote *note = getRequestNote(r);
989
+ if (note != 0 && hasModAutoIndex()) {
990
+ note->handlerBeforeModAutoIndex = r->handler;
991
+ r->handler = "";
992
+ }
993
+ return DECLINED;
994
+ }
995
+
996
+ int endBlockingModAutoIndex(request_rec *r) {
997
+ RequestNote *note = getRequestNote(r);
998
+ if (note != 0 && hasModAutoIndex()) {
999
+ r->handler = note->handlerBeforeModAutoIndex;
1000
+ }
1001
+ return DECLINED;
1002
+ }
1003
+
1004
+ int handleRequestWhenInHighPerformanceMode(request_rec *r) {
1005
+ DirConfig *config = getDirConfig(r);
1006
+ if (config->highPerformanceMode()) {
1007
+ return handleRequest(r);
1008
+ } else {
1009
+ return DECLINED;
1010
+ }
1011
+ }
1012
+
1013
+ int handleRequestWhenNotInHighPerformanceMode(request_rec *r) {
1014
+ DirConfig *config = getDirConfig(r);
1015
+ if (config->highPerformanceMode()) {
1016
+ return DECLINED;
1017
+ } else {
1018
+ return handleRequest(r);
1019
+ }
1020
+ }
1021
+ };
1022
+
1023
+
1024
+
1025
+ /******************************************************************
1026
+ * Below follows lightweight C wrappers around the C++ Hook class.
1027
+ ******************************************************************/
1028
+
1029
+ /**
1030
+ * @ingroup Hooks
1031
+ * @{
1032
+ */
1033
+
1034
+ static Hooks *hooks = NULL;
1035
+
1036
+ static apr_status_t
1037
+ destroy_hooks(void *arg) {
1038
+ try {
1039
+ this_thread::disable_interruption di;
1040
+ this_thread::disable_syscall_interruption dsi;
1041
+ P_DEBUG("Shutting down Phusion Passenger...");
1042
+ delete hooks;
1043
+ hooks = NULL;
1044
+ } catch (const thread_interrupted &) {
1045
+ // Ignore interruptions, we're shutting down anyway.
1046
+ P_TRACE(3, "A system call was interrupted during shutdown of mod_passenger.");
1047
+ } catch (const exception &e) {
1048
+ // Ignore other exceptions, we're shutting down anyway.
1049
+ P_TRACE(3, "Exception during shutdown of mod_passenger: " << e.what());
1050
+ }
1051
+ return APR_SUCCESS;
1052
+ }
1053
+
1054
+ static int
1055
+ init_module(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *s) {
1056
+ /*
1057
+ * HISTORICAL NOTE:
1058
+ *
1059
+ * The Apache initialization process has the following properties:
1060
+ *
1061
+ * 1. Apache on Unix calls the post_config hook twice, once before detach() and once
1062
+ * after. On Windows it never calls detach().
1063
+ * 2. When Apache is compiled to use DSO modules, the modules are unloaded between the
1064
+ * two post_config hook calls.
1065
+ * 3. On Unix, if the -X commandline option is given (the 'DEBUG' config is set),
1066
+ * detach() will not be called.
1067
+ *
1068
+ * Because of property #2, the post_config hook is called twice. We initially tried
1069
+ * to avoid this with all kinds of hacks and workarounds, but none of them are
1070
+ * universal, i.e. it works for some people but not for others. So we got rid of the
1071
+ * hacks, and now we always initialize in the post_config hook.
1072
+ */
1073
+ if (hooks != NULL) {
1074
+ P_DEBUG("Restarting Phusion Passenger....");
1075
+ delete hooks;
1076
+ hooks = NULL;
1077
+ }
1078
+ try {
1079
+ hooks = new Hooks(pconf, plog, ptemp, s);
1080
+ apr_pool_cleanup_register(pconf, NULL,
1081
+ destroy_hooks,
1082
+ apr_pool_cleanup_null);
1083
+ return OK;
1084
+
1085
+ } catch (const thread_interrupted &e) {
1086
+ P_TRACE(2, "A system call was interrupted during mod_passenger "
1087
+ "initialization. Apache might be restarting or shutting "
1088
+ "down. Backtrace:\n" << e.backtrace());
1089
+ return DECLINED;
1090
+
1091
+ } catch (const thread_resource_error &e) {
1092
+ struct rlimit lim;
1093
+ string pthread_threads_max;
1094
+
1095
+ lim.rlim_cur = 0;
1096
+ lim.rlim_max = 0;
1097
+
1098
+ /* Solaris does not define the RLIMIT_NPROC limit. Setting it to infinity... */
1099
+ #ifdef RLIMIT_NPROC
1100
+ getrlimit(RLIMIT_NPROC, &lim);
1101
+ #else
1102
+ lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
1103
+ #endif
1104
+
1105
+ #ifdef PTHREAD_THREADS_MAX
1106
+ pthread_threads_max = toString(PTHREAD_THREADS_MAX);
1107
+ #else
1108
+ pthread_threads_max = "unknown";
1109
+ #endif
1110
+
1111
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
1112
+ "*** Passenger could not be initialize because a "
1113
+ "threading resource could not be allocated or initialized. "
1114
+ "The error message is:");
1115
+ fprintf(stderr,
1116
+ " %s\n\n"
1117
+ "System settings:\n"
1118
+ " RLIMIT_NPROC: soft = %d, hard = %d\n"
1119
+ " PTHREAD_THREADS_MAX: %s\n"
1120
+ "\n",
1121
+ e.what(),
1122
+ (int) lim.rlim_cur, (int) lim.rlim_max,
1123
+ pthread_threads_max.c_str());
1124
+
1125
+ fprintf(stderr, "Output of 'uname -a' follows:\n");
1126
+ fflush(stderr);
1127
+ system("uname -a >&2");
1128
+
1129
+ fprintf(stderr, "\nOutput of 'ulimit -a' follows:\n");
1130
+ fflush(stderr);
1131
+ system("ulimit -a >&2");
1132
+
1133
+ return DECLINED;
1134
+
1135
+ } catch (const exception &e) {
1136
+ ap_log_error(APLOG_MARK, APLOG_ERR, 0, s,
1137
+ "*** Passenger could not be initialized because of this error: %s",
1138
+ e.what());
1139
+ hooks = NULL;
1140
+ return DECLINED;
1141
+ }
1142
+ }
1143
+
1144
+ #define DEFINE_REQUEST_HOOK(c_name, cpp_name) \
1145
+ static int c_name(request_rec *r) { \
1146
+ if (OXT_LIKELY(hooks != NULL)) { \
1147
+ return hooks->cpp_name(r); \
1148
+ } else { \
1149
+ return DECLINED; \
1150
+ } \
1151
+ }
1152
+
1153
+ DEFINE_REQUEST_HOOK(prepare_request_when_in_high_performance_mode, prepareRequestWhenInHighPerformanceMode)
1154
+ DEFINE_REQUEST_HOOK(save_original_filename, saveOriginalFilename)
1155
+ DEFINE_REQUEST_HOOK(prepare_request_when_not_in_high_performance_mode, prepareRequestWhenNotInHighPerformanceMode)
1156
+ DEFINE_REQUEST_HOOK(save_state_before_rewrite_rules, saveStateBeforeRewriteRules)
1157
+ DEFINE_REQUEST_HOOK(undo_redirection_to_dispatch_cgi, undoRedirectionToDispatchCgi)
1158
+ DEFINE_REQUEST_HOOK(start_blocking_mod_dir, startBlockingModDir)
1159
+ DEFINE_REQUEST_HOOK(end_blocking_mod_dir, endBlockingModDir)
1160
+ DEFINE_REQUEST_HOOK(start_blocking_mod_autoindex, startBlockingModAutoIndex)
1161
+ DEFINE_REQUEST_HOOK(end_blocking_mod_autoindex, endBlockingModAutoIndex)
1162
+ DEFINE_REQUEST_HOOK(handle_request_when_in_high_performance_mode, handleRequestWhenInHighPerformanceMode)
1163
+ DEFINE_REQUEST_HOOK(handle_request_when_not_in_high_performance_mode, handleRequestWhenNotInHighPerformanceMode)
1164
+
1165
+
1166
+ /**
1167
+ * Apache hook registration function.
1168
+ */
1169
+ void
1170
+ passenger_register_hooks(apr_pool_t *p) {
1171
+ static const char * const rewrite_module[] = { "mod_rewrite.c", NULL };
1172
+ static const char * const dir_module[] = { "mod_dir.c", NULL };
1173
+ static const char * const autoindex_module[] = { "mod_autoindex.c", NULL };
1174
+
1175
+ ap_hook_post_config(init_module, NULL, NULL, APR_HOOK_MIDDLE);
1176
+
1177
+ ap_hook_map_to_storage(prepare_request_when_in_high_performance_mode, NULL, NULL, APR_HOOK_FIRST);
1178
+ ap_hook_map_to_storage(save_original_filename, NULL, NULL, APR_HOOK_LAST);
1179
+
1180
+ ap_hook_fixups(prepare_request_when_not_in_high_performance_mode, NULL, rewrite_module, APR_HOOK_FIRST);
1181
+ ap_hook_fixups(save_state_before_rewrite_rules, NULL, rewrite_module, APR_HOOK_LAST);
1182
+ ap_hook_fixups(undo_redirection_to_dispatch_cgi, rewrite_module, NULL, APR_HOOK_FIRST);
1183
+ ap_hook_fixups(start_blocking_mod_dir, NULL, dir_module, APR_HOOK_MIDDLE);
1184
+ ap_hook_fixups(end_blocking_mod_dir, dir_module, NULL, APR_HOOK_MIDDLE);
1185
+
1186
+ ap_hook_handler(handle_request_when_in_high_performance_mode, NULL, NULL, APR_HOOK_FIRST);
1187
+ ap_hook_handler(start_blocking_mod_autoindex, NULL, autoindex_module, APR_HOOK_LAST);
1188
+ ap_hook_handler(end_blocking_mod_autoindex, autoindex_module, NULL, APR_HOOK_FIRST);
1189
+ ap_hook_handler(handle_request_when_not_in_high_performance_mode, NULL, NULL, APR_HOOK_LAST);
1190
+ }
1191
+
1192
+ /**
1193
+ * @}
1194
+ */
1195
+