passenger 3.0.0.pre2 → 3.0.0.pre3

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