passenger 4.0.48 → 4.0.49

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 (218) hide show
  1. checksums.yaml +8 -8
  2. checksums.yaml.gz.asc +7 -7
  3. data.tar.gz.asc +7 -7
  4. data/.editorconfig +36 -2
  5. data/.travis.yml +1 -1
  6. data/CHANGELOG +16 -0
  7. data/Rakefile +0 -1
  8. data/build/apache2.rb +4 -4
  9. data/build/common_library.rb +18 -18
  10. data/build/cplusplus_support.rb +2 -2
  11. data/build/documentation.rb +1 -1
  12. data/build/integration_tests.rb +12 -4
  13. data/build/misc.rb +12 -7
  14. data/build/packaging.rb +14 -14
  15. data/build/preprocessor.rb +10 -10
  16. data/build/rake_extensions.rb +11 -11
  17. data/build/ruby_extension.rb +2 -2
  18. data/dev/ci/inituidgid +24 -0
  19. data/dev/ci/run_jenkins.sh +57 -0
  20. data/dev/ci/run_rpm_tests.sh +77 -0
  21. data/dev/{run_travis.sh → ci/run_travis.sh} +60 -4
  22. data/doc/Users guide Nginx.txt +2 -2
  23. data/doc/users_guide_snippets/environment_variables.txt +0 -2
  24. data/doc/users_guide_snippets/tips.txt +20 -1
  25. data/ext/apache2/Bucket.cpp +18 -18
  26. data/ext/apache2/Bucket.h +4 -4
  27. data/ext/apache2/Configuration.cpp +7 -7
  28. data/ext/apache2/Configuration.hpp +43 -43
  29. data/ext/apache2/DirectoryMapper.h +5 -5
  30. data/ext/apache2/Hooks.cpp +142 -142
  31. data/ext/apache2/MergeDirConfig.cpp +40 -40
  32. data/ext/common/Account.h +17 -17
  33. data/ext/common/AccountsDatabase.h +9 -9
  34. data/ext/common/AgentsStarter.cpp +2 -2
  35. data/ext/common/AgentsStarter.h +40 -40
  36. data/ext/common/ApplicationPool2/Common.h +10 -6
  37. data/ext/common/ApplicationPool2/ComponentInfo.h +2 -2
  38. data/ext/common/ApplicationPool2/DirectSpawner.h +17 -17
  39. data/ext/common/ApplicationPool2/DummySpawner.h +5 -5
  40. data/ext/common/ApplicationPool2/Group.h +54 -38
  41. data/ext/common/ApplicationPool2/Implementation.cpp +76 -49
  42. data/ext/common/ApplicationPool2/Options.h +98 -91
  43. data/ext/common/ApplicationPool2/Pool.h +70 -69
  44. data/ext/common/ApplicationPool2/Process.h +21 -21
  45. data/ext/common/ApplicationPool2/Session.h +11 -11
  46. data/ext/common/ApplicationPool2/SmartSpawner.h +60 -60
  47. data/ext/common/ApplicationPool2/Socket.h +19 -19
  48. data/ext/common/ApplicationPool2/Spawner.h +64 -72
  49. data/ext/common/ApplicationPool2/SpawnerFactory.h +4 -4
  50. data/ext/common/ApplicationPool2/SuperGroup.h +41 -41
  51. data/ext/common/BackgroundEventLoop.cpp +1 -1
  52. data/ext/common/BackgroundEventLoop.h +2 -2
  53. data/ext/common/Constants.h +1 -1
  54. data/ext/common/EventedBufferedInput.h +5 -5
  55. data/ext/common/EventedClient.h +51 -51
  56. data/ext/common/EventedMessageServer.h +39 -39
  57. data/ext/common/EventedServer.h +32 -32
  58. data/ext/common/Exceptions.h +23 -23
  59. data/ext/common/FileDescriptor.h +18 -18
  60. data/ext/common/Logging.cpp +1 -1
  61. data/ext/common/MessageClient.h +27 -27
  62. data/ext/common/MessageReadersWriters.h +79 -79
  63. data/ext/common/MessageServer.h +59 -59
  64. data/ext/common/RandomGenerator.h +12 -12
  65. data/ext/common/ResourceLocator.h +8 -8
  66. data/ext/common/SafeLibev.h +54 -25
  67. data/ext/common/ServerInstanceDir.h +31 -31
  68. data/ext/common/StaticString.h +50 -48
  69. data/ext/common/Utils.cpp +73 -78
  70. data/ext/common/Utils.h +6 -6
  71. data/ext/common/Utils/Base64.cpp +3 -3
  72. data/ext/common/Utils/Base64.h +7 -7
  73. data/ext/common/Utils/BlockingQueue.h +9 -9
  74. data/ext/common/Utils/BufferedIO.h +17 -17
  75. data/ext/common/Utils/CachedFileStat.hpp +16 -16
  76. data/ext/common/Utils/Dechunker.h +25 -25
  77. data/ext/common/Utils/FileChangeChecker.h +10 -10
  78. data/ext/common/Utils/MemZeroGuard.h +5 -5
  79. data/ext/common/Utils/MemoryBarrier.h +1 -1
  80. data/ext/common/Utils/MessageIO.h +61 -61
  81. data/ext/common/Utils/ProcessMetricsCollector.h +40 -40
  82. data/ext/common/Utils/ScopeGuard.h +7 -7
  83. data/ext/common/Utils/SpeedMeter.h +1 -1
  84. data/ext/common/Utils/StrIntUtils.cpp +13 -13
  85. data/ext/common/Utils/StrIntUtils.h +3 -3
  86. data/ext/common/Utils/StringScanning.h +5 -5
  87. data/ext/common/Utils/SystemMetricsCollector.h +2 -2
  88. data/ext/common/Utils/SystemTime.h +10 -10
  89. data/ext/common/Utils/Template.h +2 -2
  90. data/ext/common/Utils/Timer.h +6 -6
  91. data/ext/common/Utils/VariantMap.h +29 -29
  92. data/ext/common/agents/Base.cpp +19 -19
  93. data/ext/common/agents/HelperAgent/AgentOptions.h +1 -1
  94. data/ext/common/agents/HelperAgent/FileBackedPipe.h +6 -6
  95. data/ext/common/agents/HelperAgent/Main.cpp +44 -43
  96. data/ext/common/agents/HelperAgent/RequestHandler.cpp +4 -4
  97. data/ext/common/agents/HelperAgent/RequestHandler.h +29 -28
  98. data/ext/common/agents/HelperAgent/ScgiRequestParser.h +56 -50
  99. data/ext/common/agents/LoggingAgent/AdminController.h +8 -8
  100. data/ext/common/agents/LoggingAgent/DataStoreId.h +17 -17
  101. data/ext/common/agents/LoggingAgent/FilterSupport.h +167 -167
  102. data/ext/common/agents/LoggingAgent/LoggingServer.h +122 -122
  103. data/ext/common/agents/LoggingAgent/Main.cpp +7 -7
  104. data/ext/common/agents/LoggingAgent/RemoteSender.h +54 -54
  105. data/ext/common/agents/SpawnPreparer.cpp +4 -4
  106. data/ext/common/agents/TempDirToucher.c +2 -2
  107. data/ext/common/agents/Watchdog/AgentWatcher.cpp +47 -47
  108. data/ext/common/agents/Watchdog/HelperAgentWatcher.cpp +7 -7
  109. data/ext/common/agents/Watchdog/LoggingAgentWatcher.cpp +7 -7
  110. data/ext/common/agents/Watchdog/Main.cpp +22 -22
  111. data/ext/common/agents/Watchdog/ServerInstanceDirToucher.cpp +9 -9
  112. data/ext/libeio/eio.c +1 -1
  113. data/ext/nginx/Configuration.c +30 -30
  114. data/ext/nginx/Configuration.h +1 -1
  115. data/ext/nginx/ContentHandler.c +54 -54
  116. data/ext/nginx/ContentHandler.h +3 -3
  117. data/ext/nginx/StaticContentHandler.c +2 -2
  118. data/ext/nginx/ngx_http_passenger_module.c +21 -21
  119. data/ext/oxt/detail/backtrace_enabled.hpp +1 -1
  120. data/ext/oxt/detail/context.hpp +1 -1
  121. data/ext/oxt/detail/spin_lock_darwin.hpp +4 -4
  122. data/ext/oxt/detail/spin_lock_gcc_x86.hpp +3 -3
  123. data/ext/oxt/detail/spin_lock_pthreads.hpp +4 -4
  124. data/ext/oxt/detail/tracable_exception_disabled.hpp +1 -1
  125. data/ext/oxt/dynamic_thread_group.hpp +18 -18
  126. data/ext/oxt/implementation.cpp +9 -8
  127. data/ext/oxt/macros.hpp +2 -2
  128. data/ext/oxt/system_calls.cpp +11 -11
  129. data/ext/oxt/system_calls.hpp +13 -13
  130. data/ext/oxt/thread.hpp +22 -14
  131. data/ext/ruby/passenger_native_support.c +55 -55
  132. data/lib/phusion_passenger.rb +24 -24
  133. data/lib/phusion_passenger/common_library.rb +2 -0
  134. data/lib/phusion_passenger/loader_shared_helpers.rb +18 -18
  135. data/lib/phusion_passenger/packaging.rb +9 -4
  136. data/lib/phusion_passenger/platform_info/apache.rb +45 -31
  137. data/lib/phusion_passenger/platform_info/compiler.rb +11 -11
  138. data/lib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
  139. data/lib/phusion_passenger/request_handler/thread_handler.rb +8 -8
  140. data/lib/phusion_passenger/standalone/app_finder.rb +16 -16
  141. data/lib/phusion_passenger/standalone/command.rb +22 -22
  142. data/packaging/rpm/LICENSE.txt +19 -0
  143. data/packaging/rpm/Makefile +13 -0
  144. data/packaging/rpm/README.md +41 -0
  145. data/packaging/rpm/Vagrantfile +38 -0
  146. data/{rpm/Vagrantfile → packaging/rpm/Vagrantfile.centos} +0 -0
  147. data/packaging/rpm/build +170 -0
  148. data/packaging/rpm/create_project +41 -0
  149. data/packaging/rpm/git_update +88 -0
  150. data/packaging/rpm/image/Dockerfile +37 -0
  151. data/packaging/rpm/image/Gemfile +3 -0
  152. data/packaging/rpm/image/Gemfile.lock +12 -0
  153. data/packaging/rpm/image/RPM-GPG-KEY-amazon-ga +19 -0
  154. data/packaging/rpm/image/amazon2014-i386.cfg +96 -0
  155. data/packaging/rpm/image/amazon2014-x86_64.cfg +96 -0
  156. data/packaging/rpm/image/site-defaults.cfg +168 -0
  157. data/packaging/rpm/internal/build_tasks.rb +238 -0
  158. data/packaging/rpm/internal/dummygpg +11 -0
  159. data/packaging/rpm/internal/exec_build +42 -0
  160. data/packaging/rpm/internal/get_distro_arch +14 -0
  161. data/packaging/rpm/internal/get_distro_id +10 -0
  162. data/packaging/rpm/internal/git_update +27 -0
  163. data/packaging/rpm/internal/inituidgid +17 -0
  164. data/packaging/rpm/internal/my_init +344 -0
  165. data/packaging/rpm/internal/python27 +3 -0
  166. data/packaging/rpm/internal/repo_update +46 -0
  167. data/packaging/rpm/internal/setuser +26 -0
  168. data/packaging/rpm/internal/tracking_helper +40 -0
  169. data/packaging/rpm/jenkins_release +99 -0
  170. data/packaging/rpm/lib/build_tasks_support.rb +402 -0
  171. data/packaging/rpm/lib/preprocessor.rb +341 -0
  172. data/packaging/rpm/nginx_spec/404.html +119 -0
  173. data/packaging/rpm/nginx_spec/50x.html +119 -0
  174. data/packaging/rpm/nginx_spec/index.html +116 -0
  175. data/packaging/rpm/nginx_spec/nginx-auto-cc-gcc.patch +13 -0
  176. data/packaging/rpm/nginx_spec/nginx-logo.png +0 -0
  177. data/packaging/rpm/nginx_spec/nginx-upgrade +13 -0
  178. data/packaging/rpm/nginx_spec/nginx-upgrade.8 +151 -0
  179. data/packaging/rpm/nginx_spec/nginx.conf +131 -0
  180. data/packaging/rpm/nginx_spec/nginx.init +144 -0
  181. data/packaging/rpm/nginx_spec/nginx.logrotate +13 -0
  182. data/packaging/rpm/nginx_spec/nginx.service +15 -0
  183. data/packaging/rpm/nginx_spec/nginx.spec.template +559 -0
  184. data/packaging/rpm/nginx_spec/nginx.sysconfig +4 -0
  185. data/packaging/rpm/nginx_spec/passenger.conf +9 -0
  186. data/packaging/rpm/nginx_spec/poweredby.png +0 -0
  187. data/{rpm → packaging/rpm/passenger_spec}/apache-passenger.conf.in +0 -0
  188. data/{rpm → packaging/rpm/passenger_spec}/config.json +0 -0
  189. data/{rpm → packaging/rpm/passenger_spec}/passenger.logrotate +0 -0
  190. data/{rpm → packaging/rpm/passenger_spec}/passenger.spec.template +58 -31
  191. data/{rpm → packaging/rpm/passenger_spec}/passenger_dynamic_thread_group.patch +0 -0
  192. data/{rpm → packaging/rpm/passenger_spec}/passenger_tests_default_config_example.patch +0 -0
  193. data/{rpm → packaging/rpm/passenger_spec}/rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch +0 -0
  194. data/{rpm → packaging/rpm/passenger_spec}/rubygem-passenger-4.0.18-gcc47-include-sys_types.patch +0 -0
  195. data/packaging/rpm/repo_update +114 -0
  196. data/packaging/rpm/setup-system +60 -0
  197. data/packaging/rpm/shell +10 -0
  198. data/resources/templates/standalone/config.erb +3 -1
  199. data/test/config.json.rpm-automation +1 -1
  200. data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +11 -11
  201. data/test/cxx/ApplicationPool2/OptionsTest.cpp +5 -5
  202. data/test/cxx/ApplicationPool2/PoolTest.cpp +129 -89
  203. data/test/cxx/ApplicationPool2/ProcessTest.cpp +15 -15
  204. data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +22 -22
  205. data/test/cxx/ApplicationPool2/SpawnerTestCases.cpp +11 -11
  206. data/test/cxx/ScgiRequestParserTest.cpp +75 -61
  207. data/test/cxx/UtilsTest.cpp +86 -85
  208. data/test/gdbinit.example +3 -0
  209. data/test/integration_tests/nginx_tests.rb +3 -3
  210. data/test/integration_tests/source_packaging_test.rb +3 -1
  211. data/test/stub/nginx/nginx.conf.erb +8 -1
  212. data/test/support/nginx_controller.rb +7 -7
  213. metadata +62 -17
  214. metadata.gz.asc +7 -7
  215. data/build/rpm.rb +0 -128
  216. data/dev/rpmtool +0 -21
  217. data/dev/test_rpm_packaging.sh +0 -28
  218. data/rpm/get_distro_id.py +0 -4
@@ -176,7 +176,7 @@ initializePrivilegedWorkingObjects(WorkingObjects &wo) {
176
176
  } while (ret == -1 && errno == EINTR);
177
177
  }
178
178
 
179
- wo.adminAccountsDatabase = boost::make_shared<AccountsDatabase>();
179
+ wo.adminAccountsDatabase = boost::make_shared<AccountsDatabase>();
180
180
  wo.adminAccountsDatabase->add("_passenger-status", adminToolStatusPassword, false);
181
181
  wo.adminServer = boost::make_shared<MessageServer>(parseUnixSocketAddress(adminSocketAddress),
182
182
  wo.adminAccountsDatabase);
@@ -185,7 +185,7 @@ initializePrivilegedWorkingObjects(WorkingObjects &wo) {
185
185
  static void
186
186
  lowerPrivilege(const string &username, const struct passwd *user, gid_t gid) {
187
187
  int e;
188
-
188
+
189
189
  if (initgroups(username.c_str(), gid) != 0) {
190
190
  e = errno;
191
191
  P_WARN("WARNING: Unable to set supplementary groups for " <<
@@ -216,7 +216,7 @@ maybeLowerPrivilege() {
216
216
  gid_t gid;
217
217
 
218
218
  /* Sanity check user accounts. */
219
-
219
+
220
220
  user = getpwnam(username.c_str());
221
221
  if (user == NULL) {
222
222
  throw NonExistentUserException(string("The configuration option ") +
@@ -225,7 +225,7 @@ maybeLowerPrivilege() {
225
225
  username + "', but this user doesn't exist. Please fix " +
226
226
  "the configuration option.");
227
227
  }
228
-
228
+
229
229
  if (groupname.empty()) {
230
230
  gid = user->pw_gid;
231
231
  groupname = getGroupName(user->pw_gid);
@@ -249,7 +249,7 @@ maybeLowerPrivilege() {
249
249
  static struct ev_loop *
250
250
  createEventLoop() {
251
251
  struct ev_loop *loop;
252
-
252
+
253
253
  // libev doesn't like choosing epoll and kqueue because the author thinks they're broken,
254
254
  // so let's try to force it.
255
255
  loop = ev_default_loop(EVBACKEND_EPOLL);
@@ -310,14 +310,14 @@ runMainLoop(WorkingObjects &wo) {
310
310
  ev::sig sigintWatcher(eventLoop);
311
311
  ev::sig sigtermWatcher(eventLoop);
312
312
  ev::sig sigquitWatcher(eventLoop);
313
-
313
+
314
314
  sigintWatcher.set<&caughtExitSignal>();
315
315
  sigintWatcher.start(SIGINT);
316
316
  sigtermWatcher.set<&caughtExitSignal>();
317
317
  sigtermWatcher.start(SIGTERM);
318
318
  sigquitWatcher.set<&printInfo>();
319
319
  sigquitWatcher.start(SIGQUIT);
320
-
320
+
321
321
  P_WARN("PassengerLoggingAgent online, listening at " << socketAddress);
322
322
  if (feedbackFdAvailable()) {
323
323
  feedbackFdWatcher.set<&feedbackFdBecameReadable>();
@@ -64,29 +64,29 @@ private:
64
64
  string nodeName;
65
65
  string category;
66
66
  string data;
67
-
67
+
68
68
  Item() {
69
69
  exit = false;
70
70
  compressed = false;
71
71
  }
72
72
  };
73
-
73
+
74
74
  class Server {
75
75
  private:
76
76
  string ip;
77
77
  unsigned short port;
78
78
  string certificate;
79
79
  const CurlProxyInfo *proxyInfo;
80
-
80
+
81
81
  CURL *curl;
82
82
  struct curl_slist *headers;
83
83
  char lastErrorMessage[CURL_ERROR_SIZE];
84
84
  string hostHeader;
85
85
  string responseBody;
86
-
86
+
87
87
  string pingURL;
88
88
  string sinkURL;
89
-
89
+
90
90
  void resetConnection() {
91
91
  if (curl != NULL) {
92
92
  #ifdef HAS_CURL_EASY_RESET
@@ -122,7 +122,7 @@ private:
122
122
  setCurlProxy(curl, *proxyInfo);
123
123
  responseBody.clear();
124
124
  }
125
-
125
+
126
126
  void prepareRequest(const string &url) {
127
127
  curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
128
128
  responseBody.clear();
@@ -181,13 +181,13 @@ private:
181
181
  P_ERROR("Could not send data to Union Station gateway server " << ip
182
182
  << ": " << lastErrorMessage);
183
183
  }
184
-
184
+
185
185
  static size_t curlDataReceived(void *buffer, size_t size, size_t nmemb, void *userData) {
186
186
  Server *self = (Server *) userData;
187
187
  self->responseBody.append((const char *) buffer, size * nmemb);
188
188
  return size * nmemb;
189
189
  }
190
-
190
+
191
191
  public:
192
192
  Server(const string &ip, const string &hostName, unsigned short port, const string &cert,
193
193
  const CurlProxyInfo *proxyInfo)
@@ -196,25 +196,25 @@ private:
196
196
  this->port = port;
197
197
  certificate = cert;
198
198
  this->proxyInfo = proxyInfo;
199
-
199
+
200
200
  hostHeader = "Host: " + hostName;
201
201
  headers = NULL;
202
202
  headers = curl_slist_append(headers, hostHeader.c_str());
203
203
  if (headers == NULL) {
204
204
  throw IOException("Unable to create a CURL linked list");
205
205
  }
206
-
207
- // Older libcurl versions didn't strdup() any option
206
+
207
+ // Older libcurl versions didn't strdup() any option
208
208
  // strings so we need to keep these in memory.
209
209
  pingURL = string("https://") + ip + ":" + toString(port) +
210
210
  "/ping";
211
211
  sinkURL = string("https://") + ip + ":" + toString(port) +
212
212
  "/sink";
213
-
213
+
214
214
  curl = NULL;
215
215
  resetConnection();
216
216
  }
217
-
217
+
218
218
  ~Server() {
219
219
  if (curl != NULL) {
220
220
  curl_easy_cleanup(curl);
@@ -225,12 +225,12 @@ private:
225
225
  string name() const {
226
226
  return ip + ":" + toString(port);
227
227
  }
228
-
228
+
229
229
  bool ping() {
230
230
  P_DEBUG("Pinging Union Station gateway " << ip << ":" << port);
231
231
  ScopeGuard guard(boost::bind(&Server::resetConnection, this));
232
232
  prepareRequest(pingURL);
233
-
233
+
234
234
  curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
235
235
  if (curl_easy_perform(curl) != 0) {
236
236
  P_DEBUG("Could not ping Union Station gateway server " << ip
@@ -247,7 +247,7 @@ private:
247
247
  return false;
248
248
  }
249
249
  }
250
-
250
+
251
251
  /** Returns true if the server is up, false if the server is down.
252
252
  * The return value does NOT indicate whether the server accepted the data!
253
253
  * Thus, if (for example) the Union Station key is invalid or disabled,
@@ -259,11 +259,11 @@ private:
259
259
  bool send(const Item &item) {
260
260
  ScopeGuard guard(boost::bind(&Server::resetConnection, this));
261
261
  prepareRequest(sinkURL);
262
-
262
+
263
263
  struct curl_httppost *post = NULL;
264
264
  struct curl_httppost *last = NULL;
265
265
  string base64_data;
266
-
266
+
267
267
  curl_formadd(&post, &last,
268
268
  CURLFORM_PTRNAME, "key",
269
269
  CURLFORM_PTRCONTENTS, item.unionStationKey.c_str(),
@@ -297,7 +297,7 @@ private:
297
297
  CURLFORM_CONTENTSLENGTH, (long) item.data.size(),
298
298
  CURLFORM_END);
299
299
  }
300
-
300
+
301
301
  curl_easy_setopt(curl, CURLOPT_HTTPGET, 0);
302
302
  curl_easy_setopt(curl, CURLOPT_HTTPPOST, post);
303
303
  P_DEBUG("Sending Union Station packet: key=" << item.unionStationKey <<
@@ -305,7 +305,7 @@ private:
305
305
  ", compressedDataSize=" << item.data.size());
306
306
  CURLcode code = curl_easy_perform(curl);
307
307
  curl_formfree(post);
308
-
308
+
309
309
  if (code == CURLE_OK) {
310
310
  guard.clear();
311
311
  return handleSendResponse();
@@ -315,35 +315,35 @@ private:
315
315
  }
316
316
  }
317
317
  };
318
-
318
+
319
319
  typedef boost::shared_ptr<Server> ServerPtr;
320
-
320
+
321
321
  string gatewayAddress;
322
322
  unsigned short gatewayPort;
323
323
  string certificate;
324
324
  CurlProxyInfo proxyInfo;
325
325
  BlockingQueue<Item> queue;
326
326
  oxt::thread *thr;
327
-
327
+
328
328
  mutable boost::mutex syncher;
329
329
  list<ServerPtr> servers;
330
330
  time_t nextCheckupTime;
331
331
  unsigned int packetsSent, packetsDropped;
332
-
332
+
333
333
  void threadMain() {
334
334
  ScopeGuard guard(boost::bind(&RemoteSender::freeThreadData, this));
335
-
335
+
336
336
  while (true) {
337
337
  Item item;
338
338
  bool hasItem;
339
-
339
+
340
340
  if (firstStarted()) {
341
341
  item = queue.get();
342
342
  hasItem = true;
343
343
  } else {
344
344
  hasItem = queue.timedGet(item, msecUntilNextCheckup());
345
345
  }
346
-
346
+
347
347
  if (hasItem) {
348
348
  if (item.exit) {
349
349
  return;
@@ -358,24 +358,24 @@ private:
358
358
  }
359
359
  }
360
360
  }
361
-
361
+
362
362
  bool firstStarted() const {
363
363
  boost::lock_guard<boost::mutex> l(syncher);
364
364
  return nextCheckupTime == 0;
365
365
  }
366
-
366
+
367
367
  void recheckServers() {
368
368
  P_INFO("Rechecking Union Station gateway servers (" << gatewayAddress << ")...");
369
-
369
+
370
370
  vector<string> ips;
371
371
  vector<string>::const_iterator it;
372
372
  list<ServerPtr> servers;
373
373
  string hostName;
374
374
  bool someServersAreDown = false;
375
-
375
+
376
376
  ips = resolveHostname(gatewayAddress, gatewayPort);
377
377
  P_INFO(ips.size() << " Union Station gateway servers found");
378
-
378
+
379
379
  for (it = ips.begin(); it != ips.end(); it++) {
380
380
  ServerPtr server = boost::make_shared<Server>(*it, gatewayAddress, gatewayPort,
381
381
  certificate, &proxyInfo);
@@ -386,7 +386,7 @@ private:
386
386
  }
387
387
  }
388
388
  P_INFO(servers.size() << " Union Station gateway servers are up");
389
-
389
+
390
390
  if (servers.empty()) {
391
391
  scheduleNextCheckup(5 * 60);
392
392
  } else if (someServersAreDown) {
@@ -398,12 +398,12 @@ private:
398
398
  boost::lock_guard<boost::mutex> l(syncher);
399
399
  this->servers = servers;
400
400
  }
401
-
401
+
402
402
  void freeThreadData() {
403
403
  boost::lock_guard<boost::mutex> l(syncher);
404
404
  servers.clear(); // Invoke destructors inside this thread.
405
405
  }
406
-
406
+
407
407
  /**
408
408
  * Schedules the next checkup to be run after the given number
409
409
  * of seconds, unless there's already a checkup scheduled for
@@ -416,7 +416,7 @@ private:
416
416
  P_DEBUG("Next checkup time in about " << seconds << " seconds");
417
417
  }
418
418
  }
419
-
419
+
420
420
  unsigned int msecUntilNextCheckup() const {
421
421
  boost::lock_guard<boost::mutex> l(syncher);
422
422
  time_t now = SystemTime::get();
@@ -426,17 +426,17 @@ private:
426
426
  return (nextCheckupTime - now) * 1000;
427
427
  }
428
428
  }
429
-
429
+
430
430
  bool timeForCheckup() const {
431
431
  boost::lock_guard<boost::mutex> l(syncher);
432
432
  return SystemTime::get() >= nextCheckupTime;
433
433
  }
434
-
434
+
435
435
  void sendOut(const Item &item) {
436
436
  boost::unique_lock<boost::mutex> l(syncher);
437
437
  bool sent = false;
438
438
  bool someServersWentDown = false;
439
-
439
+
440
440
  while (!sent && !servers.empty()) {
441
441
  // Pick first available server and put it on the back of the list
442
442
  // for round-robin load balancing.
@@ -455,7 +455,7 @@ private:
455
455
  packetsDropped++;
456
456
  }
457
457
  }
458
-
458
+
459
459
  if (someServersWentDown) {
460
460
  if (servers.empty()) {
461
461
  scheduleNextCheckup(5 * 60);
@@ -463,7 +463,7 @@ private:
463
463
  scheduleNextCheckup(60 * 60);
464
464
  }
465
465
  }
466
-
466
+
467
467
  /* If all servers went down then all items in the queue will be
468
468
  * effectively dropped until after the next checkup has detected
469
469
  * servers that are up.
@@ -476,18 +476,18 @@ private:
476
476
  ", compressedDataSize=" << item.data.size());
477
477
  }
478
478
  }
479
-
479
+
480
480
  bool compress(const StaticString data[], unsigned int count, string &output) {
481
481
  if (count == 0) {
482
482
  StaticString newdata;
483
483
  return compress(&newdata, 1, output);
484
484
  }
485
-
485
+
486
486
  unsigned char out[128 * 1024];
487
487
  z_stream strm;
488
488
  int ret, flush;
489
489
  unsigned int i, have;
490
-
490
+
491
491
  strm.zalloc = Z_NULL;
492
492
  strm.zfree = Z_NULL;
493
493
  strm.opaque = Z_NULL;
@@ -495,12 +495,12 @@ private:
495
495
  if (ret != Z_OK) {
496
496
  return false;
497
497
  }
498
-
498
+
499
499
  for (i = 0; i < count; i++) {
500
500
  strm.avail_in = data[i].size();
501
501
  strm.next_in = (unsigned char *) data[i].c_str();
502
502
  flush = (i == count - 1) ? Z_FINISH : Z_NO_FLUSH;
503
-
503
+
504
504
  do {
505
505
  strm.avail_out = sizeof(out);
506
506
  strm.next_out = out;
@@ -512,11 +512,11 @@ private:
512
512
  assert(strm.avail_in == 0);
513
513
  }
514
514
  assert(ret == Z_STREAM_END);
515
-
515
+
516
516
  deflateEnd(&strm);
517
517
  return true;
518
518
  }
519
-
519
+
520
520
  public:
521
521
  RemoteSender(const string &gatewayAddress, unsigned short gatewayPort, const string &certificate,
522
522
  const string &proxyAddress)
@@ -541,7 +541,7 @@ public:
541
541
  1024 * 512
542
542
  );
543
543
  }
544
-
544
+
545
545
  ~RemoteSender() {
546
546
  Item item;
547
547
  item.exit = true;
@@ -554,7 +554,7 @@ public:
554
554
  thr->join();
555
555
  delete thr;
556
556
  }
557
-
557
+
558
558
  void schedule(const string &unionStationKey, const StaticString &nodeName,
559
559
  const StaticString &category, const StaticString data[],
560
560
  unsigned int count)
@@ -564,13 +564,13 @@ public:
564
564
  item.unionStationKey = unionStationKey;
565
565
  item.nodeName = nodeName;
566
566
  item.category = category;
567
-
567
+
568
568
  if (compress(data, count, item.data)) {
569
569
  item.compressed = true;
570
570
  } else {
571
571
  size_t size = 0;
572
572
  unsigned int i;
573
-
573
+
574
574
  for (i = 0; i < count; i++) {
575
575
  size += data[i].size();
576
576
  }
@@ -579,7 +579,7 @@ public:
579
579
  item.data.append(data[i].c_str(), data[i].size());
580
580
  }
581
581
  }
582
-
582
+
583
583
  P_DEBUG("Scheduling Union Station packet: key=" << unionStationKey <<
584
584
  ", node=" << nodeName << ", category=" << category <<
585
585
  ", compressedDataSize=" << item.data.size());
@@ -590,7 +590,7 @@ public:
590
590
  packetsDropped++;
591
591
  }
592
592
  }
593
-
593
+
594
594
  unsigned int queued() const {
595
595
  return queue.size();
596
596
  }
@@ -73,7 +73,7 @@ setGivenEnvVars(const char *envvarsData) {
73
73
  string envvars = Base64::decode(envvarsData);
74
74
  const char *key = envvars.data();
75
75
  const char *end = envvars.data() + envvars.size();
76
-
76
+
77
77
  while (key < end) {
78
78
  const char *keyEnd = (const char *) memchr(key, '\0', end - key);
79
79
  if (keyEnd != NULL) {
@@ -181,16 +181,16 @@ main(int argc, char *argv[]) {
181
181
  fprintf(stderr, "Too few arguments.\n");
182
182
  exit(1);
183
183
  }
184
-
184
+
185
185
  const char *workingDir = argv[1];
186
186
  const char *envvars = argv[2];
187
187
  const char *executable = argv[3];
188
188
  char **execArgs = &argv[4];
189
-
189
+
190
190
  changeWorkingDir(workingDir);
191
191
  setGivenEnvVars(envvars);
192
192
  dumpInformation();
193
-
193
+
194
194
  // Print a newline just in case whatever executed us printed data
195
195
  // without a newline. Otherwise the next process's "!> I have control"
196
196
  // command will not be properly recognized.