passenger 3.0.0.pre4 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (175) hide show
  1. data/bin/passenger-install-apache2-module +6 -6
  2. data/doc/Users guide Apache.html +1 -1
  3. data/doc/Users guide Nginx.html +1 -1
  4. data/doc/Users guide Standalone.html +1 -1
  5. data/doc/cxxapi/Constants_8h_source.html +1 -1
  6. data/doc/cxxapi/MessageServer_8h_source.html +416 -410
  7. data/doc/rdoc/classes/ConditionVariable.html +215 -0
  8. data/doc/rdoc/classes/Exception.html +120 -0
  9. data/doc/rdoc/classes/GC.html +113 -0
  10. data/doc/rdoc/classes/IO.html +221 -0
  11. data/doc/rdoc/classes/PhusionPassenger.html +397 -0
  12. data/doc/rdoc/classes/PhusionPassenger/AbstractInstaller.html +180 -0
  13. data/doc/rdoc/classes/PhusionPassenger/AbstractRequestHandler.html +647 -0
  14. data/doc/rdoc/classes/PhusionPassenger/AbstractServer.html +654 -0
  15. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/InvalidPassword.html +92 -0
  16. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerAlreadyStarted.html +97 -0
  17. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerError.html +96 -0
  18. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerNotStarted.html +97 -0
  19. data/doc/rdoc/classes/PhusionPassenger/AbstractServer/UnknownMessage.html +96 -0
  20. data/doc/rdoc/classes/PhusionPassenger/AbstractServerCollection.html +619 -0
  21. data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +142 -0
  22. data/doc/rdoc/classes/PhusionPassenger/AdminTools/MemoryStats.html +368 -0
  23. data/doc/rdoc/classes/PhusionPassenger/AdminTools/MemoryStats/Process.html +231 -0
  24. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance.html +588 -0
  25. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/CorruptedDirectoryError.html +92 -0
  26. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/GenerationsAbsentError.html +92 -0
  27. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/Group.html +147 -0
  28. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/Process.html +279 -0
  29. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/RoleDeniedError.html +92 -0
  30. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/StaleDirectoryError.html +92 -0
  31. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/Stats.html +123 -0
  32. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ServerInstance/UnsupportedGenerationStructureVersionError.html +92 -0
  33. data/doc/rdoc/classes/PhusionPassenger/AnalyticsLogger.html +341 -0
  34. data/doc/rdoc/classes/PhusionPassenger/AnalyticsLogger/Log.html +294 -0
  35. data/doc/rdoc/classes/PhusionPassenger/AnalyticsLogger/SharedData.html +199 -0
  36. data/doc/rdoc/classes/PhusionPassenger/AppInitError.html +155 -0
  37. data/doc/rdoc/classes/PhusionPassenger/AppProcess.html +367 -0
  38. data/doc/rdoc/classes/PhusionPassenger/ClassicRails.html +95 -0
  39. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/ApplicationSpawner.html +351 -0
  40. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/ApplicationSpawner/Error.html +98 -0
  41. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/CGIFixed.html +200 -0
  42. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/FrameworkSpawner.html +410 -0
  43. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/FrameworkSpawner/Error.html +98 -0
  44. data/doc/rdoc/classes/PhusionPassenger/ClassicRails/RequestHandler.html +156 -0
  45. data/doc/rdoc/classes/PhusionPassenger/ClassicRailsExtensions.html +115 -0
  46. data/doc/rdoc/classes/PhusionPassenger/ClassicRailsExtensions/AnalyticsLogging.html +202 -0
  47. data/doc/rdoc/classes/PhusionPassenger/ConsoleTextTemplate.html +172 -0
  48. data/doc/rdoc/classes/PhusionPassenger/DebugLogging.html +273 -0
  49. data/doc/rdoc/classes/PhusionPassenger/FrameworkInitError.html +145 -0
  50. data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +162 -0
  51. data/doc/rdoc/classes/PhusionPassenger/InitializationError.html +141 -0
  52. data/doc/rdoc/classes/PhusionPassenger/InvalidPath.html +92 -0
  53. data/doc/rdoc/classes/PhusionPassenger/MessageChannel.html +673 -0
  54. data/doc/rdoc/classes/PhusionPassenger/MessageChannel/InvalidHashError.html +92 -0
  55. data/doc/rdoc/classes/PhusionPassenger/MessageClient.html +415 -0
  56. data/doc/rdoc/classes/PhusionPassenger/NativeSupportLoader.html +134 -0
  57. data/doc/rdoc/classes/PhusionPassenger/Packaging.html +129 -0
  58. data/doc/rdoc/classes/PhusionPassenger/PlatformInfo.html +1809 -0
  59. data/doc/rdoc/classes/PhusionPassenger/Plugin.html +237 -0
  60. data/doc/rdoc/classes/PhusionPassenger/Rack.html +91 -0
  61. data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner.html +312 -0
  62. data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner/Error.html +98 -0
  63. data/doc/rdoc/classes/PhusionPassenger/Rack/RequestHandler.html +218 -0
  64. data/doc/rdoc/classes/PhusionPassenger/Rails3Extensions.html +114 -0
  65. data/doc/rdoc/classes/PhusionPassenger/Rails3Extensions/AnalyticsLogging.html +256 -0
  66. data/doc/rdoc/classes/PhusionPassenger/Rails3Extensions/AnalyticsLogging/ACExtension.html +139 -0
  67. data/doc/rdoc/classes/PhusionPassenger/Rails3Extensions/AnalyticsLogging/ASBenchmarkableExtension.html +118 -0
  68. data/doc/rdoc/classes/PhusionPassenger/Rails3Extensions/AnalyticsLogging/ExceptionLogger.html +135 -0
  69. data/doc/rdoc/classes/PhusionPassenger/SpawnManager.html +378 -0
  70. data/doc/rdoc/classes/PhusionPassenger/Standalone.html +111 -0
  71. data/doc/rdoc/classes/PhusionPassenger/Standalone/AppFinder.html +252 -0
  72. data/doc/rdoc/classes/PhusionPassenger/Standalone/Command.html +161 -0
  73. data/doc/rdoc/classes/PhusionPassenger/Standalone/ConfigFile.html +368 -0
  74. data/doc/rdoc/classes/PhusionPassenger/Standalone/ConfigFile/DisallowedContextError.html +132 -0
  75. data/doc/rdoc/classes/PhusionPassenger/Standalone/HelpCommand.html +151 -0
  76. data/doc/rdoc/classes/PhusionPassenger/Standalone/Main.html +189 -0
  77. data/doc/rdoc/classes/PhusionPassenger/Standalone/PackageRuntimeCommand.html +177 -0
  78. data/doc/rdoc/classes/PhusionPassenger/Standalone/RuntimeInstaller.html +341 -0
  79. data/doc/rdoc/classes/PhusionPassenger/Standalone/StartCommand.html +203 -0
  80. data/doc/rdoc/classes/PhusionPassenger/Standalone/StatusCommand.html +156 -0
  81. data/doc/rdoc/classes/PhusionPassenger/Standalone/StopCommand.html +168 -0
  82. data/doc/rdoc/classes/PhusionPassenger/Standalone/Utils.html +86 -0
  83. data/doc/rdoc/classes/PhusionPassenger/Standalone/VersionCommand.html +135 -0
  84. data/doc/rdoc/classes/PhusionPassenger/UnknownError.html +125 -0
  85. data/doc/rdoc/classes/PhusionPassenger/Utils.html +1550 -0
  86. data/doc/rdoc/classes/PhusionPassenger/Utils/FileSystemWatcher.html +204 -0
  87. data/doc/rdoc/classes/PhusionPassenger/Utils/FileSystemWatcher/DirInfo.html +171 -0
  88. data/doc/rdoc/classes/PhusionPassenger/Utils/FileSystemWatcher/FileInfo.html +140 -0
  89. data/doc/rdoc/classes/PhusionPassenger/Utils/HostsFileParser.html +260 -0
  90. data/doc/rdoc/classes/PhusionPassenger/Utils/PseudoIO.html +169 -0
  91. data/doc/rdoc/classes/PhusionPassenger/Utils/RewindableInput.html +265 -0
  92. data/doc/rdoc/classes/PhusionPassenger/Utils/RewindableInput/Tempfile.html +120 -0
  93. data/doc/rdoc/classes/PhusionPassenger/Utils/UnseekableSocket.html +561 -0
  94. data/doc/rdoc/classes/PhusionPassenger/VersionNotFound.html +140 -0
  95. data/doc/rdoc/classes/PhusionPassenger/WSGI.html +89 -0
  96. data/doc/rdoc/classes/PhusionPassenger/WSGI/ApplicationSpawner.html +182 -0
  97. data/doc/rdoc/classes/Process.html +115 -0
  98. data/doc/rdoc/classes/Signal.html +139 -0
  99. data/doc/rdoc/created.rid +1 -0
  100. data/doc/rdoc/files/DEVELOPERS_TXT.html +276 -0
  101. data/doc/rdoc/files/README.html +157 -0
  102. data/doc/rdoc/files/lib/phusion_passenger/abstract_installer_rb.html +130 -0
  103. data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +135 -0
  104. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +126 -0
  105. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +128 -0
  106. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/memory_stats_rb.html +126 -0
  107. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/server_instance_rb.html +132 -0
  108. data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +122 -0
  109. data/doc/rdoc/files/lib/phusion_passenger/analytics_logger_rb.html +129 -0
  110. data/doc/rdoc/files/lib/phusion_passenger/app_process_rb.html +127 -0
  111. data/doc/rdoc/files/lib/phusion_passenger/classic_rails/application_spawner_rb.html +141 -0
  112. data/doc/rdoc/files/lib/phusion_passenger/classic_rails/cgi_fixed_rb.html +126 -0
  113. data/doc/rdoc/files/lib/phusion_passenger/classic_rails/framework_spawner_rb.html +146 -0
  114. data/doc/rdoc/files/lib/phusion_passenger/classic_rails/request_handler_rb.html +125 -0
  115. data/doc/rdoc/files/lib/phusion_passenger/classic_rails_extensions/init_rb.html +132 -0
  116. data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +126 -0
  117. data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +122 -0
  118. data/doc/rdoc/files/lib/phusion_passenger/debug_logging_rb.html +122 -0
  119. data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +147 -0
  120. data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +122 -0
  121. data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +127 -0
  122. data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +120 -0
  123. data/doc/rdoc/files/lib/phusion_passenger/message_client_rb.html +127 -0
  124. data/doc/rdoc/files/lib/phusion_passenger/native_support_rb.html +132 -0
  125. data/doc/rdoc/files/lib/phusion_passenger/packaging_rb.html +122 -0
  126. data/doc/rdoc/files/lib/phusion_passenger/platform_info/apache_rb.html +127 -0
  127. data/doc/rdoc/files/lib/phusion_passenger/platform_info/binary_compatibility_rb.html +129 -0
  128. data/doc/rdoc/files/lib/phusion_passenger/platform_info/compiler_rb.html +126 -0
  129. data/doc/rdoc/files/lib/phusion_passenger/platform_info/curl_rb.html +126 -0
  130. data/doc/rdoc/files/lib/phusion_passenger/platform_info/documentation_tools_rb.html +126 -0
  131. data/doc/rdoc/files/lib/phusion_passenger/platform_info/linux_rb.html +126 -0
  132. data/doc/rdoc/files/lib/phusion_passenger/platform_info/operating_system_rb.html +127 -0
  133. data/doc/rdoc/files/lib/phusion_passenger/platform_info/ruby_rb.html +128 -0
  134. data/doc/rdoc/files/lib/phusion_passenger/platform_info/zlib_rb.html +126 -0
  135. data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +122 -0
  136. data/doc/rdoc/files/lib/phusion_passenger/plugin_rb.html +127 -0
  137. data/doc/rdoc/files/lib/phusion_passenger/public_api_rb.html +127 -0
  138. data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +137 -0
  139. data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +125 -0
  140. data/doc/rdoc/files/lib/phusion_passenger/rails3_extensions/init_rb.html +127 -0
  141. data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +122 -0
  142. data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +160 -0
  143. data/doc/rdoc/files/lib/phusion_passenger/standalone/app_finder_rb.html +127 -0
  144. data/doc/rdoc/files/lib/phusion_passenger/standalone/command_rb.html +135 -0
  145. data/doc/rdoc/files/lib/phusion_passenger/standalone/config_file_rb.html +126 -0
  146. data/doc/rdoc/files/lib/phusion_passenger/standalone/help_command_rb.html +126 -0
  147. data/doc/rdoc/files/lib/phusion_passenger/standalone/main_rb.html +126 -0
  148. data/doc/rdoc/files/lib/phusion_passenger/standalone/package_runtime_command_rb.html +127 -0
  149. data/doc/rdoc/files/lib/phusion_passenger/standalone/runtime_installer_rb.html +133 -0
  150. data/doc/rdoc/files/lib/phusion_passenger/standalone/start_command_rb.html +136 -0
  151. data/doc/rdoc/files/lib/phusion_passenger/standalone/status_command_rb.html +126 -0
  152. data/doc/rdoc/files/lib/phusion_passenger/standalone/stop_command_rb.html +126 -0
  153. data/doc/rdoc/files/lib/phusion_passenger/standalone/utils_rb.html +126 -0
  154. data/doc/rdoc/files/lib/phusion_passenger/standalone/version_command_rb.html +127 -0
  155. data/doc/rdoc/files/lib/phusion_passenger/utils/file_system_watcher_rb.html +126 -0
  156. data/doc/rdoc/files/lib/phusion_passenger/utils/hosts_file_parser_rb.html +120 -0
  157. data/doc/rdoc/files/lib/phusion_passenger/utils/rewindable_input_rb.html +100 -0
  158. data/doc/rdoc/files/lib/phusion_passenger/utils/tmpdir_rb.html +122 -0
  159. data/doc/rdoc/files/lib/phusion_passenger/utils/unseekable_socket_rb.html +126 -0
  160. data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +179 -0
  161. data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +132 -0
  162. data/doc/rdoc/fr_class_index.html +138 -0
  163. data/doc/rdoc/fr_file_index.html +108 -0
  164. data/doc/rdoc/fr_method_index.html +430 -0
  165. data/doc/rdoc/index.html +26 -0
  166. data/doc/rdoc/rdoc-style.css +187 -0
  167. data/ext/apache2/HelperAgent.cpp +7 -1
  168. data/ext/common/Constants.h +1 -1
  169. data/ext/common/MessageServer.h +7 -1
  170. data/ext/nginx/StaticContentHandler.c +5 -13
  171. data/lib/phusion_passenger.rb +2 -2
  172. data/lib/phusion_passenger/standalone/start_command.rb +6 -6
  173. data/lib/phusion_passenger/templates/standalone/config.erb +2 -2
  174. metadata +168 -12
  175. data/ext/libev/config.h +0 -122
@@ -0,0 +1,125 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html>
6
+ <head>
7
+ <title>Class: PhusionPassenger::UnknownError</title>
8
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
10
+
11
+ <script language="JavaScript" type="text/javascript">
12
+ // <![CDATA[
13
+
14
+ function toggleSource( id )
15
+ {
16
+ var elem
17
+ var link
18
+
19
+ if( document.getElementById )
20
+ {
21
+ elem = document.getElementById( id )
22
+ link = document.getElementById( "l_" + id )
23
+ }
24
+ else if ( document.all )
25
+ {
26
+ elem = eval( "document.all." + id )
27
+ link = eval( "document.all.l_" + id )
28
+ }
29
+ else
30
+ return false;
31
+
32
+ if( elem.style.display == "block" )
33
+ {
34
+ elem.style.display = "none"
35
+ link.innerHTML = "show source"
36
+ }
37
+ else
38
+ {
39
+ elem.style.display = "block"
40
+ link.innerHTML = "hide source"
41
+ }
42
+ }
43
+
44
+ function openCode( url )
45
+ {
46
+ window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus();
47
+ }
48
+ // ]]>
49
+ </script>
50
+ </head>
51
+
52
+ <body>
53
+ <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
54
+ <td class="file-title"><span class="file-title-prefix">Class</span><br />PhusionPassenger::UnknownError</td>
55
+ <td align="right">
56
+ <table cellspacing="0" cellpadding="2">
57
+ <tr valign="top">
58
+ <td>In:</td>
59
+ <td>
60
+ <a href="../../files/lib/phusion_passenger/exceptions_rb.html">lib/phusion_passenger/exceptions.rb</a>
61
+ </td>
62
+ </tr>
63
+ <tr>
64
+ <td>Parent:</td>
65
+ <td>
66
+ StandardError
67
+ </td>
68
+ </tr>
69
+ </table>
70
+ </td>
71
+ </tr>
72
+ </table>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+ <div id="content">
77
+
78
+
79
+
80
+
81
+ <div class="sectiontitle">Methods</div>
82
+ <ul>
83
+ <li><a href="#M000380">new</a></li>
84
+ </ul>
85
+
86
+
87
+
88
+
89
+
90
+ <div class="sectiontitle">Attributes</div>
91
+ <table border='0' cellpadding='5'>
92
+ <tr valign='top'>
93
+ <td class='attr-rw'>
94
+ [RW]
95
+ </td>
96
+ <td class='attr-name'>real_class_name</td>
97
+ <td class='attr-desc'></td>
98
+ </tr>
99
+ </table>
100
+
101
+ <div class="sectiontitle">Public Class methods</div>
102
+ <div class="method">
103
+ <div class="title">
104
+ <a name="M000380"></a><b>new</b>(message, class_name, backtrace)
105
+ </div>
106
+ <div class="sourcecode">
107
+ <p class="source-link">[ <a href="javascript:toggleSource('M000380_source')" id="l_M000380_source">show source</a> ]</p>
108
+ <div id="M000380_source" class="dyn-source">
109
+ <pre>
110
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/exceptions.rb, line 93</span>
111
+ 93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">message</span>, <span class="ruby-identifier">class_name</span>, <span class="ruby-identifier">backtrace</span>)
112
+ 94: <span class="ruby-keyword kw">super</span>(<span class="ruby-node">&quot;#{message} (#{class_name})&quot;</span>)
113
+ 95: <span class="ruby-identifier">set_backtrace</span>(<span class="ruby-identifier">backtrace</span>)
114
+ 96: <span class="ruby-ivar">@real_class_name</span> = <span class="ruby-identifier">class_name</span>
115
+ 97: <span class="ruby-keyword kw">end</span>
116
+ </pre>
117
+ </div>
118
+ </div>
119
+ </div>
120
+ </div>
121
+
122
+ </div>
123
+
124
+ </body>
125
+ </html>
@@ -0,0 +1,1550 @@
1
+ <?xml version="1.0" encoding="iso-8859-1"?>
2
+ <!DOCTYPE html
3
+ PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
+ <html>
6
+ <head>
7
+ <title>Module: PhusionPassenger::Utils</title>
8
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9
+ <link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
10
+
11
+ <script language="JavaScript" type="text/javascript">
12
+ // <![CDATA[
13
+
14
+ function toggleSource( id )
15
+ {
16
+ var elem
17
+ var link
18
+
19
+ if( document.getElementById )
20
+ {
21
+ elem = document.getElementById( id )
22
+ link = document.getElementById( "l_" + id )
23
+ }
24
+ else if ( document.all )
25
+ {
26
+ elem = eval( "document.all." + id )
27
+ link = eval( "document.all.l_" + id )
28
+ }
29
+ else
30
+ return false;
31
+
32
+ if( elem.style.display == "block" )
33
+ {
34
+ elem.style.display = "none"
35
+ link.innerHTML = "show source"
36
+ }
37
+ else
38
+ {
39
+ elem.style.display = "block"
40
+ link.innerHTML = "hide source"
41
+ }
42
+ }
43
+
44
+ function openCode( url )
45
+ {
46
+ window.open( url, "SOURCE_CODE", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=480,width=750" ).focus();
47
+ }
48
+ // ]]>
49
+ </script>
50
+ </head>
51
+
52
+ <body>
53
+ <table width="100%" border='0' cellpadding='0' cellspacing='0' class='banner'><tr>
54
+ <td class="file-title"><span class="file-title-prefix">Module</span><br />PhusionPassenger::Utils</td>
55
+ <td align="right">
56
+ <table cellspacing="0" cellpadding="2">
57
+ <tr valign="top">
58
+ <td>In:</td>
59
+ <td>
60
+ <a href="../../files/lib/phusion_passenger/utils_rb.html">lib/phusion_passenger/utils.rb</a>
61
+ <a href="../../files/lib/phusion_passenger/utils/file_system_watcher_rb.html">lib/phusion_passenger/utils/file_system_watcher.rb</a>
62
+ <a href="../../files/lib/phusion_passenger/utils/hosts_file_parser_rb.html">lib/phusion_passenger/utils/hosts_file_parser.rb</a>
63
+ <a href="../../files/lib/phusion_passenger/utils/rewindable_input_rb.html">lib/phusion_passenger/utils/rewindable_input.rb</a>
64
+ <a href="../../files/lib/phusion_passenger/utils/tmpdir_rb.html">lib/phusion_passenger/utils/tmpdir.rb</a>
65
+ <a href="../../files/lib/phusion_passenger/utils/unseekable_socket_rb.html">lib/phusion_passenger/utils/unseekable_socket.rb</a>
66
+ </td>
67
+ </tr>
68
+ </table>
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ <!-- banner header -->
73
+
74
+ <div id="bodyContent">
75
+ <div id="content">
76
+
77
+ <div class="description"><p>
78
+ Utility functions.
79
+ </p>
80
+ </div>
81
+
82
+
83
+
84
+ <div class="sectiontitle">Methods</div>
85
+ <ul>
86
+ <li><a href="#M000210">after_handling_requests</a></li>
87
+ <li><a href="#M000208">after_loading_app_code</a></li>
88
+ <li><a href="#M000197">assert_valid_directory</a></li>
89
+ <li><a href="#M000198">assert_valid_file</a></li>
90
+ <li><a href="#M000200">assert_valid_groupname</a></li>
91
+ <li><a href="#M000199">assert_valid_username</a></li>
92
+ <li><a href="#M000207">at_exit</a></li>
93
+ <li><a href="#M000209">before_handling_requests</a></li>
94
+ <li><a href="#M000196">canonicalize_path</a></li>
95
+ <li><a href="#M000220">check_directory_tree_permissions</a></li>
96
+ <li><a href="#M000202">close_all_io_objects_for_fds</a></li>
97
+ <li><a href="#M000212">connect_to_server</a></li>
98
+ <li><a href="#M000201">generate_random_id</a></li>
99
+ <li><a href="#M000211">get_socket_address_type</a></li>
100
+ <li><a href="#M000221">global_backtrace_report</a></li>
101
+ <li><a href="#M000213">local_socket_address?</a></li>
102
+ <li><a href="#M000219">lower_privilege</a></li>
103
+ <li><a href="#M000218">lower_privilege_called</a></li>
104
+ <li><a href="#M000203">marshal_exception</a></li>
105
+ <li><a href="#M000226">new</a></li>
106
+ <li><a href="#M000227">opens_files?</a></li>
107
+ <li><a href="#M000229">passenger_tmpdir</a></li>
108
+ <li><a href="#M000228">passenger_tmpdir</a></li>
109
+ <li><a href="#M000230">passenger_tmpdir=</a></li>
110
+ <li><a href="#M000206">prepare_app_process</a></li>
111
+ <li><a href="#M000205">print_exception</a></li>
112
+ <li><a href="#M000195">private_class_method</a></li>
113
+ <li><a href="#M000215">process_is_alive?</a></li>
114
+ <li><a href="#M000216">report_app_init_status</a></li>
115
+ <li><a href="#M000214">safe_fork</a></li>
116
+ <li><a href="#M000223">sanitize_spawn_options</a></li>
117
+ <li><a href="#M000224">split_by_null_into_hash</a></li>
118
+ <li><a href="#M000225">split_by_null_into_hash</a></li>
119
+ <li><a href="#M000222">to_boolean</a></li>
120
+ <li><a href="#M000217">unmarshal_and_raise_errors</a></li>
121
+ <li><a href="#M000204">unmarshal_exception</a></li>
122
+ </ul>
123
+
124
+
125
+
126
+ <div class="sectiontitle">Classes and Modules</div>
127
+ Class <a href="Utils/FileSystemWatcher.html" class="link">PhusionPassenger::Utils::FileSystemWatcher</a><br />
128
+ Class <a href="Utils/HostsFileParser.html" class="link">PhusionPassenger::Utils::HostsFileParser</a><br />
129
+ Class <a href="Utils/PseudoIO.html" class="link">PhusionPassenger::Utils::PseudoIO</a><br />
130
+ Class <a href="Utils/RewindableInput.html" class="link">PhusionPassenger::Utils::RewindableInput</a><br />
131
+ Class <a href="Utils/UnseekableSocket.html" class="link">PhusionPassenger::Utils::UnseekableSocket</a><br />
132
+
133
+
134
+ <div class="sectiontitle">Constants</div>
135
+ <table border='0' cellpadding='5'>
136
+ <tr valign='top'>
137
+ <td class="attr-name">PADDING</td>
138
+ <td>=</td>
139
+ <td class="attr-value">&quot;_&quot;</td>
140
+ </tr>
141
+ <tr valign='top'>
142
+ <td class="attr-name">NULL</td>
143
+ <td>=</td>
144
+ <td class="attr-value">&quot;\0&quot;</td>
145
+ </tr>
146
+ <tr valign='top'>
147
+ <td class="attr-name">FileSystemWatcher</td>
148
+ <td>=</td>
149
+ <td class="attr-value">NativeSupport::FileSystemWatcher</td>
150
+ </tr>
151
+ </table>
152
+
153
+
154
+ <div class="sectiontitle">Public Class methods</div>
155
+ <div class="method">
156
+ <div class="title">
157
+ <a name="M000226"></a><b>new</b>(filenames, termination_pipe = nil)
158
+ </div>
159
+ <div class="sourcecode">
160
+ <p class="source-link">[ <a href="javascript:toggleSource('M000226_source')" id="l_M000226_source">show source</a> ]</p>
161
+ <div id="M000226_source" class="dyn-source">
162
+ <pre>
163
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils/file_system_watcher.rb, line 60</span>
164
+ 60: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">filenames</span>, <span class="ruby-identifier">termination_pipe</span> = <span class="ruby-keyword kw">nil</span>)
165
+ 61: <span class="ruby-comment cmt"># Default parameter values, type conversion and exception</span>
166
+ 62: <span class="ruby-comment cmt"># handling in C is too much of a pain.</span>
167
+ 63: <span class="ruby-identifier">filenames</span> = <span class="ruby-identifier">filenames</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">filename</span><span class="ruby-operator">|</span>
168
+ 64: <span class="ruby-identifier">filename</span>.<span class="ruby-identifier">to_s</span>
169
+ 65: <span class="ruby-keyword kw">end</span>
170
+ 66: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">_new</span>(<span class="ruby-identifier">filenames</span>, <span class="ruby-identifier">termination_pipe</span>)
171
+ 67: <span class="ruby-keyword kw">end</span>
172
+ </pre>
173
+ </div>
174
+ </div>
175
+ </div>
176
+ <div class="method">
177
+ <div class="title">
178
+ <a name="M000227"></a><b>opens_files?</b>()
179
+ </div>
180
+ <div class="sourcecode">
181
+ <p class="source-link">[ <a href="javascript:toggleSource('M000227_source')" id="l_M000227_source">show source</a> ]</p>
182
+ <div id="M000227_source" class="dyn-source">
183
+ <pre>
184
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils/file_system_watcher.rb, line 69</span>
185
+ 69: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">opens_files?</span>
186
+ 70: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
187
+ 71: <span class="ruby-keyword kw">end</span>
188
+ </pre>
189
+ </div>
190
+ </div>
191
+ </div>
192
+ <div class="sectiontitle">Protected Class methods</div>
193
+ <div class="method">
194
+ <div class="title">
195
+ <a name="M000218"></a><b>lower_privilege_called</b>()
196
+ </div>
197
+ <div class="description">
198
+ <p>
199
+ No-op, hook for unit tests.
200
+ </p>
201
+ </div>
202
+ <div class="sourcecode">
203
+ <p class="source-link">[ <a href="javascript:toggleSource('M000218_source')" id="l_M000218_source">show source</a> ]</p>
204
+ <div id="M000218_source" class="dyn-source">
205
+ <pre>
206
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 649</span>
207
+ 649: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">lower_privilege_called</span>
208
+ 650: <span class="ruby-keyword kw">end</span>
209
+ </pre>
210
+ </div>
211
+ </div>
212
+ </div>
213
+ <div class="method">
214
+ <div class="title">
215
+ <a name="M000229"></a><b>passenger_tmpdir</b>(create = true)
216
+ </div>
217
+ <div class="description">
218
+ <p>
219
+ Returns the directory in which to store Phusion Passenger-specific
220
+ temporary files. If <tt>create</tt> is true, then this method creates the
221
+ directory if it doesn&#8216;t exist.
222
+ </p>
223
+ </div>
224
+ <div class="sourcecode">
225
+ <p class="source-link">[ <a href="javascript:toggleSource('M000229_source')" id="l_M000229_source">show source</a> ]</p>
226
+ <div id="M000229_source" class="dyn-source">
227
+ <pre>
228
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils/tmpdir.rb, line 37</span>
229
+ 37: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">passenger_tmpdir</span>(<span class="ruby-identifier">create</span> = <span class="ruby-keyword kw">true</span>)
230
+ 38: <span class="ruby-identifier">dir</span> = <span class="ruby-ivar">@@passenger_tmpdir</span>
231
+ 39: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">empty?</span>
232
+ 40: <span class="ruby-identifier">tmpdir</span> = <span class="ruby-value str">&quot;/tmp&quot;</span>
233
+ 41: [<span class="ruby-value str">&quot;PASSENGER_TEMP_DIR&quot;</span>, <span class="ruby-value str">&quot;PASSENGER_TMPDIR&quot;</span>].<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">name</span><span class="ruby-operator">|</span>
234
+ 42: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">ENV</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-identifier">name</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-constant">ENV</span>[<span class="ruby-identifier">name</span>].<span class="ruby-identifier">empty?</span>
235
+ 43: <span class="ruby-identifier">tmpdir</span> = <span class="ruby-constant">ENV</span>[<span class="ruby-identifier">name</span>]
236
+ 44: <span class="ruby-keyword kw">break</span>
237
+ 45: <span class="ruby-keyword kw">end</span>
238
+ 46: <span class="ruby-keyword kw">end</span>
239
+ 47: <span class="ruby-identifier">dir</span> = <span class="ruby-node">&quot;#{tmpdir}/passenger.1.0.#{Process.pid}&quot;</span>
240
+ 48: <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">%r{//+}</span>, <span class="ruby-value str">'/'</span>)
241
+ 49: <span class="ruby-ivar">@@passenger_tmpdir</span> = <span class="ruby-identifier">dir</span>
242
+ 50: <span class="ruby-keyword kw">end</span>
243
+ 51: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">create</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-identifier">dir</span>)
244
+ 52: <span class="ruby-comment cmt"># This is a very minimal implementation of the subdirectory</span>
245
+ 53: <span class="ruby-comment cmt"># creation logic in ServerInstanceDir.h. This implementation</span>
246
+ 54: <span class="ruby-comment cmt"># is only meant to make the unit tests pass. For production</span>
247
+ 55: <span class="ruby-comment cmt"># systems one should pre-create the temp directory with</span>
248
+ 56: <span class="ruby-comment cmt"># ServerInstanceDir.h.</span>
249
+ 57: <span class="ruby-identifier">system</span>(<span class="ruby-value str">&quot;mkdir&quot;</span>, <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;-m&quot;</span>, <span class="ruby-value str">&quot;u=rwxs,g=rwx,o=rwx&quot;</span>, <span class="ruby-identifier">dir</span>)
250
+ 58: <span class="ruby-identifier">system</span>(<span class="ruby-value str">&quot;mkdir&quot;</span>, <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;-m&quot;</span>, <span class="ruby-value str">&quot;u=rwxs,g=rwx,o=rwx&quot;</span>, <span class="ruby-node">&quot;#{dir}/generation-0&quot;</span>)
251
+ 59: <span class="ruby-identifier">system</span>(<span class="ruby-value str">&quot;mkdir&quot;</span>, <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;-m&quot;</span>, <span class="ruby-value str">&quot;u=rwxs,g=rwx,o=rwx&quot;</span>, <span class="ruby-node">&quot;#{dir}/backends&quot;</span>)
252
+ 60: <span class="ruby-identifier">system</span>(<span class="ruby-value str">&quot;mkdir&quot;</span>, <span class="ruby-value str">&quot;-p&quot;</span>, <span class="ruby-value str">&quot;-m&quot;</span>, <span class="ruby-value str">&quot;u=rwxs,g=rwx,o=rwx&quot;</span>, <span class="ruby-node">&quot;#{dir}/spawn-server&quot;</span>)
253
+ 61: <span class="ruby-keyword kw">end</span>
254
+ 62: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">dir</span>
255
+ 63: <span class="ruby-keyword kw">end</span>
256
+ </pre>
257
+ </div>
258
+ </div>
259
+ </div>
260
+ <div class="method">
261
+ <div class="title">
262
+ <a name="M000230"></a><b>passenger_tmpdir=</b>(dir)
263
+ </div>
264
+ <div class="sourcecode">
265
+ <p class="source-link">[ <a href="javascript:toggleSource('M000230_source')" id="l_M000230_source">show source</a> ]</p>
266
+ <div id="M000230_source" class="dyn-source">
267
+ <pre>
268
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils/tmpdir.rb, line 65</span>
269
+ 65: <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">passenger_tmpdir=</span>(<span class="ruby-identifier">dir</span>)
270
+ 66: <span class="ruby-ivar">@@passenger_tmpdir</span> = <span class="ruby-identifier">dir</span>
271
+ 67: <span class="ruby-keyword kw">end</span>
272
+ </pre>
273
+ </div>
274
+ </div>
275
+ </div>
276
+ <div class="sectiontitle">Protected Instance methods</div>
277
+ <div class="method">
278
+ <div class="title">
279
+ <a name="M000210"></a><b>after_handling_requests</b>()
280
+ </div>
281
+ <div class="description">
282
+ <p>
283
+ To be called after the request handler main loop is exited. This function
284
+ will fire off necessary events perform necessary cleanup tasks.
285
+ </p>
286
+ </div>
287
+ <div class="sourcecode">
288
+ <p class="source-link">[ <a href="javascript:toggleSource('M000210_source')" id="l_M000210_source">show source</a> ]</p>
289
+ <div id="M000210_source" class="dyn-source">
290
+ <pre>
291
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 420</span>
292
+ 420: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_handling_requests</span>
293
+ 421: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">call_event</span>(<span class="ruby-identifier">:stopping_worker_process</span>)
294
+ 422: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">passenger_call_at_exit_blocks</span>
295
+ 423: <span class="ruby-keyword kw">end</span>
296
+ </pre>
297
+ </div>
298
+ </div>
299
+ </div>
300
+ <div class="method">
301
+ <div class="title">
302
+ <a name="M000208"></a><b>after_loading_app_code</b>(options)
303
+ </div>
304
+ <div class="description">
305
+ <p>
306
+ This method is to be called after loading the application code but before
307
+ forking a worker process.
308
+ </p>
309
+ </div>
310
+ <div class="sourcecode">
311
+ <p class="source-link">[ <a href="javascript:toggleSource('M000208_source')" id="l_M000208_source">show source</a> ]</p>
312
+ <div id="M000208_source" class="dyn-source">
313
+ <pre>
314
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 357</span>
315
+ 357: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">after_loading_app_code</span>(<span class="ruby-identifier">options</span>)
316
+ 358: <span class="ruby-comment cmt"># Even though prepare_app_process() restores the Phusion Passenger</span>
317
+ 359: <span class="ruby-comment cmt"># load path after setting up Bundler, the app itself might also</span>
318
+ 360: <span class="ruby-comment cmt"># remove Phusion Passenger from the load path for whatever reason,</span>
319
+ 361: <span class="ruby-comment cmt"># so here we restore the load path again.</span>
320
+ 362: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">LIBDIR</span>
321
+ 363: <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-constant">LIBDIR</span>)
322
+ 364: <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">uniq!</span>
323
+ 365: <span class="ruby-keyword kw">end</span>
324
+ 366:
325
+ 367: <span class="ruby-comment cmt"># Post-install framework extensions. Possibly preceded by a call to</span>
326
+ 368: <span class="ruby-comment cmt"># PhusionPassenger.install_framework_extensions!</span>
327
+ 369: <span class="ruby-identifier">require</span> <span class="ruby-value str">'rails/version'</span> <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Rails</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-keyword kw">defined?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span>)
328
+ 370: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">Rails</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">::</span><span class="ruby-constant">Rails</span><span class="ruby-operator">::</span><span class="ruby-constant">VERSION</span><span class="ruby-operator">::</span><span class="ruby-constant">MAJOR</span> <span class="ruby-operator">&lt;=</span> <span class="ruby-value">2</span>
329
+ 371: <span class="ruby-identifier">require</span> <span class="ruby-value str">'phusion_passenger/classic_rails_extensions/init'</span>
330
+ 372: <span class="ruby-constant">ClassicRailsExtensions</span>.<span class="ruby-identifier">init!</span>(<span class="ruby-identifier">options</span>)
331
+ 373: <span class="ruby-comment cmt"># Rails 3 extensions are installed by</span>
332
+ 374: <span class="ruby-comment cmt"># PhusionPassenger.install_framework_extensions!</span>
333
+ 375: <span class="ruby-keyword kw">end</span>
334
+ 376:
335
+ 377: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">_spawn_options</span> = <span class="ruby-keyword kw">nil</span>
336
+ 378: <span class="ruby-keyword kw">end</span>
337
+ </pre>
338
+ </div>
339
+ </div>
340
+ </div>
341
+ <div class="method">
342
+ <div class="title">
343
+ <a name="M000197"></a><b>assert_valid_directory</b>(path)
344
+ </div>
345
+ <div class="description">
346
+ <p>
347
+ Assert that <tt>path</tt> is a directory. Raises <tt><a
348
+ href="InvalidPath.html">InvalidPath</a></tt> if it isn&#8216;t.
349
+ </p>
350
+ </div>
351
+ <div class="sourcecode">
352
+ <p class="source-link">[ <a href="javascript:toggleSource('M000197_source')" id="l_M000197_source">show source</a> ]</p>
353
+ <div id="M000197_source" class="dyn-source">
354
+ <pre>
355
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 64</span>
356
+ 64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_valid_directory</span>(<span class="ruby-identifier">path</span>)
357
+ 65: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">directory?</span>(<span class="ruby-identifier">path</span>)
358
+ 66: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPath</span>, <span class="ruby-node">&quot;'#{path}' is not a valid directory.&quot;</span>
359
+ 67: <span class="ruby-keyword kw">end</span>
360
+ 68: <span class="ruby-keyword kw">end</span>
361
+ </pre>
362
+ </div>
363
+ </div>
364
+ </div>
365
+ <div class="method">
366
+ <div class="title">
367
+ <a name="M000198"></a><b>assert_valid_file</b>(path)
368
+ </div>
369
+ <div class="description">
370
+ <p>
371
+ Assert that <tt>path</tt> is a file. Raises <tt><a
372
+ href="InvalidPath.html">InvalidPath</a></tt> if it isn&#8216;t.
373
+ </p>
374
+ </div>
375
+ <div class="sourcecode">
376
+ <p class="source-link">[ <a href="javascript:toggleSource('M000198_source')" id="l_M000198_source">show source</a> ]</p>
377
+ <div id="M000198_source" class="dyn-source">
378
+ <pre>
379
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 71</span>
380
+ 71: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_valid_file</span>(<span class="ruby-identifier">path</span>)
381
+ 72: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">File</span>.<span class="ruby-identifier">file?</span>(<span class="ruby-identifier">path</span>)
382
+ 73: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidPath</span>, <span class="ruby-node">&quot;'#{path}' is not a valid file.&quot;</span>
383
+ 74: <span class="ruby-keyword kw">end</span>
384
+ 75: <span class="ruby-keyword kw">end</span>
385
+ </pre>
386
+ </div>
387
+ </div>
388
+ </div>
389
+ <div class="method">
390
+ <div class="title">
391
+ <a name="M000200"></a><b>assert_valid_groupname</b>(groupname)
392
+ </div>
393
+ <div class="description">
394
+ <p>
395
+ Assert that <tt>groupname</tt> is a valid group name. Raises ArgumentError
396
+ if that is not the case.
397
+ </p>
398
+ </div>
399
+ <div class="sourcecode">
400
+ <p class="source-link">[ <a href="javascript:toggleSource('M000200_source')" id="l_M000200_source">show source</a> ]</p>
401
+ <div id="M000200_source" class="dyn-source">
402
+ <pre>
403
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 86</span>
404
+ 86: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_valid_groupname</span>(<span class="ruby-identifier">groupname</span>)
405
+ 87: <span class="ruby-comment cmt"># If groupname does not exist then getgrnam() will raise an ArgumentError.</span>
406
+ 88: <span class="ruby-identifier">groupname</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrnam</span>(<span class="ruby-identifier">groupname</span>)
407
+ 89: <span class="ruby-keyword kw">end</span>
408
+ </pre>
409
+ </div>
410
+ </div>
411
+ </div>
412
+ <div class="method">
413
+ <div class="title">
414
+ <a name="M000199"></a><b>assert_valid_username</b>(username)
415
+ </div>
416
+ <div class="description">
417
+ <p>
418
+ Assert that <tt>username</tt> is a valid username. Raises ArgumentError if
419
+ that is not the case.
420
+ </p>
421
+ </div>
422
+ <div class="sourcecode">
423
+ <p class="source-link">[ <a href="javascript:toggleSource('M000199_source')" id="l_M000199_source">show source</a> ]</p>
424
+ <div id="M000199_source" class="dyn-source">
425
+ <pre>
426
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 79</span>
427
+ 79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">assert_valid_username</span>(<span class="ruby-identifier">username</span>)
428
+ 80: <span class="ruby-comment cmt"># If username does not exist then getpwnam() will raise an ArgumentError.</span>
429
+ 81: <span class="ruby-identifier">username</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-identifier">username</span>)
430
+ 82: <span class="ruby-keyword kw">end</span>
431
+ </pre>
432
+ </div>
433
+ </div>
434
+ </div>
435
+ <div class="method">
436
+ <div class="title">
437
+ <a name="M000207"></a><b>at_exit</b>(&amp;block)
438
+ </div>
439
+ <div class="sourcecode">
440
+ <p class="source-link">[ <a href="javascript:toggleSource('M000207_source')" id="l_M000207_source">show source</a> ]</p>
441
+ <div id="M000207_source" class="dyn-source">
442
+ <pre>
443
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 267</span>
444
+ 267: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">at_exit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
445
+ 268: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">passenger_at_exit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
446
+ 269: <span class="ruby-keyword kw">end</span>
447
+ </pre>
448
+ </div>
449
+ </div>
450
+ </div>
451
+ <div class="method">
452
+ <div class="title">
453
+ <a name="M000209"></a><b>before_handling_requests</b>(forked, options)
454
+ </div>
455
+ <div class="description">
456
+ <p>
457
+ To be called before the request handler main loop is entered, but after the
458
+ app startup file has been loaded. This function will fire off necessary
459
+ events and perform necessary preparation tasks.
460
+ </p>
461
+ <p>
462
+ <tt>forked</tt> indicates whether the current worker process is forked off
463
+ from an ApplicationSpawner that has preloaded the app code.
464
+ <tt>options</tt> are the spawn options that were passed.
465
+ </p>
466
+ </div>
467
+ <div class="sourcecode">
468
+ <p class="source-link">[ <a href="javascript:toggleSource('M000209_source')" id="l_M000209_source">show source</a> ]</p>
469
+ <div id="M000209_source" class="dyn-source">
470
+ <pre>
471
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 387</span>
472
+ 387: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">before_handling_requests</span>(<span class="ruby-identifier">forked</span>, <span class="ruby-identifier">options</span>)
473
+ 388: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">forked</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;analytics_logger&quot;</span>]
474
+ 389: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;analytics_logger&quot;</span>].<span class="ruby-identifier">clear_connection</span>
475
+ 390: <span class="ruby-keyword kw">end</span>
476
+ 391:
477
+ 392: <span class="ruby-comment cmt"># If we were forked from a preloader process then clear or</span>
478
+ 393: <span class="ruby-comment cmt"># re-establish ActiveRecord database connections. This prevents</span>
479
+ 394: <span class="ruby-comment cmt"># child processes from concurrently accessing the same</span>
480
+ 395: <span class="ruby-comment cmt"># database connection handles.</span>
481
+ 396: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">forked</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>)
482
+ 397: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:clear_all_connections!</span>)
483
+ 398: <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">clear_all_connections!</span>
484
+ 399: <span class="ruby-keyword kw">elsif</span> <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:clear_active_connections!</span>)
485
+ 400: <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">clear_active_connections!</span>
486
+ 401: <span class="ruby-keyword kw">elsif</span> <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:connected?</span>) <span class="ruby-operator">&amp;&amp;</span>
487
+ 402: <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">connected?</span>
488
+ 403: <span class="ruby-operator">::</span><span class="ruby-constant">ActiveRecord</span><span class="ruby-operator">::</span><span class="ruby-constant">Base</span>.<span class="ruby-identifier">establish_connection</span>
489
+ 404: <span class="ruby-keyword kw">end</span>
490
+ 405: <span class="ruby-keyword kw">end</span>
491
+ 406:
492
+ 407: <span class="ruby-comment cmt"># Fire off events.</span>
493
+ 408: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">call_event</span>(<span class="ruby-identifier">:starting_worker_process</span>, <span class="ruby-identifier">forked</span>)
494
+ 409: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;pool_account_username&quot;</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;pool_account_password_base64&quot;</span>]
495
+ 410: <span class="ruby-identifier">password</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;pool_account_password_base64&quot;</span>].<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'m'</span>).<span class="ruby-identifier">first</span>
496
+ 411: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">call_event</span>(<span class="ruby-identifier">:credentials</span>,
497
+ 412: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;pool_account_username&quot;</span>], <span class="ruby-identifier">password</span>)
498
+ 413: <span class="ruby-keyword kw">else</span>
499
+ 414: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">call_event</span>(<span class="ruby-identifier">:credentials</span>, <span class="ruby-keyword kw">nil</span>, <span class="ruby-keyword kw">nil</span>)
500
+ 415: <span class="ruby-keyword kw">end</span>
501
+ 416: <span class="ruby-keyword kw">end</span>
502
+ </pre>
503
+ </div>
504
+ </div>
505
+ </div>
506
+ <div class="method">
507
+ <div class="title">
508
+ <a name="M000196"></a><b>canonicalize_path</b>(path)
509
+ </div>
510
+ <div class="description">
511
+ <p>
512
+ Return the canonicalized version of <tt>path</tt>. This path is guaranteed
513
+ to to be &quot;normal&quot;, i.e. it doesn&#8216;t contain stuff like
514
+ &quot;..&quot; or &quot;/&quot;, and it fully resolves symbolic links.
515
+ </p>
516
+ <p>
517
+ Raises SystemCallError if something went wrong. Raises ArgumentError if
518
+ <tt>path</tt> is nil. Raises <a href="InvalidPath.html">InvalidPath</a> if
519
+ <tt>path</tt> does not appear to be a valid path.
520
+ </p>
521
+ </div>
522
+ <div class="sourcecode">
523
+ <p class="source-link">[ <a href="javascript:toggleSource('M000196_source')" id="l_M000196_source">show source</a> ]</p>
524
+ <div id="M000196_source" class="dyn-source">
525
+ <pre>
526
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 56</span>
527
+ 56: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">canonicalize_path</span>(<span class="ruby-identifier">path</span>)
528
+ 57: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-value str">&quot;The 'path' argument may not be nil&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span>.<span class="ruby-identifier">nil?</span>
529
+ 58: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Pathname</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>).<span class="ruby-identifier">realpath</span>.<span class="ruby-identifier">to_s</span>
530
+ 59: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
531
+ 60: <span class="ruby-identifier">raise</span> <span class="ruby-constant">InvalidAPath</span>, <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
532
+ 61: <span class="ruby-keyword kw">end</span>
533
+ </pre>
534
+ </div>
535
+ </div>
536
+ </div>
537
+ <div class="method">
538
+ <div class="title">
539
+ <a name="M000220"></a><b>check_directory_tree_permissions</b>(dir)
540
+ </div>
541
+ <div class="description">
542
+ <p>
543
+ Checks the permissions of all parent directories of <tt>dir</tt> as well as
544
+ <tt>dir</tt> itself.
545
+ </p>
546
+ <p>
547
+ <tt>dir</tt> must be a canonical path.
548
+ </p>
549
+ <p>
550
+ If one of the parent directories has wrong permissions, causing
551
+ <tt>dir</tt> to be inaccessible by the current process, then this function
552
+ returns [path, true] where <tt>path</tt> is the path of the top-most
553
+ directory with wrong permissions.
554
+ </p>
555
+ <p>
556
+ If <tt>dir</tt> itself is not executable by the current process then this
557
+ function returns [dir, false].
558
+ </p>
559
+ <p>
560
+ Otherwise, nil is returned.
561
+ </p>
562
+ </div>
563
+ <div class="sourcecode">
564
+ <p class="source-link">[ <a href="javascript:toggleSource('M000220_source')" id="l_M000220_source">show source</a> ]</p>
565
+ <div id="M000220_source" class="dyn-source">
566
+ <pre>
567
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 749</span>
568
+ 749: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">check_directory_tree_permissions</span>(<span class="ruby-identifier">dir</span>)
569
+ 750: <span class="ruby-identifier">components</span> = <span class="ruby-identifier">dir</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;/&quot;</span>)
570
+ 751: <span class="ruby-identifier">components</span>.<span class="ruby-identifier">shift</span>
571
+ 752: <span class="ruby-identifier">i</span> = <span class="ruby-value">0</span>
572
+ 753: <span class="ruby-comment cmt"># We can't use File.readable() and friends here because they</span>
573
+ 754: <span class="ruby-comment cmt"># don't always work right with ACLs. Instead of we use 'real'</span>
574
+ 755: <span class="ruby-comment cmt"># checks.</span>
575
+ 756: <span class="ruby-keyword kw">while</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">&lt;</span> <span class="ruby-identifier">components</span>.<span class="ruby-identifier">size</span>
576
+ 757: <span class="ruby-identifier">path</span> = <span class="ruby-value str">&quot;/&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">components</span>[<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-identifier">i</span>].<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;/&quot;</span>)
577
+ 758: <span class="ruby-keyword kw">begin</span>
578
+ 759: <span class="ruby-constant">File</span>.<span class="ruby-identifier">stat</span>(<span class="ruby-identifier">path</span>)
579
+ 760: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EACCES</span>
580
+ 761: <span class="ruby-keyword kw">return</span> [<span class="ruby-constant">File</span>.<span class="ruby-identifier">dirname</span>(<span class="ruby-identifier">path</span>), <span class="ruby-keyword kw">true</span>]
581
+ 762: <span class="ruby-keyword kw">end</span>
582
+ 763: <span class="ruby-identifier">i</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span>
583
+ 764: <span class="ruby-keyword kw">end</span>
584
+ 765: <span class="ruby-keyword kw">begin</span>
585
+ 766: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>(<span class="ruby-identifier">dir</span>) <span class="ruby-keyword kw">do</span>
586
+ 767: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">nil</span>
587
+ 768: <span class="ruby-keyword kw">end</span>
588
+ 769: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">EACCES</span>
589
+ 770: <span class="ruby-keyword kw">return</span> [<span class="ruby-identifier">dir</span>, <span class="ruby-keyword kw">false</span>]
590
+ 771: <span class="ruby-keyword kw">end</span>
591
+ 772: <span class="ruby-keyword kw">end</span>
592
+ </pre>
593
+ </div>
594
+ </div>
595
+ </div>
596
+ <div class="method">
597
+ <div class="title">
598
+ <a name="M000202"></a><b>close_all_io_objects_for_fds</b>(file_descriptors_to_leave_open)
599
+ </div>
600
+ <div class="sourcecode">
601
+ <p class="source-link">[ <a href="javascript:toggleSource('M000202_source')" id="l_M000202_source">show source</a> ]</p>
602
+ <div id="M000202_source" class="dyn-source">
603
+ <pre>
604
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 109</span>
605
+ 109: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">close_all_io_objects_for_fds</span>(<span class="ruby-identifier">file_descriptors_to_leave_open</span>)
606
+ 110: <span class="ruby-constant">ObjectSpace</span>.<span class="ruby-identifier">each_object</span>(<span class="ruby-constant">IO</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">io</span><span class="ruby-operator">|</span>
607
+ 111: <span class="ruby-keyword kw">begin</span>
608
+ 112: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">file_descriptors_to_leave_open</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">io</span>.<span class="ruby-identifier">fileno</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">io</span>.<span class="ruby-identifier">closed?</span>
609
+ 113: <span class="ruby-identifier">io</span>.<span class="ruby-identifier">close</span>
610
+ 114: <span class="ruby-keyword kw">end</span>
611
+ 115: <span class="ruby-keyword kw">rescue</span>
612
+ 116: <span class="ruby-keyword kw">end</span>
613
+ 117: <span class="ruby-keyword kw">end</span>
614
+ 118: <span class="ruby-keyword kw">end</span>
615
+ </pre>
616
+ </div>
617
+ </div>
618
+ </div>
619
+ <div class="method">
620
+ <div class="title">
621
+ <a name="M000212"></a><b>connect_to_server</b>(address)
622
+ </div>
623
+ <div class="sourcecode">
624
+ <p class="source-link">[ <a href="javascript:toggleSource('M000212_source')" id="l_M000212_source">show source</a> ]</p>
625
+ <div id="M000212_source" class="dyn-source">
626
+ <pre>
627
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 435</span>
628
+ 435: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">connect_to_server</span>(<span class="ruby-identifier">address</span>)
629
+ 436: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">get_socket_address_type</span>(<span class="ruby-identifier">address</span>)
630
+ 437: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:unix</span>
631
+ 438: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">UNIXSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">address</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">/^unix:/</span>, <span class="ruby-value str">''</span>))
632
+ 439: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:tcp</span>
633
+ 440: <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span> = <span class="ruby-identifier">address</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">%r{^tcp://}</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">':'</span>, <span class="ruby-value">2</span>)
634
+ 441: <span class="ruby-identifier">port</span> = <span class="ruby-identifier">port</span>.<span class="ruby-identifier">to_i</span>
635
+ 442: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">TCPSocket</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span>)
636
+ 443: <span class="ruby-keyword kw">else</span>
637
+ 444: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Unknown socket address type for '#{address}'.&quot;</span>
638
+ 445: <span class="ruby-keyword kw">end</span>
639
+ 446: <span class="ruby-keyword kw">end</span>
640
+ </pre>
641
+ </div>
642
+ </div>
643
+ </div>
644
+ <div class="method">
645
+ <div class="title">
646
+ <a name="M000201"></a><b>generate_random_id</b>(method)
647
+ </div>
648
+ <div class="description">
649
+ <p>
650
+ Generate a long, cryptographically secure random ID string, which is also a
651
+ valid filename.
652
+ </p>
653
+ </div>
654
+ <div class="sourcecode">
655
+ <p class="source-link">[ <a href="javascript:toggleSource('M000201_source')" id="l_M000201_source">show source</a> ]</p>
656
+ <div id="M000201_source" class="dyn-source">
657
+ <pre>
658
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 93</span>
659
+ 93: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">generate_random_id</span>(<span class="ruby-identifier">method</span>)
660
+ 94: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">method</span>
661
+ 95: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:base64</span>
662
+ 96: <span class="ruby-identifier">data</span> = [<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-value str">&quot;/dev/urandom&quot;</span>, <span class="ruby-value">64</span>)].<span class="ruby-identifier">pack</span>(<span class="ruby-value str">'m'</span>)
663
+ 97: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">&quot;\n&quot;</span>, <span class="ruby-value str">''</span>)
664
+ 98: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">&quot;+&quot;</span>, <span class="ruby-value str">''</span>)
665
+ 99: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-value str">&quot;/&quot;</span>, <span class="ruby-value str">''</span>)
666
+ 100: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">gsub!</span>(<span class="ruby-regexp re">/==$/</span>, <span class="ruby-value str">''</span>)
667
+ 101: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">data</span>
668
+ 102: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:hex</span>
669
+ 103: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-value str">&quot;/dev/urandom&quot;</span>, <span class="ruby-value">64</span>).<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">'H*'</span>)[<span class="ruby-value">0</span>]
670
+ 104: <span class="ruby-keyword kw">else</span>
671
+ 105: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Invalid method #{method.inspect}&quot;</span>
672
+ 106: <span class="ruby-keyword kw">end</span>
673
+ 107: <span class="ruby-keyword kw">end</span>
674
+ </pre>
675
+ </div>
676
+ </div>
677
+ </div>
678
+ <div class="method">
679
+ <div class="title">
680
+ <a name="M000211"></a><b>get_socket_address_type</b>(address)
681
+ </div>
682
+ <div class="sourcecode">
683
+ <p class="source-link">[ <a href="javascript:toggleSource('M000211_source')" id="l_M000211_source">show source</a> ]</p>
684
+ <div id="M000211_source" class="dyn-source">
685
+ <pre>
686
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 425</span>
687
+ 425: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">get_socket_address_type</span>(<span class="ruby-identifier">address</span>)
688
+ 426: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">address</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%r{^unix:.}</span>
689
+ 427: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">:unix</span>
690
+ 428: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">address</span> <span class="ruby-operator">=~</span> <span class="ruby-regexp re">%r{^tcp://.}</span>
691
+ 429: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">:tcp</span>
692
+ 430: <span class="ruby-keyword kw">else</span>
693
+ 431: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">:unknown</span>
694
+ 432: <span class="ruby-keyword kw">end</span>
695
+ 433: <span class="ruby-keyword kw">end</span>
696
+ </pre>
697
+ </div>
698
+ </div>
699
+ </div>
700
+ <div class="method">
701
+ <div class="title">
702
+ <a name="M000221"></a><b>global_backtrace_report</b>()
703
+ </div>
704
+ <div class="description">
705
+ <p>
706
+ Returns a string which reports the backtraces for all threads, or if
707
+ that&#8216;s not supported the backtrace for the current thread.
708
+ </p>
709
+ </div>
710
+ <div class="sourcecode">
711
+ <p class="source-link">[ <a href="javascript:toggleSource('M000221_source')" id="l_M000221_source">show source</a> ]</p>
712
+ <div id="M000221_source" class="dyn-source">
713
+ <pre>
714
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 776</span>
715
+ 776: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">global_backtrace_report</span>
716
+ 777: <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:caller_for_all_threads</span>)
717
+ 778: <span class="ruby-identifier">output</span> = <span class="ruby-node">&quot;========== Process #{Process.pid}: backtrace dump ==========\n&quot;</span>
718
+ 779: <span class="ruby-identifier">caller_for_all_threads</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">thread</span>, <span class="ruby-identifier">stack</span><span class="ruby-operator">|</span>
719
+ 780: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
720
+ 781: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;# Thread: #{thread.inspect}, &quot;</span>
721
+ 782: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">thread</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">main</span>
722
+ 783: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;[main thread], &quot;</span>
723
+ 784: <span class="ruby-keyword kw">end</span>
724
+ 785: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">thread</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>
725
+ 786: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;[current thread], &quot;</span>
726
+ 787: <span class="ruby-keyword kw">end</span>
727
+ 788: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;alive = #{thread.alive?}\n&quot;</span>
728
+ 789: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
729
+ 790: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">stack</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n &quot;</span>)
730
+ 791: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n\n&quot;</span>
731
+ 792: <span class="ruby-keyword kw">end</span>
732
+ 793: <span class="ruby-keyword kw">else</span>
733
+ 794: <span class="ruby-identifier">output</span> = <span class="ruby-node">&quot;========== Process #{Process.pid}: backtrace dump ==========\n&quot;</span>
734
+ 795: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
735
+ 796: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;# Current thread: #{Thread.current.inspect}\n&quot;</span>
736
+ 797: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> (<span class="ruby-value str">&quot;-&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-value">60</span>) <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;\n&quot;</span>
737
+ 798: <span class="ruby-identifier">output</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot; &quot;</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">caller</span>.<span class="ruby-identifier">join</span>(<span class="ruby-value str">&quot;\n &quot;</span>)
738
+ 799: <span class="ruby-keyword kw">end</span>
739
+ 800: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">output</span>
740
+ 801: <span class="ruby-keyword kw">end</span>
741
+ </pre>
742
+ </div>
743
+ </div>
744
+ </div>
745
+ <div class="method">
746
+ <div class="title">
747
+ <a name="M000213"></a><b>local_socket_address?</b>(address)
748
+ </div>
749
+ <div class="sourcecode">
750
+ <p class="source-link">[ <a href="javascript:toggleSource('M000213_source')" id="l_M000213_source">show source</a> ]</p>
751
+ <div id="M000213_source" class="dyn-source">
752
+ <pre>
753
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 448</span>
754
+ 448: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">local_socket_address?</span>(<span class="ruby-identifier">address</span>)
755
+ 449: <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">get_socket_address_type</span>(<span class="ruby-identifier">address</span>)
756
+ 450: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:unix</span>
757
+ 451: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
758
+ 452: <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">:tcp</span>
759
+ 453: <span class="ruby-identifier">host</span>, <span class="ruby-identifier">port</span> = <span class="ruby-identifier">address</span>.<span class="ruby-identifier">sub</span>(<span class="ruby-regexp re">%r{^tcp://}</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">split</span>(<span class="ruby-value str">':'</span>, <span class="ruby-value">2</span>)
760
+ 454: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">host</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;127.0.0.1&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">host</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;::1&quot;</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">host</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;localhost&quot;</span>
761
+ 455: <span class="ruby-keyword kw">else</span>
762
+ 456: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">&quot;Unknown socket address type for '#{address}'.&quot;</span>
763
+ 457: <span class="ruby-keyword kw">end</span>
764
+ 458: <span class="ruby-keyword kw">end</span>
765
+ </pre>
766
+ </div>
767
+ </div>
768
+ </div>
769
+ <div class="method">
770
+ <div class="title">
771
+ <a name="M000219"></a><b>lower_privilege</b>(startup_file, options)
772
+ </div>
773
+ <div class="description">
774
+ <p>
775
+ Lowers the current process&#8216;s privilege based on the documented rules
776
+ for the &quot;user&quot;, &quot;group&quot;, &quot;default_user&quot; and
777
+ &quot;default_group&quot; options.
778
+ </p>
779
+ </div>
780
+ <div class="sourcecode">
781
+ <p class="source-link">[ <a href="javascript:toggleSource('M000219_source')" id="l_M000219_source">show source</a> ]</p>
782
+ <div id="M000219_source" class="dyn-source">
783
+ <pre>
784
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 654</span>
785
+ 654: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lower_privilege</span>(<span class="ruby-identifier">startup_file</span>, <span class="ruby-identifier">options</span>)
786
+ 655: <span class="ruby-constant">Utils</span>.<span class="ruby-identifier">lower_privilege_called</span>
787
+ 656: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">if</span> <span class="ruby-constant">Process</span>.<span class="ruby-identifier">euid</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
788
+ 657:
789
+ 658: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_user&quot;</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_user&quot;</span>].<span class="ruby-identifier">empty?</span>
790
+ 659: <span class="ruby-identifier">default_user</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_user&quot;</span>]
791
+ 660: <span class="ruby-keyword kw">else</span>
792
+ 661: <span class="ruby-identifier">default_user</span> = <span class="ruby-value str">&quot;nobody&quot;</span>
793
+ 662: <span class="ruby-keyword kw">end</span>
794
+ 663: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_group&quot;</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_group&quot;</span>].<span class="ruby-identifier">empty?</span>
795
+ 664: <span class="ruby-identifier">default_group</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;default_group&quot;</span>]
796
+ 665: <span class="ruby-keyword kw">else</span>
797
+ 666: <span class="ruby-identifier">default_group</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrgid</span>(<span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-identifier">default_user</span>).<span class="ruby-identifier">gid</span>).<span class="ruby-identifier">name</span>
798
+ 667: <span class="ruby-keyword kw">end</span>
799
+ 668:
800
+ 669: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;user&quot;</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;user&quot;</span>].<span class="ruby-identifier">empty?</span>
801
+ 670: <span class="ruby-keyword kw">begin</span>
802
+ 671: <span class="ruby-identifier">user_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;user&quot;</span>])
803
+ 672: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
804
+ 673: <span class="ruby-identifier">user_info</span> = <span class="ruby-keyword kw">nil</span>
805
+ 674: <span class="ruby-keyword kw">end</span>
806
+ 675: <span class="ruby-keyword kw">else</span>
807
+ 676: <span class="ruby-identifier">uid</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">lstat</span>(<span class="ruby-identifier">startup_file</span>).<span class="ruby-identifier">uid</span>
808
+ 677: <span class="ruby-keyword kw">begin</span>
809
+ 678: <span class="ruby-identifier">user_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwuid</span>(<span class="ruby-identifier">uid</span>)
810
+ 679: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
811
+ 680: <span class="ruby-identifier">user_info</span> = <span class="ruby-keyword kw">nil</span>
812
+ 681: <span class="ruby-keyword kw">end</span>
813
+ 682: <span class="ruby-keyword kw">end</span>
814
+ 683: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">user_info</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">uid</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
815
+ 684: <span class="ruby-keyword kw">begin</span>
816
+ 685: <span class="ruby-identifier">user_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwnam</span>(<span class="ruby-identifier">default_user</span>)
817
+ 686: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
818
+ 687: <span class="ruby-identifier">user_info</span> = <span class="ruby-keyword kw">nil</span>
819
+ 688: <span class="ruby-keyword kw">end</span>
820
+ 689: <span class="ruby-keyword kw">end</span>
821
+ 690:
822
+ 691: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;group&quot;</span>] <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;group&quot;</span>].<span class="ruby-identifier">empty?</span>
823
+ 692: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;group&quot;</span>] <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;!STARTUP_FILE!&quot;</span>
824
+ 693: <span class="ruby-identifier">gid</span> = <span class="ruby-constant">File</span>.<span class="ruby-identifier">lstat</span>(<span class="ruby-identifier">startup_file</span>).<span class="ruby-identifier">gid</span>
825
+ 694: <span class="ruby-keyword kw">begin</span>
826
+ 695: <span class="ruby-identifier">group_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrgid</span>(<span class="ruby-identifier">gid</span>)
827
+ 696: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
828
+ 697: <span class="ruby-identifier">group_info</span> = <span class="ruby-keyword kw">nil</span>
829
+ 698: <span class="ruby-keyword kw">end</span>
830
+ 699: <span class="ruby-keyword kw">else</span>
831
+ 700: <span class="ruby-keyword kw">begin</span>
832
+ 701: <span class="ruby-identifier">group_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrnam</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;group&quot;</span>])
833
+ 702: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
834
+ 703: <span class="ruby-identifier">group_info</span> = <span class="ruby-keyword kw">nil</span>
835
+ 704: <span class="ruby-keyword kw">end</span>
836
+ 705: <span class="ruby-keyword kw">end</span>
837
+ 706: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">user_info</span>
838
+ 707: <span class="ruby-keyword kw">begin</span>
839
+ 708: <span class="ruby-identifier">group_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrgid</span>(<span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">gid</span>)
840
+ 709: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
841
+ 710: <span class="ruby-identifier">group_info</span> = <span class="ruby-keyword kw">nil</span>
842
+ 711: <span class="ruby-keyword kw">end</span>
843
+ 712: <span class="ruby-keyword kw">else</span>
844
+ 713: <span class="ruby-identifier">group_info</span> = <span class="ruby-keyword kw">nil</span>
845
+ 714: <span class="ruby-keyword kw">end</span>
846
+ 715: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">group_info</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">group_info</span>.<span class="ruby-identifier">gid</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
847
+ 716: <span class="ruby-keyword kw">begin</span>
848
+ 717: <span class="ruby-identifier">group_info</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrnam</span>(<span class="ruby-identifier">default_group</span>)
849
+ 718: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>
850
+ 719: <span class="ruby-identifier">group_info</span> = <span class="ruby-keyword kw">nil</span>
851
+ 720: <span class="ruby-keyword kw">end</span>
852
+ 721: <span class="ruby-keyword kw">end</span>
853
+ 722:
854
+ 723: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">user_info</span>
855
+ 724: <span class="ruby-identifier">raise</span> <span class="ruby-constant">SecurityError</span>, <span class="ruby-value str">&quot;Cannot determine a user to lower privilege to&quot;</span>
856
+ 725: <span class="ruby-keyword kw">end</span>
857
+ 726: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">group_info</span>
858
+ 727: <span class="ruby-identifier">raise</span> <span class="ruby-constant">SecurityError</span>, <span class="ruby-value str">&quot;Cannot determine a group to lower privilege to&quot;</span>
859
+ 728: <span class="ruby-keyword kw">end</span>
860
+ 729:
861
+ 730: <span class="ruby-constant">NativeSupport</span>.<span class="ruby-identifier">switch_user</span>(<span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">name</span>, <span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">uid</span>, <span class="ruby-identifier">group_info</span>.<span class="ruby-identifier">gid</span>)
862
+ 731: <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'USER'</span>] = <span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">name</span>
863
+ 732: <span class="ruby-constant">ENV</span>[<span class="ruby-value str">'HOME'</span>] = <span class="ruby-identifier">user_info</span>.<span class="ruby-identifier">dir</span>
864
+ 733: <span class="ruby-keyword kw">end</span>
865
+ </pre>
866
+ </div>
867
+ </div>
868
+ </div>
869
+ <div class="method">
870
+ <div class="title">
871
+ <a name="M000203"></a><b>marshal_exception</b>(exception)
872
+ </div>
873
+ <div class="sourcecode">
874
+ <p class="source-link">[ <a href="javascript:toggleSource('M000203_source')" id="l_M000203_source">show source</a> ]</p>
875
+ <div id="M000203_source" class="dyn-source">
876
+ <pre>
877
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 120</span>
878
+ 120: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">marshal_exception</span>(<span class="ruby-identifier">exception</span>)
879
+ 121: <span class="ruby-identifier">data</span> = {
880
+ 122: <span class="ruby-identifier">:message</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">message</span>,
881
+ 123: <span class="ruby-identifier">:class</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>,
882
+ 124: <span class="ruby-identifier">:backtrace</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">backtrace</span>
883
+ 125: }
884
+ 126: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">InitializationError</span>)
885
+ 127: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:is_initialization_error</span>] = <span class="ruby-keyword kw">true</span>
886
+ 128: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span>
887
+ 129: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:child_exception</span>] = <span class="ruby-identifier">marshal_exception</span>(<span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span>)
888
+ 130: <span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span>
889
+ 131: <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span> = <span class="ruby-keyword kw">nil</span>
890
+ 132: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:exception</span>] = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">exception</span>)
891
+ 133: <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">child_exception</span>
892
+ 134: <span class="ruby-keyword kw">end</span>
893
+ 135: <span class="ruby-keyword kw">else</span>
894
+ 136: <span class="ruby-keyword kw">begin</span>
895
+ 137: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:exception</span>] = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">exception</span>)
896
+ 138: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-constant">TypeError</span>
897
+ 139: <span class="ruby-identifier">e</span> = <span class="ruby-constant">UnknownError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">exception</span>.<span class="ruby-identifier">message</span>, <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>,
898
+ 140: <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">backtrace</span>)
899
+ 141: <span class="ruby-identifier">data</span>[<span class="ruby-identifier">:exception</span>] = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">e</span>)
900
+ 142: <span class="ruby-keyword kw">end</span>
901
+ 143: <span class="ruby-keyword kw">end</span>
902
+ 144: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">dump</span>(<span class="ruby-identifier">data</span>)
903
+ 145: <span class="ruby-keyword kw">end</span>
904
+ </pre>
905
+ </div>
906
+ </div>
907
+ </div>
908
+ <div class="method">
909
+ <div class="title">
910
+ <a name="M000228"></a><b>passenger_tmpdir</b>(create = true)
911
+ </div>
912
+ <div class="sourcecode">
913
+ <p class="source-link">[ <a href="javascript:toggleSource('M000228_source')" id="l_M000228_source">show source</a> ]</p>
914
+ <div id="M000228_source" class="dyn-source">
915
+ <pre>
916
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils/tmpdir.rb, line 30</span>
917
+ 30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">passenger_tmpdir</span>(<span class="ruby-identifier">create</span> = <span class="ruby-keyword kw">true</span>)
918
+ 31: <span class="ruby-constant">PhusionPassenger</span><span class="ruby-operator">::</span><span class="ruby-constant">Utils</span>.<span class="ruby-identifier">passenger_tmpdir</span>(<span class="ruby-identifier">create</span>)
919
+ 32: <span class="ruby-keyword kw">end</span>
920
+ </pre>
921
+ </div>
922
+ </div>
923
+ </div>
924
+ <div class="method">
925
+ <div class="title">
926
+ <a name="M000206"></a><b>prepare_app_process</b>(startup_file, options)
927
+ </div>
928
+ <div class="description">
929
+ <p>
930
+ Prepare an application process using rules for the given spawn options.
931
+ This method is to be called before loading the application code.
932
+ </p>
933
+ <p>
934
+ <tt>startup_file</tt> is the application type&#8216;s startup file, e.g.
935
+ &quot;config/environment.rb&quot; for Rails apps and &quot;config.ru&quot;
936
+ for <a href="Rack.html">Rack</a> apps. See <a
937
+ href="SpawnManager.html#M000363">SpawnManager#spawn_application</a> for
938
+ options.
939
+ </p>
940
+ <p>
941
+ This function may modify <tt>options</tt>. The modified options are to be
942
+ passed to the request handler.
943
+ </p>
944
+ </div>
945
+ <div class="sourcecode">
946
+ <p class="source-link">[ <a href="javascript:toggleSource('M000206_source')" id="l_M000206_source">show source</a> ]</p>
947
+ <div id="M000206_source" class="dyn-source">
948
+ <pre>
949
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 194</span>
950
+ 194: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">prepare_app_process</span>(<span class="ruby-identifier">startup_file</span>, <span class="ruby-identifier">options</span>)
951
+ 195: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_root&quot;</span>] = <span class="ruby-identifier">canonicalize_path</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_root&quot;</span>])
952
+ 196: <span class="ruby-constant">Dir</span>.<span class="ruby-identifier">chdir</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_root&quot;</span>])
953
+ 197:
954
+ 198: <span class="ruby-identifier">lower_privilege</span>(<span class="ruby-identifier">startup_file</span>, <span class="ruby-identifier">options</span>)
955
+ 199: <span class="ruby-identifier">path</span>, <span class="ruby-identifier">is_parent</span> = <span class="ruby-identifier">check_directory_tree_permissions</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_root&quot;</span>])
956
+ 200: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">path</span>
957
+ 201: <span class="ruby-identifier">username</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getpwuid</span>(<span class="ruby-constant">Process</span>.<span class="ruby-identifier">euid</span>).<span class="ruby-identifier">name</span>
958
+ 202: <span class="ruby-identifier">groupname</span> = <span class="ruby-constant">Etc</span>.<span class="ruby-identifier">getgrgid</span>(<span class="ruby-constant">Process</span>.<span class="ruby-identifier">egid</span>).<span class="ruby-identifier">name</span>
959
+ 203: <span class="ruby-identifier">message</span> = <span class="ruby-value str">&quot;This application process is currently running as &quot;</span> <span class="ruby-operator">+</span>
960
+ 204: <span class="ruby-node">&quot;user '#{username}' and group '#{groupname}' and must be &quot;</span> <span class="ruby-operator">+</span>
961
+ 205: <span class="ruby-value str">&quot;able to access its application root directory &quot;</span> <span class="ruby-operator">+</span>
962
+ 206: <span class="ruby-node">&quot;'#{options[&quot;app_root&quot;]}'. &quot;</span>
963
+ 207: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">is_parent</span>
964
+ 208: <span class="ruby-identifier">message</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-node">&quot;However the parent directory '#{path}' &quot;</span> <span class="ruby-operator">+</span>
965
+ 209: <span class="ruby-value str">&quot;has wrong permissions, thereby preventing &quot;</span> <span class="ruby-operator">+</span>
966
+ 210: <span class="ruby-value str">&quot;this process from accessing its application &quot;</span> <span class="ruby-operator">+</span>
967
+ 211: <span class="ruby-value str">&quot;root directory. Please fix the permissions &quot;</span> <span class="ruby-operator">+</span>
968
+ 212: <span class="ruby-node">&quot;of the directory '#{path}' first.&quot;</span>
969
+ 213: <span class="ruby-keyword kw">else</span>
970
+ 214: <span class="ruby-identifier">message</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-value str">&quot;However this directory is not accessible &quot;</span> <span class="ruby-operator">+</span>
971
+ 215: <span class="ruby-value str">&quot;because it has wrong permissions. Please fix &quot;</span> <span class="ruby-operator">+</span>
972
+ 216: <span class="ruby-value str">&quot;these permissions first.&quot;</span>
973
+ 217: <span class="ruby-keyword kw">end</span>
974
+ 218: <span class="ruby-identifier">raise</span>(<span class="ruby-identifier">message</span>)
975
+ 219: <span class="ruby-keyword kw">end</span>
976
+ 220:
977
+ 221: <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RAILS_ENV&quot;</span>] = <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RACK_ENV&quot;</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;environment&quot;</span>]
978
+ 222:
979
+ 223: <span class="ruby-identifier">base_uri</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;base_uri&quot;</span>]
980
+ 224: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">base_uri</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-operator">!</span><span class="ruby-identifier">base_uri</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">base_uri</span> <span class="ruby-operator">!=</span> <span class="ruby-value str">&quot;/&quot;</span>
981
+ 225: <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RAILS_RELATIVE_URL_ROOT&quot;</span>] = <span class="ruby-identifier">base_uri</span>
982
+ 226: <span class="ruby-constant">ENV</span>[<span class="ruby-value str">&quot;RACK_BASE_URI&quot;</span>] = <span class="ruby-identifier">base_uri</span>
983
+ 227: <span class="ruby-keyword kw">end</span>
984
+ 228:
985
+ 229: <span class="ruby-identifier">encoded_environment_variables</span> = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;environment_variables&quot;</span>]
986
+ 230: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">encoded_environment_variables</span>
987
+ 231: <span class="ruby-identifier">env_vars_string</span> = <span class="ruby-identifier">encoded_environment_variables</span>.<span class="ruby-identifier">unpack</span>(<span class="ruby-value str">&quot;m&quot;</span>).<span class="ruby-identifier">first</span>
988
+ 232: <span class="ruby-identifier">env_vars_array</span> = <span class="ruby-identifier">env_vars_string</span>.<span class="ruby-identifier">split</span>(<span class="ruby-value str">&quot;\0&quot;</span>, <span class="ruby-value">-1</span>)
989
+ 233: <span class="ruby-identifier">env_vars_array</span>.<span class="ruby-identifier">pop</span>
990
+ 234: <span class="ruby-identifier">env_vars</span> = <span class="ruby-constant">Hash</span>[<span class="ruby-operator">*</span><span class="ruby-identifier">env_vars_array</span>]
991
+ 235: <span class="ruby-identifier">env_vars</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
992
+ 236: <span class="ruby-constant">ENV</span>[<span class="ruby-identifier">key</span>] = <span class="ruby-identifier">value</span>
993
+ 237: <span class="ruby-keyword kw">end</span>
994
+ 238: <span class="ruby-keyword kw">end</span>
995
+ 239:
996
+ 240: <span class="ruby-comment cmt"># Instantiate the analytics logger if requested. Can be nil.</span>
997
+ 241: <span class="ruby-identifier">require</span> <span class="ruby-value str">'phusion_passenger/analytics_logger'</span>
998
+ 242: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;analytics_logger&quot;</span>] = <span class="ruby-constant">AnalyticsLogger</span>.<span class="ruby-identifier">new_from_options</span>(<span class="ruby-identifier">options</span>)
999
+ 243:
1000
+ 244: <span class="ruby-comment cmt"># Make sure RubyGems uses any new environment variable values</span>
1001
+ 245: <span class="ruby-comment cmt"># that have been set now (e.g. $HOME, $GEM_HOME, etc) and that</span>
1002
+ 246: <span class="ruby-comment cmt"># it is able to detect newly installed gems.</span>
1003
+ 247: <span class="ruby-constant">Gem</span>.<span class="ruby-identifier">clear_paths</span>
1004
+ 248:
1005
+ 249: <span class="ruby-comment cmt"># Because spawned app processes exit using #exit!, #at_exit</span>
1006
+ 250: <span class="ruby-comment cmt"># blocks aren't called. Here we ninja patch Kernel so that</span>
1007
+ 251: <span class="ruby-comment cmt"># we can call #at_exit blocks during app process shutdown.</span>
1008
+ 252: <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">Kernel</span>
1009
+ 253: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">passenger_call_at_exit_blocks</span>
1010
+ 254: <span class="ruby-ivar">@passenger_at_exit_blocks</span> <span class="ruby-operator">||=</span> []
1011
+ 255: <span class="ruby-ivar">@passenger_at_exit_blocks</span>.<span class="ruby-identifier">reverse_each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">block</span><span class="ruby-operator">|</span>
1012
+ 256: <span class="ruby-identifier">block</span>.<span class="ruby-identifier">call</span>
1013
+ 257: <span class="ruby-keyword kw">end</span>
1014
+ 258: <span class="ruby-keyword kw">end</span>
1015
+ 259:
1016
+ 260: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">passenger_at_exit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1017
+ 261: <span class="ruby-ivar">@passenger_at_exit_blocks</span> <span class="ruby-operator">||=</span> []
1018
+ 262: <span class="ruby-ivar">@passenger_at_exit_blocks</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">block</span>
1019
+ 263: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">block</span>
1020
+ 264: <span class="ruby-keyword kw">end</span>
1021
+ 265: <span class="ruby-keyword kw">end</span>
1022
+ 266: <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">class_eval</span> <span class="ruby-keyword kw">do</span>
1023
+ 267: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">at_exit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1024
+ 268: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Kernel</span>.<span class="ruby-identifier">passenger_at_exit</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
1025
+ 269: <span class="ruby-keyword kw">end</span>
1026
+ 270: <span class="ruby-keyword kw">end</span>
1027
+ 271:
1028
+ 272:
1029
+ 273: <span class="ruby-comment cmt"># Rack::ApplicationSpawner depends on the 'rack' library, but the app</span>
1030
+ 274: <span class="ruby-comment cmt"># might want us to use a bundled version instead of a</span>
1031
+ 275: <span class="ruby-comment cmt"># gem/apt-get/yum/whatever-installed version. Therefore we must setup</span>
1032
+ 276: <span class="ruby-comment cmt"># the correct load paths before requiring 'rack'.</span>
1033
+ 277: <span class="ruby-comment cmt">#</span>
1034
+ 278: <span class="ruby-comment cmt"># The most popular tool for bundling dependencies is Bundler. Bundler</span>
1035
+ 279: <span class="ruby-comment cmt"># works as follows:</span>
1036
+ 280: <span class="ruby-comment cmt"># - If the bundle is locked then a file .bundle/environment.rb exists</span>
1037
+ 281: <span class="ruby-comment cmt"># which will setup the load paths.</span>
1038
+ 282: <span class="ruby-comment cmt"># - If the bundle is not locked then the load paths must be set up by</span>
1039
+ 283: <span class="ruby-comment cmt"># calling Bundler.setup.</span>
1040
+ 284: <span class="ruby-comment cmt"># - Rails 3's boot.rb automatically loads .bundle/environment.rb or</span>
1041
+ 285: <span class="ruby-comment cmt"># calls Bundler.setup if that's not available.</span>
1042
+ 286: <span class="ruby-comment cmt"># - Other Rack apps might not have a boot.rb but we still want to setup</span>
1043
+ 287: <span class="ruby-comment cmt"># Bundler.</span>
1044
+ 288: <span class="ruby-comment cmt"># - Some Rails 2 apps might have explicitly added Bundler support.</span>
1045
+ 289: <span class="ruby-comment cmt"># These apps call Bundler.setup in their preinitializer.rb.</span>
1046
+ 290: <span class="ruby-comment cmt">#</span>
1047
+ 291: <span class="ruby-comment cmt"># So the strategy is as follows:</span>
1048
+ 292:
1049
+ 293: <span class="ruby-comment cmt"># Our strategy might be completely unsuitable for the app or the</span>
1050
+ 294: <span class="ruby-comment cmt"># developer is using something other than Bundler, so we let the user</span>
1051
+ 295: <span class="ruby-comment cmt"># manually specify a load path setup file.</span>
1052
+ 296: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;load_path_setup_file&quot;</span>]
1053
+ 297: <span class="ruby-identifier">require</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;load_path_setup_file&quot;</span>])
1054
+ 298:
1055
+ 299: <span class="ruby-comment cmt"># The app developer may also override our strategy with this magic file.</span>
1056
+ 300: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-value str">'config/setup_load_paths.rb'</span>)
1057
+ 301: <span class="ruby-identifier">require</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-value str">'config/setup_load_paths'</span>)
1058
+ 302:
1059
+ 303: <span class="ruby-comment cmt"># If the Bundler lock environment file exists then load that. If it</span>
1060
+ 304: <span class="ruby-comment cmt"># exists then there's a 99.9% chance that loading it is the correct</span>
1061
+ 305: <span class="ruby-comment cmt"># thing to do.</span>
1062
+ 306: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-value str">'.bundle/environment.rb'</span>)
1063
+ 307: <span class="ruby-identifier">require</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">expand_path</span>(<span class="ruby-value str">'.bundle/environment'</span>)
1064
+ 308:
1065
+ 309: <span class="ruby-comment cmt"># If the Bundler environment file doesn't exist then there are two</span>
1066
+ 310: <span class="ruby-comment cmt"># possibilities:</span>
1067
+ 311: <span class="ruby-comment cmt"># 1. Bundler is not used, in which case we don't have to do anything.</span>
1068
+ 312: <span class="ruby-comment cmt"># 2. Bundler *is* used, but the gems are not locked and we're supposed</span>
1069
+ 313: <span class="ruby-comment cmt"># to call Bundler.setup.</span>
1070
+ 314: <span class="ruby-comment cmt">#</span>
1071
+ 315: <span class="ruby-comment cmt"># The existence of Gemfile indicates whether (2) is true:</span>
1072
+ 316: <span class="ruby-keyword kw">elsif</span> <span class="ruby-constant">File</span>.<span class="ruby-identifier">exist?</span>(<span class="ruby-value str">'Gemfile'</span>)
1073
+ 317: <span class="ruby-comment cmt"># In case of Rails 3, config/boot.rb already calls Bundler.setup.</span>
1074
+ 318: <span class="ruby-comment cmt"># However older versions of Rails may not so loading boot.rb might</span>
1075
+ 319: <span class="ruby-comment cmt"># not be the correct thing to do. To be on the safe side we</span>
1076
+ 320: <span class="ruby-comment cmt"># call Bundler.setup ourselves; calling Bundler.setup twice is</span>
1077
+ 321: <span class="ruby-comment cmt"># harmless. If this isn't the correct thing to do after all then</span>
1078
+ 322: <span class="ruby-comment cmt"># there's always the load_path_setup_file option and</span>
1079
+ 323: <span class="ruby-comment cmt"># setup_load_paths.rb.</span>
1080
+ 324: <span class="ruby-identifier">require</span> <span class="ruby-value str">'rubygems'</span>
1081
+ 325: <span class="ruby-identifier">require</span> <span class="ruby-value str">'bundler'</span>
1082
+ 326: <span class="ruby-constant">Bundler</span>.<span class="ruby-identifier">setup</span>
1083
+ 327: <span class="ruby-keyword kw">end</span>
1084
+ 328:
1085
+ 329: <span class="ruby-comment cmt"># Bundler might remove Phusion Passenger from the load path in its zealous</span>
1086
+ 330: <span class="ruby-comment cmt"># attempt to un-require RubyGems, so here we put Phusion Passenger back</span>
1087
+ 331: <span class="ruby-comment cmt"># into the load path. This must be done before loading the app's startup</span>
1088
+ 332: <span class="ruby-comment cmt"># file because the app might require() Phusion Passenger files.</span>
1089
+ 333: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">!=</span> <span class="ruby-constant">LIBDIR</span>
1090
+ 334: <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">unshift</span>(<span class="ruby-constant">LIBDIR</span>)
1091
+ 335: <span class="ruby-identifier">$LOAD_PATH</span>.<span class="ruby-identifier">uniq!</span>
1092
+ 336: <span class="ruby-keyword kw">end</span>
1093
+ 337:
1094
+ 338:
1095
+ 339: <span class="ruby-comment cmt"># !!! NOTE !!!</span>
1096
+ 340: <span class="ruby-comment cmt"># If the app is using Bundler then any dependencies required past this</span>
1097
+ 341: <span class="ruby-comment cmt"># point must be specified in the Gemfile. Like ruby-debug if debugging is on...</span>
1098
+ 342:
1099
+ 343: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;debugger&quot;</span>]
1100
+ 344: <span class="ruby-identifier">require</span> <span class="ruby-value str">'ruby-debug'</span>
1101
+ 345: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-constant">Debugger</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:ctrl_port</span>)
1102
+ 346: <span class="ruby-identifier">raise</span> <span class="ruby-value str">&quot;Your version of ruby-debug is too old. Please upgrade to the latest version.&quot;</span>
1103
+ 347: <span class="ruby-keyword kw">end</span>
1104
+ 348: <span class="ruby-constant">Debugger</span>.<span class="ruby-identifier">start_remote</span>(<span class="ruby-value str">'127.0.0.1'</span>, [<span class="ruby-value">0</span>, <span class="ruby-value">0</span>])
1105
+ 349: <span class="ruby-constant">Debugger</span>.<span class="ruby-identifier">start</span>
1106
+ 350: <span class="ruby-keyword kw">end</span>
1107
+ 351:
1108
+ 352: <span class="ruby-constant">PhusionPassenger</span>.<span class="ruby-identifier">_spawn_options</span> = <span class="ruby-identifier">options</span>
1109
+ 353: <span class="ruby-keyword kw">end</span>
1110
+ </pre>
1111
+ </div>
1112
+ </div>
1113
+ </div>
1114
+ <div class="method">
1115
+ <div class="title">
1116
+ <a name="M000205"></a><b>print_exception</b>(current_location, exception, destination = nil)
1117
+ </div>
1118
+ <div class="description">
1119
+ <p>
1120
+ Print the given exception, including the stack trace, to STDERR.
1121
+ </p>
1122
+ <p>
1123
+ <tt>current_location</tt> is a string which describes where the code is
1124
+ currently at. Usually the current class name will be enough.
1125
+ </p>
1126
+ </div>
1127
+ <div class="sourcecode">
1128
+ <p class="source-link">[ <a href="javascript:toggleSource('M000205_source')" id="l_M000205_source">show source</a> ]</p>
1129
+ <div id="M000205_source" class="dyn-source">
1130
+ <pre>
1131
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 172</span>
1132
+ 172: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_exception</span>(<span class="ruby-identifier">current_location</span>, <span class="ruby-identifier">exception</span>, <span class="ruby-identifier">destination</span> = <span class="ruby-keyword kw">nil</span>)
1133
+ 173: <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">exception</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">SystemExit</span>)
1134
+ 174: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">backtrace_string</span>(<span class="ruby-identifier">current_location</span>)
1135
+ 175: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">defined?</span>(<span class="ruby-constant">DebugLogging</span>) <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">DebugLogging</span>)
1136
+ 176: <span class="ruby-identifier">error</span>(<span class="ruby-identifier">data</span>)
1137
+ 177: <span class="ruby-keyword kw">else</span>
1138
+ 178: <span class="ruby-identifier">destination</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">STDERR</span>
1139
+ 179: <span class="ruby-identifier">destination</span>.<span class="ruby-identifier">puts</span>(<span class="ruby-identifier">data</span>)
1140
+ 180: <span class="ruby-identifier">destination</span>.<span class="ruby-identifier">flush</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">destination</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:flush</span>)
1141
+ 181: <span class="ruby-keyword kw">end</span>
1142
+ 182: <span class="ruby-keyword kw">end</span>
1143
+ 183: <span class="ruby-keyword kw">end</span>
1144
+ </pre>
1145
+ </div>
1146
+ </div>
1147
+ </div>
1148
+ <div class="method">
1149
+ <div class="title">
1150
+ <a name="M000195"></a><b>private_class_method</b>(name)
1151
+ </div>
1152
+ <div class="sourcecode">
1153
+ <p class="source-link">[ <a href="javascript:toggleSource('M000195_source')" id="l_M000195_source">show source</a> ]</p>
1154
+ <div id="M000195_source" class="dyn-source">
1155
+ <pre>
1156
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 44</span>
1157
+ 44: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">private_class_method</span>(<span class="ruby-identifier">name</span>)
1158
+ 45: <span class="ruby-identifier">metaclass</span> = <span class="ruby-keyword kw">class</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-keyword kw">self</span>; <span class="ruby-keyword kw">self</span>; <span class="ruby-keyword kw">end</span>
1159
+ 46: <span class="ruby-identifier">metaclass</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:private</span>, <span class="ruby-identifier">name</span>)
1160
+ 47: <span class="ruby-keyword kw">end</span>
1161
+ </pre>
1162
+ </div>
1163
+ </div>
1164
+ </div>
1165
+ <div class="method">
1166
+ <div class="title">
1167
+ <a name="M000215"></a><b>process_is_alive?</b>(pid)
1168
+ </div>
1169
+ <div class="description">
1170
+ <p>
1171
+ Checks whether the given process exists.
1172
+ </p>
1173
+ </div>
1174
+ <div class="sourcecode">
1175
+ <p class="source-link">[ <a href="javascript:toggleSource('M000215_source')" id="l_M000215_source">show source</a> ]</p>
1176
+ <div id="M000215_source" class="dyn-source">
1177
+ <pre>
1178
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 502</span>
1179
+ 502: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">process_is_alive?</span>(<span class="ruby-identifier">pid</span>)
1180
+ 503: <span class="ruby-keyword kw">begin</span>
1181
+ 504: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">kill</span>(<span class="ruby-value">0</span>, <span class="ruby-identifier">pid</span>)
1182
+ 505: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
1183
+ 506: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ESRCH</span>
1184
+ 507: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
1185
+ 508: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SystemCallError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
1186
+ 509: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
1187
+ 510: <span class="ruby-keyword kw">end</span>
1188
+ 511: <span class="ruby-keyword kw">end</span>
1189
+ </pre>
1190
+ </div>
1191
+ </div>
1192
+ </div>
1193
+ <div class="method">
1194
+ <div class="title">
1195
+ <a name="M000216"></a><b>report_app_init_status</b>(channel, sink = STDERR) {|| ...}
1196
+ </div>
1197
+ <div class="description">
1198
+ <p>
1199
+ Run the given block. A message will be sent through <tt>channel</tt> (a <a
1200
+ href="MessageChannel.html">MessageChannel</a> object), telling the remote
1201
+ side whether the block raised an exception, called exit(), or succeeded.
1202
+ </p>
1203
+ <p>
1204
+ If <em>sink</em> is non-nil, then every operation on $stderr/STDERR inside
1205
+ the block will be performed on <em>sink</em> as well. If <em>sink</em> is
1206
+ nil then all operations on $stderr/STDERR inside the block will be silently
1207
+ discarded, i.e. if one writes to $stderr/STDERR then nothing will be
1208
+ actually written to the console.
1209
+ </p>
1210
+ <p>
1211
+ Returns whether the block succeeded, i.e. whether it didn&#8216;t raise an
1212
+ exception.
1213
+ </p>
1214
+ <p>
1215
+ Exceptions are not propagated, except SystemExit and a few
1216
+ non-StandardExeption classes such as SignalException. Of the exceptions
1217
+ that are propagated, only SystemExit will be reported.
1218
+ </p>
1219
+ </div>
1220
+ <div class="sourcecode">
1221
+ <p class="source-link">[ <a href="javascript:toggleSource('M000216_source')" id="l_M000216_source">show source</a> ]</p>
1222
+ <div id="M000216_source" class="dyn-source">
1223
+ <pre>
1224
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 552</span>
1225
+ 552: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">report_app_init_status</span>(<span class="ruby-identifier">channel</span>, <span class="ruby-identifier">sink</span> = <span class="ruby-constant">STDERR</span>)
1226
+ 553: <span class="ruby-keyword kw">begin</span>
1227
+ 554: <span class="ruby-identifier">old_global_stderr</span> = <span class="ruby-identifier">$stderr</span>
1228
+ 555: <span class="ruby-identifier">old_stderr</span> = <span class="ruby-constant">STDERR</span>
1229
+ 556: <span class="ruby-identifier">stderr_output</span> = <span class="ruby-value str">&quot;&quot;</span>
1230
+ 557:
1231
+ 558: <span class="ruby-identifier">pseudo_stderr</span> = <span class="ruby-constant">PseudoIO</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">sink</span>)
1232
+ 559: <span class="ruby-constant">Object</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:remove_const</span>, <span class="ruby-value str">'STDERR'</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
1233
+ 560: <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_set</span>(<span class="ruby-value str">'STDERR'</span>, <span class="ruby-identifier">pseudo_stderr</span>)
1234
+ 561: <span class="ruby-identifier">$stderr</span> = <span class="ruby-identifier">pseudo_stderr</span>
1235
+ 562:
1236
+ 563: <span class="ruby-keyword kw">begin</span>
1237
+ 564: <span class="ruby-keyword kw">yield</span>
1238
+ 565: <span class="ruby-keyword kw">ensure</span>
1239
+ 566: <span class="ruby-constant">Object</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">:remove_const</span>, <span class="ruby-value str">'STDERR'</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
1240
+ 567: <span class="ruby-constant">Object</span>.<span class="ruby-identifier">const_set</span>(<span class="ruby-value str">'STDERR'</span>, <span class="ruby-identifier">old_stderr</span>)
1241
+ 568: <span class="ruby-identifier">$stderr</span> = <span class="ruby-identifier">old_global_stderr</span>
1242
+ 569: <span class="ruby-identifier">stderr_output</span> = <span class="ruby-identifier">pseudo_stderr</span>.<span class="ruby-identifier">done!</span>
1243
+ 570: <span class="ruby-keyword kw">end</span>
1244
+ 571:
1245
+ 572: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write</span>(<span class="ruby-value str">'success'</span>)
1246
+ 573: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span>
1247
+ 574: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">StandardError</span>, <span class="ruby-constant">ScriptError</span>, <span class="ruby-constant">NoMemoryError</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
1248
+ 575: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write</span>(<span class="ruby-value str">'exception'</span>)
1249
+ 576: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write_scalar</span>(<span class="ruby-identifier">marshal_exception</span>(<span class="ruby-identifier">e</span>))
1250
+ 577: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write_scalar</span>(<span class="ruby-identifier">stderr_output</span>)
1251
+ 578: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">false</span>
1252
+ 579: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">SystemExit</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
1253
+ 580: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write</span>(<span class="ruby-value str">'exit'</span>)
1254
+ 581: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write_scalar</span>(<span class="ruby-identifier">marshal_exception</span>(<span class="ruby-identifier">e</span>))
1255
+ 582: <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">write_scalar</span>(<span class="ruby-identifier">stderr_output</span>)
1256
+ 583: <span class="ruby-identifier">raise</span>
1257
+ 584: <span class="ruby-keyword kw">end</span>
1258
+ 585: <span class="ruby-keyword kw">end</span>
1259
+ </pre>
1260
+ </div>
1261
+ </div>
1262
+ </div>
1263
+ <div class="method">
1264
+ <div class="title">
1265
+ <a name="M000214"></a><b>safe_fork</b>(current_location = self.class, double_fork = false) {|| ...}
1266
+ </div>
1267
+ <div class="description">
1268
+ <p>
1269
+ Fork a <a href="Utils.html#M000226">new</a> process and run the given block
1270
+ inside the child process, just like fork(). Unlike fork(), this method is
1271
+ safe, i.e. there&#8216;s no way for the child process to escape the block.
1272
+ Any uncaught exceptions in the child process will be printed to standard
1273
+ output, citing <tt>current_location</tt> as the source. Futhermore, the
1274
+ child process will exit by calling Kernel#exit!, thereby bypassing any <a
1275
+ href="Utils.html#M000207">at_exit</a> or ensure blocks.
1276
+ </p>
1277
+ <p>
1278
+ If <tt>double_fork</tt> is true, then the child process will fork and
1279
+ immediately exit. This technique can be used to avoid zombie processes, at
1280
+ the expense of not being able to waitpid() the second child.
1281
+ </p>
1282
+ </div>
1283
+ <div class="sourcecode">
1284
+ <p class="source-link">[ <a href="javascript:toggleSource('M000214_source')" id="l_M000214_source">show source</a> ]</p>
1285
+ <div id="M000214_source" class="dyn-source">
1286
+ <pre>
1287
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 470</span>
1288
+ 470: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">safe_fork</span>(<span class="ruby-identifier">current_location</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>, <span class="ruby-identifier">double_fork</span> = <span class="ruby-keyword kw">false</span>)
1289
+ 471: <span class="ruby-identifier">pid</span> = <span class="ruby-identifier">fork</span>
1290
+ 472: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pid</span>.<span class="ruby-identifier">nil?</span>
1291
+ 473: <span class="ruby-identifier">has_exception</span> = <span class="ruby-keyword kw">false</span>
1292
+ 474: <span class="ruby-keyword kw">begin</span>
1293
+ 475: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">double_fork</span>
1294
+ 476: <span class="ruby-identifier">pid2</span> = <span class="ruby-identifier">fork</span>
1295
+ 477: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">pid2</span>.<span class="ruby-identifier">nil?</span>
1296
+ 478: <span class="ruby-identifier">srand</span>
1297
+ 479: <span class="ruby-keyword kw">yield</span>
1298
+ 480: <span class="ruby-keyword kw">end</span>
1299
+ 481: <span class="ruby-keyword kw">else</span>
1300
+ 482: <span class="ruby-identifier">srand</span>
1301
+ 483: <span class="ruby-keyword kw">yield</span>
1302
+ 484: <span class="ruby-keyword kw">end</span>
1303
+ 485: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
1304
+ 486: <span class="ruby-identifier">has_exception</span> = <span class="ruby-keyword kw">true</span>
1305
+ 487: <span class="ruby-identifier">print_exception</span>(<span class="ruby-identifier">current_location</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">e</span>)
1306
+ 488: <span class="ruby-keyword kw">ensure</span>
1307
+ 489: <span class="ruby-identifier">exit!</span>(<span class="ruby-identifier">has_exception</span> <span class="ruby-value">? </span><span class="ruby-value">1</span> <span class="ruby-operator">:</span> <span class="ruby-value">0</span>)
1308
+ 490: <span class="ruby-keyword kw">end</span>
1309
+ 491: <span class="ruby-keyword kw">else</span>
1310
+ 492: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">double_fork</span>
1311
+ 493: <span class="ruby-constant">Process</span>.<span class="ruby-identifier">waitpid</span>(<span class="ruby-identifier">pid</span>) <span class="ruby-keyword kw">rescue</span> <span class="ruby-keyword kw">nil</span>
1312
+ 494: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">pid</span>
1313
+ 495: <span class="ruby-keyword kw">else</span>
1314
+ 496: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">pid</span>
1315
+ 497: <span class="ruby-keyword kw">end</span>
1316
+ 498: <span class="ruby-keyword kw">end</span>
1317
+ 499: <span class="ruby-keyword kw">end</span>
1318
+ </pre>
1319
+ </div>
1320
+ </div>
1321
+ </div>
1322
+ <div class="method">
1323
+ <div class="title">
1324
+ <a name="M000223"></a><b>sanitize_spawn_options</b>(options)
1325
+ </div>
1326
+ <div class="sourcecode">
1327
+ <p class="source-link">[ <a href="javascript:toggleSource('M000223_source')" id="l_M000223_source">show source</a> ]</p>
1328
+ <div id="M000223_source" class="dyn-source">
1329
+ <pre>
1330
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 807</span>
1331
+ 807: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">sanitize_spawn_options</span>(<span class="ruby-identifier">options</span>)
1332
+ 808: <span class="ruby-identifier">defaults</span> = {
1333
+ 809: <span class="ruby-value str">&quot;app_type&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;rails&quot;</span>,
1334
+ 810: <span class="ruby-value str">&quot;environment&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;production&quot;</span>,
1335
+ 811: <span class="ruby-value str">&quot;spawn_method&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value str">&quot;smart-lv2&quot;</span>,
1336
+ 812: <span class="ruby-value str">&quot;framework_spawner_timeout&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>,
1337
+ 813: <span class="ruby-value str">&quot;app_spawner_timeout&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-value">-1</span>,
1338
+ 814: <span class="ruby-value str">&quot;print_exceptions&quot;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-keyword kw">true</span>
1339
+ 815: }
1340
+ 816: <span class="ruby-identifier">options</span> = <span class="ruby-identifier">defaults</span>.<span class="ruby-identifier">merge</span>(<span class="ruby-identifier">options</span>)
1341
+ 817: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_group_name&quot;</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_root&quot;</span>] <span class="ruby-keyword kw">if</span> <span class="ruby-operator">!</span><span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_group_name&quot;</span>]
1342
+ 818: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;framework_spawner_timeout&quot;</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;framework_spawner_timeout&quot;</span>].<span class="ruby-identifier">to_i</span>
1343
+ 819: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_spawner_timeout&quot;</span>] = <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;app_spawner_timeout&quot;</span>].<span class="ruby-identifier">to_i</span>
1344
+ 820: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>.<span class="ruby-identifier">has_key?</span>(<span class="ruby-value str">&quot;print_framework_loading_exceptions&quot;</span>)
1345
+ 821: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;print_framework_loading_exceptions&quot;</span>] = <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;print_framework_loading_exceptions&quot;</span>])
1346
+ 822: <span class="ruby-keyword kw">end</span>
1347
+ 823: <span class="ruby-comment cmt"># Force this to be a boolean for easy use with Utils#unmarshal_and_raise_errors.</span>
1348
+ 824: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;print_exceptions&quot;</span>] = <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;print_exceptions&quot;</span>])
1349
+ 825:
1350
+ 826: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;analytics&quot;</span>] = <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;analytics&quot;</span>])
1351
+ 827: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;show_version_in_header&quot;</span>] = <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;show_version_in_header&quot;</span>])
1352
+ 828:
1353
+ 829: <span class="ruby-comment cmt"># Smart spawning is not supported when using ruby-debug.</span>
1354
+ 830: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;debugger&quot;</span>] = <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;debugger&quot;</span>])
1355
+ 831: <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;spawn_method&quot;</span>] = <span class="ruby-value str">&quot;conservative&quot;</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>[<span class="ruby-value str">&quot;debugger&quot;</span>]
1356
+ 832:
1357
+ 833: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">options</span>
1358
+ 834: <span class="ruby-keyword kw">end</span>
1359
+ </pre>
1360
+ </div>
1361
+ </div>
1362
+ </div>
1363
+ <div class="method">
1364
+ <div class="title">
1365
+ <a name="M000224"></a><b>split_by_null_into_hash</b>(data)
1366
+ </div>
1367
+ <div class="description">
1368
+ <p>
1369
+ Split the given string into an hash. Keys and values are obtained by
1370
+ splitting the string using the null character as the delimitor.
1371
+ </p>
1372
+ </div>
1373
+ <div class="sourcecode">
1374
+ <p class="source-link">[ <a href="javascript:toggleSource('M000224_source')" id="l_M000224_source">show source</a> ]</p>
1375
+ <div id="M000224_source" class="dyn-source">
1376
+ <pre>
1377
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 839</span>
1378
+ 839: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">split_by_null_into_hash</span>(<span class="ruby-identifier">data</span>)
1379
+ 840: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">PhusionPassenger</span><span class="ruby-operator">::</span><span class="ruby-constant">NativeSupport</span>.<span class="ruby-identifier">split_by_null_into_hash</span>(<span class="ruby-identifier">data</span>)
1380
+ 841: <span class="ruby-keyword kw">end</span>
1381
+ </pre>
1382
+ </div>
1383
+ </div>
1384
+ </div>
1385
+ <div class="method">
1386
+ <div class="title">
1387
+ <a name="M000225"></a><b>split_by_null_into_hash</b>(data)
1388
+ </div>
1389
+ <div class="sourcecode">
1390
+ <p class="source-link">[ <a href="javascript:toggleSource('M000225_source')" id="l_M000225_source">show source</a> ]</p>
1391
+ <div id="M000225_source" class="dyn-source">
1392
+ <pre>
1393
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 846</span>
1394
+ 846: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">split_by_null_into_hash</span>(<span class="ruby-identifier">data</span>)
1395
+ 847: <span class="ruby-identifier">data</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-constant">PADDING</span>
1396
+ 848: <span class="ruby-identifier">array</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">split</span>(<span class="ruby-constant">NULL</span>)
1397
+ 849: <span class="ruby-identifier">array</span>.<span class="ruby-identifier">pop</span>
1398
+ 850: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">slice!</span>(<span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>, <span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>)
1399
+ 851: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Hash</span>[<span class="ruby-operator">*</span><span class="ruby-identifier">array</span>]
1400
+ 852: <span class="ruby-keyword kw">end</span>
1401
+ </pre>
1402
+ </div>
1403
+ </div>
1404
+ </div>
1405
+ <div class="method">
1406
+ <div class="title">
1407
+ <a name="M000222"></a><b>to_boolean</b>(value)
1408
+ </div>
1409
+ <div class="sourcecode">
1410
+ <p class="source-link">[ <a href="javascript:toggleSource('M000222_source')" id="l_M000222_source">show source</a> ]</p>
1411
+ <div id="M000222_source" class="dyn-source">
1412
+ <pre>
1413
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 803</span>
1414
+ 803: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">to_boolean</span>(<span class="ruby-identifier">value</span>)
1415
+ 804: <span class="ruby-keyword kw">return</span> <span class="ruby-operator">!</span>(<span class="ruby-identifier">value</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">false</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">value</span> <span class="ruby-operator">==</span> <span class="ruby-value str">&quot;false&quot;</span>)
1416
+ 805: <span class="ruby-keyword kw">end</span>
1417
+ </pre>
1418
+ </div>
1419
+ </div>
1420
+ </div>
1421
+ <div class="method">
1422
+ <div class="title">
1423
+ <a name="M000217"></a><b>unmarshal_and_raise_errors</b>(channel, print_exception = nil, app_type = &quot;rails&quot;)
1424
+ </div>
1425
+ <div class="description">
1426
+ <p>
1427
+ Receive status information that was sent to <tt>channel</tt> by <a
1428
+ href="Utils.html#M000216">report_app_init_status</a>. If an error occured
1429
+ according to the received information, then an appropriate exception will
1430
+ be raised.
1431
+ </p>
1432
+ <p>
1433
+ If <tt><a href="Utils.html#M000205">print_exception</a></tt> evaluates to
1434
+ true, then the exception message and the backtrace will also be printed.
1435
+ Where it is printed to depends on the type of <tt><a
1436
+ href="Utils.html#M000205">print_exception</a></tt>:
1437
+ </p>
1438
+ <ul>
1439
+ <li>If it responds to #puts, then the exception information will be printed
1440
+ using this method.
1441
+
1442
+ </li>
1443
+ <li>If it responds to #to_str, then the exception information will be appended
1444
+ to the file whose filename equals the return value of the #to_str call.
1445
+
1446
+ </li>
1447
+ <li>Otherwise, it will be printed to STDERR.
1448
+
1449
+ </li>
1450
+ </ul>
1451
+ <p>
1452
+ Raises:
1453
+ </p>
1454
+ <ul>
1455
+ <li><a href="AppInitError.html">AppInitError</a>: this class wraps the
1456
+ exception information received through the channel.
1457
+
1458
+ </li>
1459
+ <li>IOError, SystemCallError, SocketError: these errors are raised if an error
1460
+ occurred while receiving the information through the channel.
1461
+
1462
+ </li>
1463
+ </ul>
1464
+ </div>
1465
+ <div class="sourcecode">
1466
+ <p class="source-link">[ <a href="javascript:toggleSource('M000217_source')" id="l_M000217_source">show source</a> ]</p>
1467
+ <div id="M000217_source" class="dyn-source">
1468
+ <pre>
1469
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 609</span>
1470
+ 609: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unmarshal_and_raise_errors</span>(<span class="ruby-identifier">channel</span>, <span class="ruby-identifier">print_exception</span> = <span class="ruby-keyword kw">nil</span>, <span class="ruby-identifier">app_type</span> = <span class="ruby-value str">&quot;rails&quot;</span>)
1471
+ 610: <span class="ruby-identifier">args</span> = <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">read</span>
1472
+ 611: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>.<span class="ruby-identifier">nil?</span>
1473
+ 612: <span class="ruby-identifier">raise</span> <span class="ruby-constant">EOFError</span>, <span class="ruby-value str">&quot;Unexpected end-of-file detected.&quot;</span>
1474
+ 613: <span class="ruby-keyword kw">end</span>
1475
+ 614: <span class="ruby-identifier">status</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">0</span>]
1476
+ 615: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'exception'</span>
1477
+ 616: <span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">unmarshal_exception</span>(<span class="ruby-identifier">channel</span>.<span class="ruby-identifier">read_scalar</span>)
1478
+ 617: <span class="ruby-identifier">stderr</span> = <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">read_scalar</span>
1479
+ 618: <span class="ruby-identifier">exception</span> = <span class="ruby-constant">AppInitError</span>.<span class="ruby-identifier">new</span>(
1480
+ 619: <span class="ruby-node">&quot;Application '#{@app_root}' raised an exception: &quot;</span> <span class="ruby-operator">&lt;&lt;</span>
1481
+ 620: <span class="ruby-node">&quot;#{child_exception.class} (#{child_exception.message})&quot;</span>,
1482
+ 621: <span class="ruby-identifier">child_exception</span>,
1483
+ 622: <span class="ruby-identifier">app_type</span>,
1484
+ 623: <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">stderr</span>)
1485
+ 624: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">status</span> <span class="ruby-operator">==</span> <span class="ruby-value str">'exit'</span>
1486
+ 625: <span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">unmarshal_exception</span>(<span class="ruby-identifier">channel</span>.<span class="ruby-identifier">read_scalar</span>)
1487
+ 626: <span class="ruby-identifier">stderr</span> = <span class="ruby-identifier">channel</span>.<span class="ruby-identifier">read_scalar</span>
1488
+ 627: <span class="ruby-identifier">exception</span> = <span class="ruby-constant">AppInitError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;Application '#{@app_root}' exited during startup&quot;</span>,
1489
+ 628: <span class="ruby-identifier">child_exception</span>, <span class="ruby-identifier">app_type</span>, <span class="ruby-identifier">stderr</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-value">? </span><span class="ruby-keyword kw">nil</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">stderr</span>)
1490
+ 629: <span class="ruby-keyword kw">else</span>
1491
+ 630: <span class="ruby-identifier">exception</span> = <span class="ruby-keyword kw">nil</span>
1492
+ 631: <span class="ruby-keyword kw">end</span>
1493
+ 632:
1494
+ 633: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">print_exception</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">exception</span>
1495
+ 634: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">print_exception</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:puts</span>)
1496
+ 635: <span class="ruby-identifier">print_exception</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">child_exception</span>, <span class="ruby-identifier">print_exception</span>)
1497
+ 636: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">print_exception</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">:to_str</span>)
1498
+ 637: <span class="ruby-identifier">filename</span> = <span class="ruby-identifier">print_exception</span>.<span class="ruby-identifier">to_str</span>
1499
+ 638: <span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">filename</span>, <span class="ruby-value str">'a'</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">f</span><span class="ruby-operator">|</span>
1500
+ 639: <span class="ruby-identifier">print_exception</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">child_exception</span>, <span class="ruby-identifier">f</span>)
1501
+ 640: <span class="ruby-keyword kw">end</span>
1502
+ 641: <span class="ruby-keyword kw">else</span>
1503
+ 642: <span class="ruby-identifier">print_exception</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">to_s</span>, <span class="ruby-identifier">child_exception</span>)
1504
+ 643: <span class="ruby-keyword kw">end</span>
1505
+ 644: <span class="ruby-keyword kw">end</span>
1506
+ 645: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">exception</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exception</span>
1507
+ 646: <span class="ruby-keyword kw">end</span>
1508
+ </pre>
1509
+ </div>
1510
+ </div>
1511
+ </div>
1512
+ <div class="method">
1513
+ <div class="title">
1514
+ <a name="M000204"></a><b>unmarshal_exception</b>(data)
1515
+ </div>
1516
+ <div class="sourcecode">
1517
+ <p class="source-link">[ <a href="javascript:toggleSource('M000204_source')" id="l_M000204_source">show source</a> ]</p>
1518
+ <div id="M000204_source" class="dyn-source">
1519
+ <pre>
1520
+ <span class="ruby-comment cmt"># File lib/phusion_passenger/utils.rb, line 147</span>
1521
+ 147: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unmarshal_exception</span>(<span class="ruby-identifier">data</span>)
1522
+ 148: <span class="ruby-identifier">hash</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">data</span>)
1523
+ 149: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:is_initialization_error</span>]
1524
+ 150: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:child_exception</span>]
1525
+ 151: <span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">unmarshal_exception</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:child_exception</span>])
1526
+ 152: <span class="ruby-keyword kw">else</span>
1527
+ 153: <span class="ruby-identifier">child_exception</span> = <span class="ruby-keyword kw">nil</span>
1528
+ 154: <span class="ruby-keyword kw">end</span>
1529
+ 155:
1530
+ 156: <span class="ruby-identifier">exception</span> = <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:exception</span>])
1531
+ 157: <span class="ruby-identifier">exception</span>.<span class="ruby-identifier">child_exception</span> = <span class="ruby-identifier">child_exception</span>
1532
+ 158: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">exception</span>
1533
+ 159: <span class="ruby-keyword kw">else</span>
1534
+ 160: <span class="ruby-keyword kw">begin</span>
1535
+ 161: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">Marshal</span>.<span class="ruby-identifier">load</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:exception</span>])
1536
+ 162: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-constant">TypeError</span>
1537
+ 163: <span class="ruby-keyword kw">return</span> <span class="ruby-constant">UnknownError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:message</span>], <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:class</span>], <span class="ruby-identifier">hash</span>[<span class="ruby-identifier">:backtrace</span>])
1538
+ 164: <span class="ruby-keyword kw">end</span>
1539
+ 165: <span class="ruby-keyword kw">end</span>
1540
+ 166: <span class="ruby-keyword kw">end</span>
1541
+ </pre>
1542
+ </div>
1543
+ </div>
1544
+ </div>
1545
+ </div>
1546
+
1547
+ </div>
1548
+
1549
+ </body>
1550
+ </html>