passenger 4.0.49 → 4.0.50

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 (77) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/CHANGELOG +7 -0
  5. data/build/test_basics.rb +1 -0
  6. data/ext/common/ApplicationPool2/Options.h +42 -39
  7. data/ext/common/Constants.h +1 -1
  8. data/helper-scripts/classic-rails-loader.rb +2 -1
  9. data/helper-scripts/classic-rails-preloader.rb +2 -1
  10. data/helper-scripts/node-loader.js +27 -5
  11. data/helper-scripts/rack-loader.rb +2 -1
  12. data/helper-scripts/rack-preloader.rb +2 -1
  13. data/helper-scripts/wsgi-loader.py +30 -7
  14. data/lib/phusion_passenger.rb +1 -1
  15. data/lib/phusion_passenger/active_support3_extensions/init.rb +1 -0
  16. data/lib/phusion_passenger/preloader_shared_helpers.rb +31 -9
  17. data/lib/phusion_passenger/request_handler.rb +31 -24
  18. data/lib/phusion_passenger/utils.rb +21 -9
  19. data/test/ruby/rails4.1/loader_spec.rb +28 -0
  20. data/test/ruby/rails4.1/preloader_spec.rb +34 -0
  21. data/test/ruby/request_handler_spec.rb +27 -25
  22. data/test/stub/rails4.1/.gitignore +16 -0
  23. data/test/stub/rails4.1/Gemfile +45 -0
  24. data/test/stub/rails4.1/Gemfile.lock +129 -0
  25. data/test/stub/rails4.1/README.rdoc +28 -0
  26. data/test/stub/rails4.1/Rakefile +6 -0
  27. data/test/stub/rails4.1/app/assets/images/.keep +0 -0
  28. data/test/stub/rails4.1/app/assets/javascripts/application.js +16 -0
  29. data/test/stub/rails4.1/app/assets/stylesheets/application.css +13 -0
  30. data/test/stub/rails4.1/app/controllers/application_controller.rb +5 -0
  31. data/test/stub/rails4.1/app/controllers/concerns/.keep +0 -0
  32. data/test/stub/rails4.1/app/helpers/application_helper.rb +2 -0
  33. data/test/stub/rails4.1/app/mailers/.keep +0 -0
  34. data/test/stub/rails4.1/app/models/.keep +0 -0
  35. data/test/stub/rails4.1/app/models/concerns/.keep +0 -0
  36. data/test/stub/rails4.1/app/views/layouts/application.html.erb +14 -0
  37. data/test/stub/rails4.1/bin/bundle +3 -0
  38. data/test/stub/rails4.1/bin/rails +4 -0
  39. data/test/stub/rails4.1/bin/rake +4 -0
  40. data/test/stub/rails4.1/config.ru +4 -0
  41. data/test/stub/rails4.1/config/application.rb +23 -0
  42. data/test/stub/rails4.1/config/boot.rb +4 -0
  43. data/test/stub/rails4.1/config/database.yml +25 -0
  44. data/test/stub/rails4.1/config/environment.rb +5 -0
  45. data/test/stub/rails4.1/config/environments/development.rb +29 -0
  46. data/test/stub/rails4.1/config/environments/production.rb +80 -0
  47. data/test/stub/rails4.1/config/environments/test.rb +36 -0
  48. data/test/stub/rails4.1/config/initializers/backtrace_silencers.rb +7 -0
  49. data/test/stub/rails4.1/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/test/stub/rails4.1/config/initializers/inflections.rb +16 -0
  51. data/test/stub/rails4.1/config/initializers/mime_types.rb +5 -0
  52. data/test/stub/rails4.1/config/initializers/passenger.rb +5 -0
  53. data/test/stub/rails4.1/config/initializers/secret_token.rb +12 -0
  54. data/test/stub/rails4.1/config/initializers/session_store.rb +3 -0
  55. data/test/stub/rails4.1/config/initializers/wrap_parameters.rb +14 -0
  56. data/test/stub/rails4.1/config/locales/en.yml +23 -0
  57. data/test/stub/rails4.1/config/routes.rb +57 -0
  58. data/test/stub/rails4.1/db/seeds.rb +7 -0
  59. data/test/stub/rails4.1/lib/assets/.keep +0 -0
  60. data/test/stub/rails4.1/lib/tasks/.keep +0 -0
  61. data/test/stub/rails4.1/log/.keep +0 -0
  62. data/test/stub/rails4.1/public/404.html +58 -0
  63. data/test/stub/rails4.1/public/422.html +58 -0
  64. data/test/stub/rails4.1/public/500.html +57 -0
  65. data/test/stub/rails4.1/public/favicon.ico +0 -0
  66. data/test/stub/rails4.1/public/robots.txt +5 -0
  67. data/test/stub/rails4.1/test/controllers/.keep +0 -0
  68. data/test/stub/rails4.1/test/fixtures/.keep +0 -0
  69. data/test/stub/rails4.1/test/helpers/.keep +0 -0
  70. data/test/stub/rails4.1/test/integration/.keep +0 -0
  71. data/test/stub/rails4.1/test/mailers/.keep +0 -0
  72. data/test/stub/rails4.1/test/models/.keep +0 -0
  73. data/test/stub/rails4.1/test/test_helper.rb +15 -0
  74. data/test/stub/rails4.1/vendor/assets/javascripts/.keep +0 -0
  75. data/test/stub/rails4.1/vendor/assets/stylesheets/.keep +0 -0
  76. metadata +58 -2
  77. metadata.gz.asc +7 -7
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- NzZiZGQzODhkNDZjNTUwZjM2M2VlMzI2OTQ3ZGI1NDA5ZmY3NjM1Ng==
4
+ YjJhMzI2NDM1MTlhN2QwZDE5YmZjOTI1YTAwMWU5NjhmYjBlZTdmMg==
5
5
  data.tar.gz: !binary |-
6
- NmMxNDdmNzY2MWNjYzllMDBmYzMyODUxZTIzZDA3MzY0ZjU3OTE1MQ==
6
+ NTEwMzNiNWM5MDlkYWUyNzE3ZTZjNWM1YThlMjg0NmE0ZTEwMGViYQ==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- NTBiZTUxOGE1MTRlMDUxZDljZDBhN2JjYTg3ZGFhODU3ZjM1ODZkMTUwMTcy
10
- ZDQwYzFiOTIyM2JiYzcwNjI2NGYwZThhM2NhYjQzNWY3YjEyYTg0MjljMjVm
11
- OWFlZGMzNmM2YjM5ODI2ODRiNzgzMmJmNGQ4ODY1ZmJmMmU3MGM=
9
+ ZjkwMjhmNzExYzNlNzA5ZjQ5MzA2YTQzMjNlY2I0Zjc0OWU4ZDYzNjVlNzE5
10
+ ZTg5NzBkZGY3NzU5NjU5ZTM0ZGM2MGU5YTg2ZjRjZmI1ZWM2MDBjNjg1ODUx
11
+ ZTRjNzJiYTdkZDcwNzlmYTNmNmQxNDQ0ODk3OTc0ODA1MDJiNzk=
12
12
  data.tar.gz: !binary |-
13
- NzRkYjE0OTg2M2VhYjIxMWQyMmFlODJlMjRlOGU5ODgyOWM5YjliM2NkODJj
14
- N2FjNWYwNjUyOGFlOGI2MTVmZGZkYjU1NTYxNzU5MjE2YzRjOGFkN2ZkM2M5
15
- YTI4OTZhYTUwODgyY2UwODliMDY1YmZhZDU2ODQ3NDJiODU2MDk=
13
+ YzYzOTVhOWVhNTYwY2FiMDU5YTA3NzFjYWJiMjQ3MmVhNmJjNmI5NDQ3ZDY5
14
+ M2U2OGRmZTA4NzllYmMzN2RkM2RkOWRiZmE5ZDM0MjJhYmQ0ODg5NmYxNWFj
15
+ OWM1YWQ2Mjg2OTVmZDY4ZTdhZmI5YmJlMGVkNDUzNzgyZTlmZTU=
checksums.yaml.gz.asc CHANGED
@@ -2,11 +2,11 @@
2
2
  Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABAgAGBQJT91guAAoJECrHRaUKISqMi8AIAKcJEymk64GyK27CR7KRYByH
6
- OTsizdQ5gTq2pETdjwDjAGn7T1lp1tWObakMbbOw4Fm0MU1kEMFFZg0GK0XTe2N+
7
- iF7T4tGP83pgUKNP3uuM4QPgfouVrRUGFNGJOsBiqIFKFTLdiBZkLDYQpOTU3+Q1
8
- ZIKKHbzzXoxKYdlpz+AP6OCurqrIIYGlaPmnEqafg1zP99K76HTGmQmL/j3e940q
9
- Sp8wPgBXpRDfv9f5oe9yRl46sCI61B+IFgubNG9ECrnTf/I1Qpe4jx7Xv65Ne6sJ
10
- EtHbZ5IwJyNnlIqzs7gX5lIIDlRUuA6pThkzD2zlf6em5mdDe4Yge8nn47/lMfI=
11
- =vGWc
5
+ iQEcBAABAgAGBQJT/ac4AAoJECrHRaUKISqMyBQIAI3940hdxJ7dL8kC+He5qLhk
6
+ RCpmZBZhmANL97OOVslpi3ZSMDE4lUsvn/oPD0T+zO1doaoxsus1CFaorT1vfzB9
7
+ 30MEMVXWUMMQ22aWSsWyTmtPL+0HUMRlAmVvgUFW8m27//irl8sIBXA2cFiIHhk+
8
+ 8b1OV1wlr6UEkqXmw2XKTyb6+rH9nU3Qhj1VZKsg/7kDCp9R7rNgxn7MuK0+JRUD
9
+ BfDmuovFnkhj+XssXbBGiTg1+n7/Ywie23uY+tmGNKE84S5ZA593BwJPJ8CzahHf
10
+ MKXpCKbr8fWA841sr/4M5BgoCiu4K+5b9VMwvU/K4YMR+pxk+doze9/rBoJara8=
11
+ =/3iD
12
12
  -----END PGP SIGNATURE-----
data.tar.gz.asc CHANGED
@@ -2,11 +2,11 @@
2
2
  Version: GnuPG/MacGPG2 v2.0.17 (Darwin)
3
3
  Comment: GPGTools - http://gpgtools.org
4
4
 
5
- iQEcBAABAgAGBQJT91guAAoJECrHRaUKISqMhbwIAKnAe12hzjsoxbOFMTXuX7GE
6
- EGEgQeVsTOkrWTJT7cPg+dcyyUCcNf9GggVARjCRpFOaUcTvwxi+kk53GcicOUex
7
- FKheeJe2cX7iwrS/yScE4sECFVYfz/tE0J78yhDlRGWPUYHg/0aRkPMIEIyxEoNl
8
- 4RuLoy12RMRRFoVa57sfZXzvui7HpGOKFkqvpo7mcKATkw8I+9bl5rAY4cSp0CBf
9
- RNfO3BvSRNUcV0dueiomegep+c4ANiks/w4kJ/I9rpjs5hi5Y/1jevnBZqpTjD3O
10
- Zhp2plPWifd2gAlasT7gzUdjg2MTnz10ejXpcgree80BcR7jAaCjwp0pQQjwxNI=
11
- =sAyH
5
+ iQEcBAABAgAGBQJT/ac4AAoJECrHRaUKISqMrpEH/126KVkt90cVfXkzNBSB7GxI
6
+ sMCmJK4iHgiTo8QDckXWXYqTGzlYvVN+90vw16aXJQadq4LZ7KEe3Nzon33ljR64
7
+ sJLak3Yiucr+y9QFJaHzfIegD0eZID2nFRxLpUebzsEZlmfpwa9oSkezacCGupEO
8
+ asIRMbNoEgzn4FXB9sGfNTCfVCz/xLVL2527BpZh2T/7kvyib6XtCUpW9uAQG94U
9
+ 9L1iOpKXST/gADAnYjJtTSG2TmF/rjqczDy9KgzJsTpFTImZL44ZLNw+wVvzKynt
10
+ GvvBNSXPL3OtAN0Cbh6+fSEP6O7pp9qtMd+KKZONY8Y3jyUb9evYprxeXucYh2A=
11
+ =7wtl
12
12
  -----END PGP SIGNATURE-----
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ Release 4.0.50
2
+ --------------
3
+
4
+ * Fixed a potential heap corruption bug.
5
+ * Added Union Station support for Rails 4.1.
6
+
7
+
1
8
  Release 4.0.49
2
9
  --------------
3
10
 
data/build/test_basics.rb CHANGED
@@ -75,6 +75,7 @@ task 'test:install_deps' do
75
75
 
76
76
  if ruby_version_int >= 190
77
77
  sh "cd test/stub/rails4.0 && bundle install"
78
+ sh "cd test/stub/rails4.1 && bundle install"
78
79
  end
79
80
  end
80
81
  if boolean_option('NODE_MODULES', default)
@@ -76,40 +76,41 @@ class Options {
76
76
  private:
77
77
  shared_array<char> storage;
78
78
 
79
- vector<const StaticString *> getStringFields() const {
80
- vector<const StaticString *> result;
79
+ template<typename OptionsClass, typename StaticStringClass>
80
+ static vector<StaticStringClass *> getStringFields(OptionsClass &options) {
81
+ vector<StaticStringClass *> result;
81
82
  result.reserve(20);
82
83
 
83
- result.push_back(&appRoot);
84
- result.push_back(&appGroupName);
85
- result.push_back(&appType);
86
- result.push_back(&startCommand);
87
- result.push_back(&startupFile);
88
- result.push_back(&processTitle);
89
-
90
- result.push_back(&environment);
91
- result.push_back(&baseURI);
92
- result.push_back(&spawnMethod);
93
-
94
- result.push_back(&user);
95
- result.push_back(&group);
96
- result.push_back(&defaultUser);
97
- result.push_back(&defaultGroup);
98
- result.push_back(&restartDir);
99
-
100
- result.push_back(&preexecChroot);
101
- result.push_back(&postexecChroot);
102
-
103
- result.push_back(&ruby);
104
- result.push_back(&python);
105
- result.push_back(&nodejs);
106
- result.push_back(&loggingAgentAddress);
107
- result.push_back(&loggingAgentUsername);
108
- result.push_back(&loggingAgentPassword);
109
- result.push_back(&groupSecret);
110
- result.push_back(&hostName);
111
- result.push_back(&uri);
112
- result.push_back(&unionStationKey);
84
+ result.push_back(&options.appRoot);
85
+ result.push_back(&options.appGroupName);
86
+ result.push_back(&options.appType);
87
+ result.push_back(&options.startCommand);
88
+ result.push_back(&options.startupFile);
89
+ result.push_back(&options.processTitle);
90
+
91
+ result.push_back(&options.environment);
92
+ result.push_back(&options.baseURI);
93
+ result.push_back(&options.spawnMethod);
94
+
95
+ result.push_back(&options.user);
96
+ result.push_back(&options.group);
97
+ result.push_back(&options.defaultUser);
98
+ result.push_back(&options.defaultGroup);
99
+ result.push_back(&options.restartDir);
100
+
101
+ result.push_back(&options.preexecChroot);
102
+ result.push_back(&options.postexecChroot);
103
+
104
+ result.push_back(&options.ruby);
105
+ result.push_back(&options.python);
106
+ result.push_back(&options.nodejs);
107
+ result.push_back(&options.loggingAgentAddress);
108
+ result.push_back(&options.loggingAgentUsername);
109
+ result.push_back(&options.loggingAgentPassword);
110
+ result.push_back(&options.groupSecret);
111
+ result.push_back(&options.hostName);
112
+ result.push_back(&options.uri);
113
+ result.push_back(&options.unionStationKey);
113
114
 
114
115
  return result;
115
116
  }
@@ -478,8 +479,9 @@ public:
478
479
  * area.
479
480
  */
480
481
  Options &persist(const Options &other) {
481
- const vector<const StaticString *> strings = getStringFields();
482
- const vector<const StaticString *> otherStrings = other.getStringFields();
482
+ vector<StaticString *> strings = getStringFields<Options, StaticString>(*this);
483
+ const vector<const StaticString *> otherStrings =
484
+ getStringFields<const Options, const StaticString>(other);
483
485
  unsigned int i;
484
486
  size_t otherLen = 0;
485
487
  char *end;
@@ -501,18 +503,19 @@ public:
501
503
 
502
504
  // Copy string fields into the internal storage area.
503
505
  for (i = 0; i < otherStrings.size(); i++) {
504
- const StaticString *str = strings[i];
506
+ const char *pos = end;
507
+ StaticString *str = strings[i];
505
508
  const StaticString *otherStr = otherStrings[i];
506
509
 
507
- // Point current object's field to the data in the
508
- // internal storage area.
509
- *const_cast<StaticString *>(str) = StaticString(end, otherStr->size());
510
-
511
510
  // Copy over the string data.
512
511
  memcpy(end, otherStr->c_str(), otherStr->size());
513
512
  end += otherStr->size();
514
513
  *end = '\0';
515
514
  end++;
515
+
516
+ // Point current object's field to the data in the
517
+ // internal storage area.
518
+ *str = StaticString(pos, end - pos - 1);
516
519
  }
517
520
 
518
521
  // Copy environmentVariables names and values into the internal storage area.
@@ -90,7 +90,7 @@
90
90
 
91
91
  #define NGINX_DOC_URL "https://www.phusionpassenger.com/documentation/Users%20guide%20Nginx.html"
92
92
 
93
- #define PASSENGER_VERSION "4.0.49"
93
+ #define PASSENGER_VERSION "4.0.50"
94
94
 
95
95
  #define POOL_HELPER_THREAD_STACK_SIZE 262144
96
96
 
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # Phusion Passenger - https://www.phusionpassenger.com/
3
- # Copyright (c) 2013 Phusion
3
+ # Copyright (c) 2013-2014 Phusion
4
4
  #
5
5
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
6
  #
@@ -159,6 +159,7 @@ module App
159
159
  LoaderSharedHelpers.advertise_sockets(STDOUT, handler)
160
160
  puts "!> "
161
161
  handler.main_loop
162
+ handler.cleanup
162
163
  LoaderSharedHelpers.after_handling_requests
163
164
 
164
165
  end # module App
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: utf-8
3
3
  # Phusion Passenger - https://www.phusionpassenger.com/
4
- # Copyright (c) 2013 Phusion
4
+ # Copyright (c) 2013-2014 Phusion
5
5
  #
6
6
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
7
7
  #
@@ -185,6 +185,7 @@ module App
185
185
  if PreloaderSharedHelpers.run_main_loop(options) == :forked
186
186
  handler = negotiate_spawn_command
187
187
  handler.main_loop
188
+ handler.cleanup
188
189
  LoaderSharedHelpers.after_handling_requests
189
190
  end
190
191
 
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Phusion Passenger - https://www.phusionpassenger.com/
3
- * Copyright (c) 2010-2013 Phusion
3
+ * Copyright (c) 2010-2014 Phusion
4
4
  *
5
5
  * "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
6
  *
@@ -25,6 +25,8 @@
25
25
 
26
26
  module.paths.unshift(__dirname + "/../node_lib");
27
27
  var EventEmitter = require('events').EventEmitter;
28
+ var os = require('os');
29
+ var fs = require('fs');
28
30
  var net = require('net');
29
31
  var http = require('http');
30
32
 
@@ -113,8 +115,9 @@ function configure(_options) {
113
115
  }
114
116
 
115
117
  function loadApplication() {
118
+ var appRoot = PhusionPassenger.options.app_root || process.cwd();
116
119
  var startupFile = PhusionPassenger.options.startup_file || 'app.js';
117
- require(PhusionPassenger.options.app_root + '/' + startupFile);
120
+ require(appRoot + '/' + startupFile);
118
121
  }
119
122
 
120
123
  function extractCallback(args) {
@@ -124,8 +127,21 @@ function extractCallback(args) {
124
127
  }
125
128
 
126
129
  function generateServerSocketPath() {
127
- return PhusionPassenger.options.generation_dir + "/backends/"
128
- + process.pid + "." + ((Math.random() * 0xFFFFFFFF) & 0xFFFFFFF);
130
+ var options = PhusionPassenger.options;
131
+ var socketDir, socketPrefix, socketSuffix;
132
+
133
+ if (options.generation_dir) {
134
+ socketDir = options.generation_dir + "/backends";
135
+ socketPrefix = "node";
136
+ } else {
137
+ socketDir = os.tmpdir().replace(/\/$/, '');
138
+ socketPrefix = "PsgNodeApp";
139
+ }
140
+ socketSuffix = ((Math.random() * 0xFFFFFFFF) & 0xFFFFFFF);
141
+
142
+ var result = socketDir + "/" + socketPrefix + "." + socketSuffix.toString(36);
143
+ var UNIX_PATH_MAX = options.UNIX_PATH_MAX || 100;
144
+ return result.substr(0, UNIX_PATH_MAX);
129
145
  }
130
146
 
131
147
  function addListenerAtBeginning(emitter, event, callback) {
@@ -176,8 +192,9 @@ function installServer() {
176
192
  }
177
193
  }
178
194
 
195
+ var socketPath = PhusionPassenger.options.socket_path = generateServerSocketPath();
179
196
  server.once('error', errorHandler);
180
- server.originalListen(generateServerSocketPath(), function() {
197
+ server.originalListen(socketPath, function() {
181
198
  server.removeListener('error', errorHandler);
182
199
  doneListening(callback);
183
200
  process.nextTick(finalizeStartup);
@@ -224,6 +241,11 @@ function finalizeStartup() {
224
241
  }
225
242
 
226
243
  function shutdown() {
244
+ try {
245
+ fs.unlinkSync(PhusionPassenger.options.socket_path);
246
+ } catch (e) {
247
+ // Ignore error.
248
+ }
227
249
  if (PhusionPassenger.listeners('exit').length == 0) {
228
250
  process.exit(0);
229
251
  } else {
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: binary
3
3
  # Phusion Passenger - https://www.phusionpassenger.com/
4
- # Copyright (c) 2013 Phusion
4
+ # Copyright (c) 2013-2014 Phusion
5
5
  #
6
6
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
7
7
  #
@@ -131,6 +131,7 @@ module App
131
131
  LoaderSharedHelpers.advertise_sockets(STDOUT, handler)
132
132
  puts "!> "
133
133
  handler.main_loop
134
+ handler.cleanup
134
135
  LoaderSharedHelpers.after_handling_requests
135
136
 
136
137
  end # module App
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: binary
3
3
  # Phusion Passenger - https://www.phusionpassenger.com/
4
- # Copyright (c) 2013 Phusion
4
+ # Copyright (c) 20132-2014 Phusion
5
5
  #
6
6
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
7
7
  #
@@ -159,6 +159,7 @@ module App
159
159
  if PreloaderSharedHelpers.run_main_loop(options) == :forked
160
160
  handler = negotiate_spawn_command
161
161
  handler.main_loop
162
+ handler.cleanup
162
163
  LoaderSharedHelpers.after_handling_requests
163
164
  end
164
165
 
@@ -23,6 +23,7 @@
23
23
  # THE SOFTWARE.
24
24
 
25
25
  import sys, os, re, imp, threading, signal, traceback, socket, select, struct, logging, errno
26
+ import tempfile
26
27
 
27
28
  options = {}
28
29
 
@@ -62,13 +63,31 @@ def load_app():
62
63
  def create_server_socket():
63
64
  global options
64
65
 
65
- filename = options['generation_dir'] + '/backends/wsgi.' + str(os.getpid())
66
- s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
67
- try:
68
- os.remove(filename)
69
- except OSError:
70
- pass
71
- s.bind(filename)
66
+ UNIX_PATH_MAX = options.get('UNIX_PATH_MAX', 100)
67
+ if 'generation_dir' in options:
68
+ socket_dir = options['generation_dir'] + '/backends'
69
+ socket_prefix = 'wsgi'
70
+ else:
71
+ socket_dir = tempfile.gettempdir()
72
+ socket_prefix = 'PsgWsgiApp'
73
+
74
+ i = 0
75
+ while i < 128:
76
+ s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
77
+ socket_suffix = format(struct.unpack('Q', os.urandom(8))[0], 'x')
78
+ filename = socket_dir + '/' + socket_prefix + '.' + socket_suffix
79
+ filename = filename[0:UNIX_PATH_MAX]
80
+ try:
81
+ s.bind(filename)
82
+ break
83
+ except socket.error as e:
84
+ if e.errno == errno.EADDRINUSE:
85
+ i += 1
86
+ if i == 128:
87
+ raise e
88
+ else:
89
+ raise e
90
+
72
91
  s.listen(1000)
73
92
  return (filename, s)
74
93
 
@@ -305,3 +324,7 @@ if __name__ == "__main__":
305
324
  print("!> Ready")
306
325
  advertise_sockets(socket_filename)
307
326
  handler.main_loop()
327
+ try:
328
+ os.remove(socket_filename)
329
+ except OSError:
330
+ pass
@@ -30,7 +30,7 @@ module PhusionPassenger
30
30
 
31
31
  PACKAGE_NAME = 'passenger'
32
32
  # Run 'rake ext/common/Constants.h' after changing this number.
33
- VERSION_STRING = '4.0.49'
33
+ VERSION_STRING = '4.0.50'
34
34
 
35
35
  PREFERRED_NGINX_VERSION = '1.6.1'
36
36
  NGINX_SHA256_CHECKSUM = 'f5cfe682a1aeef4602c2ca705402d5049b748f946563f41d8256c18674836067'
@@ -93,6 +93,7 @@ class UnionStationExtension < ActiveSupport::LogSubscriber
93
93
  end
94
94
 
95
95
  def initialize(options)
96
+ super()
96
97
  install_event_preprocessor(options[:event_preprocessor]) if options[:event_preprocessor]
97
98
  end
98
99
 
@@ -1,6 +1,6 @@
1
1
  # encoding: binary
2
2
  # Phusion Passenger - https://www.phusionpassenger.com/
3
- # Copyright (c) 2011, 2012 Phusion
3
+ # Copyright (c) 2011-2014 Phusion
4
4
  #
5
5
  # "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
6
  #
@@ -23,6 +23,8 @@
23
23
  # THE SOFTWARE.
24
24
 
25
25
  require 'socket'
26
+ require 'tmpdir'
27
+ PhusionPassenger.require_passenger_lib 'utils'
26
28
  PhusionPassenger.require_passenger_lib 'native_support'
27
29
 
28
30
  module PhusionPassenger
@@ -44,7 +46,7 @@ module PreloaderSharedHelpers
44
46
  end
45
47
  return options
46
48
  end
47
-
49
+
48
50
  def accept_and_process_next_client(server_socket)
49
51
  original_pid = Process.pid
50
52
  client = server_socket.accept
@@ -60,10 +62,10 @@ module PreloaderSharedHelpers
60
62
  while client.readline != "\n"
61
63
  # Do nothing.
62
64
  end
63
-
65
+
64
66
  # Improve copy-on-write friendliness.
65
67
  GC.start
66
-
68
+
67
69
  pid = fork
68
70
  if pid.nil?
69
71
  $0 = "#{$0} (forking...)"
@@ -91,15 +93,35 @@ module PreloaderSharedHelpers
91
93
  end
92
94
  end
93
95
  end
94
-
96
+
95
97
  def run_main_loop(options)
96
98
  $0 = "Passenger AppPreloader: #{options['app_root']}"
97
99
  client = nil
98
100
  original_pid = Process.pid
99
- socket_filename = "#{options['generation_dir']}/backends/preloader.#{Process.pid}"
100
- server = UNIXServer.new(socket_filename)
101
+
102
+ if defined?(NativeSupport)
103
+ unix_path_max = NativeSupport::UNIX_PATH_MAX
104
+ else
105
+ unix_path_max = options.fetch('UNIX_PATH_MAX', 100).to_i
106
+ end
107
+ if options['generation_dir']
108
+ socket_dir = "#{options['generation_dir']}/backends"
109
+ socket_prefix = "preloader"
110
+ else
111
+ socket_dir = Dir.tmpdir
112
+ socket_prefix = "PsgPreloader"
113
+ end
114
+
115
+ socket_filename = nil
116
+ server = nil
117
+ Utils.retry_at_most(128, Errno::EADDRINUSE) do
118
+ socket_filename = "#{socket_dir}/#{socket_prefix}.#{rand(0xFFFFFFFF).to_s(36)}"
119
+ socket_filename = socket_filename.slice(0, unix_path_max - 10)
120
+ server = UNIXServer.new(socket_filename)
121
+ end
101
122
  server.close_on_exec!
102
-
123
+ File.chmod(0600, socket_filename)
124
+
103
125
  # Update the dump information just before telling the preloader that we're
104
126
  # ready because the HelperAgent will read and memorize this information.
105
127
  LoaderSharedHelpers.dump_all_information
@@ -107,7 +129,7 @@ module PreloaderSharedHelpers
107
129
  puts "!> Ready"
108
130
  puts "!> socket: unix:#{socket_filename}"
109
131
  puts "!> "
110
-
132
+
111
133
  while true
112
134
  # We call ::select just in case someone overwrites the global select()
113
135
  # function by including ActionView::Helpers in the wrong place.