passenger 5.1.10 → 5.1.11

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 (200) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +18 -0
  3. data/Rakefile +20 -17
  4. data/bin/passenger-install-apache2-module +14 -11
  5. data/build/agent.rb +45 -18
  6. data/build/apache2.rb +32 -16
  7. data/build/basics.rb +29 -40
  8. data/build/common_library.rb +70 -54
  9. data/build/cxx_tests.rb +34 -43
  10. data/build/integration_tests.rb +10 -10
  11. data/build/misc.rb +6 -6
  12. data/build/node_tests.rb +1 -2
  13. data/build/oxt_tests.rb +7 -5
  14. data/build/packaging.rb +11 -441
  15. data/build/ruby_extension.rb +1 -1
  16. data/build/ruby_tests.rb +1 -2
  17. data/build/support/cplusplus.rb +6 -5
  18. data/build/support/cxx_dependency_map.rb +357 -833
  19. data/build/support/general.rb +23 -1
  20. data/build/test_basics.rb +3 -28
  21. data/dev/ci/tests/rpm/Jenkinsfile +68 -0
  22. data/dev/ci/tests/rpm/run +63 -0
  23. data/dev/ci/tests/source-packaging/run +1 -1
  24. data/dev/ci/tests/source-packaging/setup +1 -1
  25. data/doc/{Packaging.txt.md → Packaging.md} +0 -0
  26. data/resources/templates/apache2/deployment_example.txt.erb +2 -2
  27. data/resources/templates/apache2/multiple_apache_installations_detected.txt.erb +2 -2
  28. data/resources/templates/nginx/deployment_example.txt.erb +1 -1
  29. data/resources/templates/standalone/mass_deployment_default_server.erb +2 -2
  30. data/resources/templates/standalone/server.erb +2 -2
  31. data/src/agent/AgentMain.cpp +0 -4
  32. data/src/agent/Core/CoreMain.cpp +88 -5
  33. data/src/agent/Core/SpawningKit/Spawner.h +2 -1
  34. data/src/agent/Shared/Fundamentals/AbortHandler.cpp +1109 -0
  35. data/src/agent/Shared/Fundamentals/AbortHandler.h +63 -0
  36. data/src/agent/Shared/Fundamentals/Implementation.cpp +7 -0
  37. data/src/agent/Shared/Fundamentals/Initialization.cpp +614 -0
  38. data/src/agent/Shared/{Base.h → Fundamentals/Initialization.h} +23 -14
  39. data/src/agent/Shared/Fundamentals/Utils.cpp +127 -0
  40. data/src/agent/Shared/Fundamentals/Utils.h +46 -0
  41. data/src/agent/TempDirToucher/TempDirToucherMain.cpp +1 -1
  42. data/src/agent/Watchdog/CoreWatcher.cpp +3 -1
  43. data/src/agent/Watchdog/InstanceDirToucher.cpp +90 -53
  44. data/src/agent/Watchdog/WatchdogMain.cpp +13 -29
  45. data/src/apache2_module/Hooks.cpp +4 -1
  46. data/src/cxx_supportlib/ConfigKit/Store.h +32 -5
  47. data/src/cxx_supportlib/Constants.h +1 -2
  48. data/src/cxx_supportlib/Crypto.cpp +2 -1
  49. data/src/cxx_supportlib/Hooks.h +16 -37
  50. data/src/cxx_supportlib/LoggingKit/Context.h +22 -0
  51. data/src/cxx_supportlib/LoggingKit/Forward.h +1 -0
  52. data/src/cxx_supportlib/LoggingKit/Implementation.cpp +106 -22
  53. data/src/cxx_supportlib/ProcessManagement/Ruby.cpp +106 -0
  54. data/src/{agent/UstRouter/FileSink.h → cxx_supportlib/ProcessManagement/Ruby.h} +23 -47
  55. data/src/cxx_supportlib/ProcessManagement/Spawn.cpp +199 -0
  56. data/src/cxx_supportlib/ProcessManagement/Spawn.h +150 -0
  57. data/src/cxx_supportlib/ProcessManagement/Utils.cpp +459 -0
  58. data/src/cxx_supportlib/ProcessManagement/Utils.h +107 -0
  59. data/src/cxx_supportlib/Utils.cpp +41 -561
  60. data/src/cxx_supportlib/Utils.h +0 -68
  61. data/src/cxx_supportlib/Utils/AsyncSignalSafeUtils.h +187 -0
  62. data/src/cxx_supportlib/Utils/ProcessMetricsCollector.h +14 -2
  63. data/src/cxx_supportlib/WatchdogLauncher.h +2 -12
  64. data/src/cxx_supportlib/oxt/dynamic_thread_group.hpp +2 -2
  65. data/src/cxx_supportlib/vendor-modified/jsoncpp/json-forwards.h +4 -0
  66. data/src/cxx_supportlib/vendor-modified/jsoncpp/json.h +16 -1
  67. data/src/cxx_supportlib/vendor-modified/jsoncpp/jsoncpp.cpp +12 -9
  68. data/src/cxx_supportlib/vendor-modified/libev/ev++.h +4 -4
  69. data/src/cxx_supportlib/vendor-modified/libev/ev.h +3 -3
  70. data/src/nginx_module/CacheLocationConfig.c +0 -75
  71. data/src/nginx_module/CacheLocationConfig.c.cxxcodebuilder +1 -0
  72. data/src/nginx_module/Configuration.c +0 -1
  73. data/src/nginx_module/Configuration.h +0 -1
  74. data/src/nginx_module/ConfigurationCommands.c +1 -1
  75. data/src/nginx_module/ContentHandler.c +0 -1
  76. data/src/nginx_module/ContentHandler.h +0 -1
  77. data/src/nginx_module/CreateLocationConfig.c +0 -5
  78. data/src/nginx_module/CreateLocationConfig.c.cxxcodebuilder +1 -0
  79. data/src/nginx_module/LocationConfig.h +0 -4
  80. data/src/nginx_module/LocationConfig.h.cxxcodebuilder +2 -1
  81. data/src/nginx_module/MergeLocationConfig.c +0 -12
  82. data/src/nginx_module/MergeLocationConfig.c.cxxcodebuilder +1 -0
  83. data/src/nginx_module/ngx_http_passenger_module.h +0 -1
  84. data/src/ruby_supportlib/phusion_passenger.rb +1 -1
  85. data/src/ruby_supportlib/phusion_passenger/common_library.rb +20 -11
  86. data/src/ruby_supportlib/phusion_passenger/config/api_call_command.rb +1 -1
  87. data/src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb +0 -1
  88. data/src/ruby_supportlib/phusion_passenger/config/validate_install_command.rb +10 -3
  89. data/src/ruby_supportlib/phusion_passenger/console_text_template.rb +3 -1
  90. data/src/ruby_supportlib/phusion_passenger/constants.rb +0 -1
  91. data/src/ruby_supportlib/phusion_passenger/debug_logging.rb +1 -1
  92. data/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +32 -6
  93. data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +0 -1
  94. data/src/ruby_supportlib/phusion_passenger/packaging.rb +2 -4
  95. data/src/ruby_supportlib/phusion_passenger/platform_info/apache.rb +101 -20
  96. data/src/ruby_supportlib/phusion_passenger/platform_info/apache_detector.rb +21 -9
  97. data/src/ruby_supportlib/phusion_passenger/platform_info/compiler.rb +34 -31
  98. data/src/ruby_supportlib/phusion_passenger/platform_info/cxx_portability.rb +3 -1
  99. data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +2 -14
  100. data/src/ruby_supportlib/phusion_passenger/platform_info/operating_system.rb +40 -3
  101. data/src/ruby_supportlib/phusion_passenger/standalone/app_finder.rb +15 -14
  102. data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +1 -1
  103. data/src/ruby_supportlib/phusion_passenger/standalone/config_utils.rb +1 -1
  104. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +8 -3
  105. data/src/ruby_supportlib/phusion_passenger/standalone/start_command/nginx_engine.rb +19 -18
  106. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +6 -1
  107. data/src/ruby_supportlib/phusion_passenger/vendor/daemon_controller.rb +17 -1
  108. metadata +19 -97
  109. data/build/documentation.rb +0 -70
  110. data/doc/CloudLicensingConfiguration.html +0 -172
  111. data/doc/CloudLicensingConfiguration.txt.md +0 -3
  112. data/doc/Packaging.html +0 -488
  113. data/doc/Security of user switching support.idmap.txt +0 -34
  114. data/doc/Security of user switching support.txt +0 -197
  115. data/doc/ServerOptimizationGuide.html +0 -172
  116. data/doc/ServerOptimizationGuide.txt.md +0 -3
  117. data/doc/images/by_sa.png +0 -0
  118. data/doc/images/cloud_licensing_batch_job.png +0 -0
  119. data/doc/images/code_walkthrough.jpg +0 -0
  120. data/doc/images/direct_spawning.png +0 -0
  121. data/doc/images/direct_spawning.svg +0 -251
  122. data/doc/images/glyphicons-halflings-white.png +0 -0
  123. data/doc/images/glyphicons-halflings.png +0 -0
  124. data/doc/images/icons/README +0 -5
  125. data/doc/images/icons/callouts/1.png +0 -0
  126. data/doc/images/icons/callouts/10.png +0 -0
  127. data/doc/images/icons/callouts/11.png +0 -0
  128. data/doc/images/icons/callouts/12.png +0 -0
  129. data/doc/images/icons/callouts/13.png +0 -0
  130. data/doc/images/icons/callouts/14.png +0 -0
  131. data/doc/images/icons/callouts/15.png +0 -0
  132. data/doc/images/icons/callouts/2.png +0 -0
  133. data/doc/images/icons/callouts/3.png +0 -0
  134. data/doc/images/icons/callouts/4.png +0 -0
  135. data/doc/images/icons/callouts/5.png +0 -0
  136. data/doc/images/icons/callouts/6.png +0 -0
  137. data/doc/images/icons/callouts/7.png +0 -0
  138. data/doc/images/icons/callouts/8.png +0 -0
  139. data/doc/images/icons/callouts/9.png +0 -0
  140. data/doc/images/icons/caution.png +0 -0
  141. data/doc/images/icons/example.png +0 -0
  142. data/doc/images/icons/home.png +0 -0
  143. data/doc/images/icons/important.png +0 -0
  144. data/doc/images/icons/next.png +0 -0
  145. data/doc/images/icons/note.png +0 -0
  146. data/doc/images/icons/prev.png +0 -0
  147. data/doc/images/icons/tip.png +0 -0
  148. data/doc/images/icons/up.png +0 -0
  149. data/doc/images/icons/warning.png +0 -0
  150. data/doc/images/many_web_framework_protocols.png +0 -0
  151. data/doc/images/passenger_architecture.png +0 -0
  152. data/doc/images/passenger_architecture.svg +0 -385
  153. data/doc/images/passenger_architecture_overview.png +0 -0
  154. data/doc/images/passenger_core_architecture.png +0 -0
  155. data/doc/images/passenger_nodejs_architecture.svg +0 -558
  156. data/doc/images/phusion_banner.png +0 -0
  157. data/doc/images/rack.png +0 -0
  158. data/doc/images/smart_spawning.png +0 -0
  159. data/doc/images/smart_spawning.svg +0 -323
  160. data/doc/images/spawn_server_architecture.png +0 -0
  161. data/doc/images/spawn_server_architecture.svg +0 -655
  162. data/doc/images/spawning_preparation_work.png +0 -0
  163. data/doc/images/startup_sequence.png +0 -0
  164. data/doc/images/typical_isolated_web_application.png +0 -0
  165. data/doc/images/typical_isolated_web_application.svg +0 -213
  166. data/doc/users_guide_snippets/alternative_for_flying_passenger.txt +0 -1
  167. data/doc/users_guide_snippets/analysis_and_system_maintenance.txt +0 -61
  168. data/doc/users_guide_snippets/appendix_a_about.txt +0 -13
  169. data/doc/users_guide_snippets/appendix_b_terminology.txt +0 -71
  170. data/doc/users_guide_snippets/appendix_c_spawning_methods.txt +0 -36
  171. data/doc/users_guide_snippets/deployment_basics.txt +0 -37
  172. data/doc/users_guide_snippets/enterprise_only.txt +0 -1
  173. data/doc/users_guide_snippets/environment_variables.txt +0 -44
  174. data/doc/users_guide_snippets/global_queueing_explained.txt +0 -74
  175. data/doc/users_guide_snippets/installation.txt +0 -228
  176. data/doc/users_guide_snippets/installation/run_installer.txt +0 -58
  177. data/doc/users_guide_snippets/installation/verify_running_epilogue.txt +0 -6
  178. data/doc/users_guide_snippets/passenger_spawn_method.txt +0 -37
  179. data/doc/users_guide_snippets/rackup_specifications.txt +0 -1
  180. data/doc/users_guide_snippets/rvm_helper_tool.txt +0 -44
  181. data/doc/users_guide_snippets/since_version.txt +0 -1
  182. data/doc/users_guide_snippets/support_information.txt +0 -8
  183. data/doc/users_guide_snippets/tips.txt +0 -302
  184. data/doc/users_guide_snippets/troubleshooting/default.txt +0 -48
  185. data/doc/users_guide_snippets/troubleshooting/rails.txt +0 -59
  186. data/doc/users_guide_snippets/under_the_hood/page_caching_support.txt +0 -24
  187. data/doc/users_guide_snippets/under_the_hood/relationship_with_ruby.txt +0 -10
  188. data/doc/users_guide_snippets/where_to_get_support.txt +0 -9
  189. data/src/agent/Shared/Base.cpp +0 -1678
  190. data/src/agent/UstRouter/ApiServer.h +0 -292
  191. data/src/agent/UstRouter/Client.h +0 -112
  192. data/src/agent/UstRouter/Controller.h +0 -1309
  193. data/src/agent/UstRouter/LogSink.h +0 -145
  194. data/src/agent/UstRouter/OptionParser.h +0 -180
  195. data/src/agent/UstRouter/RemoteSender.h +0 -853
  196. data/src/agent/UstRouter/RemoteSink.h +0 -145
  197. data/src/agent/UstRouter/Transaction.h +0 -278
  198. data/src/agent/UstRouter/UstRouterMain.cpp +0 -681
  199. data/src/agent/Watchdog/UstRouterWatcher.cpp +0 -80
  200. data/src/ruby_supportlib/phusion_passenger/platform_info/macos.rb +0 -45
@@ -321,73 +321,6 @@ string getHostName();
321
321
  */
322
322
  string getSignalName(int sig);
323
323
 
324
- /**
325
- * Resets the current process's signal handler disposition and signal mask
326
- * to default values. One should call this every time one forks a child process;
327
- * non-default signal masks/handler dispositions can cause all kinds of weird quirks,
328
- * like waitpid() malfunctioning on OS X.
329
- *
330
- * This function is async-signal safe.
331
- */
332
- void resetSignalHandlersAndMask();
333
-
334
- /**
335
- * Disables malloc() debugging facilities on OS X.
336
- */
337
- void disableMallocDebugging();
338
-
339
- /**
340
- * Like system(), but properly resets the signal handler mask,
341
- * disables malloc debugging and closes file descriptors > 2.
342
- * _command_ must be null-terminated.
343
- */
344
- int runShellCommand(const StaticString &command);
345
-
346
- /**
347
- * Run a command and capture its stdout output. This function
348
- * does not care whether the command fails.
349
- *
350
- * @param command The argument to pass to execvp().
351
- * @param status The status of the child process will be stored here, if non-NULL.
352
- * When unable to waitpid() the child process because of an ECHILD
353
- * or ESRCH, this will be set to -1.
354
- * @throws SystemException
355
- */
356
- string runCommandAndCaptureOutput(const char **command, int *status = NULL);
357
-
358
- /**
359
- * Async-signal safe way to fork().
360
- *
361
- * On Linux, the fork() glibc wrapper grabs a ptmalloc lock, so
362
- * if malloc causes a segfault then we can't fork.
363
- * http://sourceware.org/bugzilla/show_bug.cgi?id=4737
364
- *
365
- * OS X apparently does something similar, except they use a
366
- * spinlock so it results in 100% CPU. See _cthread_fork_prepare()
367
- * at http://www.opensource.apple.com/source/Libc/Libc-166/threads.subproj/cthreads.c
368
- * However, since POSIX in OS X is implemented on top of a Mach layer,
369
- * calling asyncFork() can mess up the state of the Mach layer, causing
370
- * some POSIX functions to mysteriously fail. See
371
- * https://code.google.com/p/phusion-passenger/issues/detail?id=1094
372
- * You should therefore not use asyncFork() unless you're in a signal
373
- * handler.
374
- */
375
- pid_t asyncFork();
376
-
377
- /**
378
- * Close all file descriptors that are higher than <em>lastToKeepOpen</em>.
379
- *
380
- * If you set `asyncSignalSafe` to true, then this function becomes fully async-signal,
381
- * through the use of asyncFork() instead of fork(). However, read the documentation
382
- * for asyncFork() to learn about its caveats.
383
- *
384
- * Also, regardless of whether `asyncSignalSafe` is true or not, this function is not
385
- * *thread* safe. Make sure there are no other threads running that might open file
386
- * descriptors, otherwise some file descriptors might not be closed even though they
387
- * should be.
388
- */
389
- void closeAllFileDescriptors(int lastToKeepOpen, bool asyncSignalSafe = false);
390
-
391
324
  /**
392
325
  * A no-op, but usually set as a breakpoint in gdb. See CONTRIBUTING.md.
393
326
  */
@@ -396,4 +329,3 @@ void breakpoint();
396
329
  } // namespace Passenger
397
330
 
398
331
  #endif /* _PASSENGER_UTILS_H_ */
399
-
@@ -0,0 +1,187 @@
1
+ /*
2
+ * Phusion Passenger - https://www.phusionpassenger.com/
3
+ * Copyright (c) 2010-2017 Phusion Holding B.V.
4
+ *
5
+ * "Passenger", "Phusion Passenger" and "Union Station" are registered
6
+ * trademarks of Phusion Holding B.V.
7
+ *
8
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
9
+ * of this software and associated documentation files (the "Software"), to deal
10
+ * in the Software without restriction, including without limitation the rights
11
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
+ * copies of the Software, and to permit persons to whom the Software is
13
+ * furnished to do so, subject to the following conditions:
14
+ *
15
+ * The above copyright notice and this permission notice shall be included in
16
+ * all copies or substantial portions of the Software.
17
+ *
18
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
+ * THE SOFTWARE.
25
+ */
26
+ #ifndef _PASSENGER_ASYNC_SIGNAL_SAFE_UTILS_H_
27
+ #define _PASSENGER_ASYNC_SIGNAL_SAFE_UTILS_H_
28
+
29
+ #include <cstdio>
30
+ #include <cerrno>
31
+ #include <unistd.h>
32
+
33
+ // We reimplement libc and some of our own utility functions here
34
+ // in an async signal-safe manner.
35
+
36
+ namespace Passenger {
37
+ namespace AsyncSignalSafeUtils {
38
+
39
+ using namespace std;
40
+
41
+
42
+ inline size_t
43
+ strlen(const char *str) {
44
+ size_t size = 0;
45
+ while (*str != '\0') {
46
+ str++;
47
+ size++;
48
+ }
49
+ return size;
50
+ }
51
+
52
+ // Just like the normal memcpy(), dest and src may not overlap.
53
+ inline void *
54
+ memcpy(void *dest, const void *src, size_t n) {
55
+ for (size_t i = 0; i < n; i++) {
56
+ ((char *) dest)[i] = ((const char *) src)[i];
57
+ }
58
+ return dest;
59
+ }
60
+
61
+ // In an async-signal-safe environment, there's nothing we can do if we fail to
62
+ // write to stderr, so we ignore its return value and we ignore compiler
63
+ // warnings about ignoring that.
64
+ inline void
65
+ writeNoWarn(int fd, const void *buf, size_t n) {
66
+ ssize_t ret = ::write(fd, buf, n);
67
+ (void) ret;
68
+ }
69
+
70
+ inline void
71
+ printError(const char *message, size_t len = (size_t) -1) {
72
+ if (len == (size_t) -1) {
73
+ len = strlen(message);
74
+ }
75
+ writeNoWarn(STDERR_FILENO, message, len);
76
+ }
77
+
78
+ inline void
79
+ reverseString(char *str, size_t len) {
80
+ char *p1, *p2;
81
+ if (len > 0 && *str == '\0') {
82
+ return;
83
+ }
84
+ for (p1 = str, p2 = str + len - 1; p2 > p1; ++p1, --p2) {
85
+ *p1 ^= *p2;
86
+ *p2 ^= *p1;
87
+ *p1 ^= *p2;
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Convert the given integer to some other radix, placing
93
+ * the result into the given output buffer. The output buffer
94
+ * will be NULL terminated. Supported radices are 2-36.
95
+ *
96
+ * @param outputSize The size of the output buffer, including space for
97
+ * the terminating NULL.
98
+ * @return The size of the created string excluding terminating NULL,
99
+ * or 0 if the output buffer is not large enough.
100
+ */
101
+ template<typename IntegerType, int radix>
102
+ size_t
103
+ integerToOtherBase(IntegerType value, char *output, size_t outputSize) {
104
+ static const char chars[] = {
105
+ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
106
+ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
107
+ 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
108
+ 'u', 'v', 'w', 'x', 'y', 'z'
109
+ };
110
+ IntegerType remainder = value;
111
+ unsigned int size = 0;
112
+
113
+ do {
114
+ output[size] = chars[remainder % radix];
115
+ remainder = remainder / radix;
116
+ size++;
117
+ } while (remainder != 0 && size < outputSize - 1);
118
+
119
+ if (remainder == 0) {
120
+ reverseString(output, size);
121
+ output[size] = '\0';
122
+ return size;
123
+ } else {
124
+ return 0;
125
+ }
126
+ }
127
+
128
+ inline char *
129
+ appendData(char *pos, const char *end, const char *data, size_t size = (size_t) -1) {
130
+ size_t maxToCopy;
131
+ if (size == (size_t) -1) {
132
+ size = strlen(data);
133
+ }
134
+ if (size_t(end - pos) < size) {
135
+ maxToCopy = end - pos;
136
+ } else {
137
+ maxToCopy = size;
138
+ }
139
+ memcpy(pos, data, maxToCopy);
140
+ return pos + size;
141
+ }
142
+
143
+ template<typename IntegerType, int radix>
144
+ inline char *
145
+ appendInteger(char *pos, const char *end, IntegerType value) {
146
+ return pos + integerToOtherBase<IntegerType, radix>(value, pos, end - pos);
147
+ }
148
+
149
+ /**
150
+ * Like `strerror()`, but only supports a limited number of errno codes.
151
+ * If the errno code is not supported then it returns `defaultResult`.
152
+ */
153
+ inline const char *
154
+ limitedStrerror(int e, const char *defaultResult = "Unknown error") {
155
+ switch (e) {
156
+ case E2BIG:
157
+ return "Argument list too long";
158
+ case EACCES:
159
+ return "Permission denied";
160
+ case EFAULT:
161
+ return "Bad address";
162
+ case EIO:
163
+ return "Input/output error";
164
+ case ELOOP:
165
+ return "Too many levels of symbolic links";
166
+ case ENAMETOOLONG:
167
+ return "File name too long";
168
+ case ENOENT:
169
+ return "No such file or directory";
170
+ case ENOEXEC:
171
+ return "Exec format error";
172
+ case ENOMEM:
173
+ return "Cannot allocate memory";
174
+ case ENOTDIR:
175
+ return "Not a directory";
176
+ case ETXTBSY:
177
+ return "Text file busy";
178
+ default:
179
+ return defaultResult;
180
+ }
181
+ }
182
+
183
+
184
+ } // namespace AsyncSignalSafeUtils
185
+ } // namespace Passenger
186
+
187
+ #endif /* _PASSENGER_ASYNC_SIGNAL_SAFE_UTILS_H_ */
@@ -60,7 +60,7 @@
60
60
 
61
61
  #include <StaticString.h>
62
62
  #include <Exceptions.h>
63
- #include <Utils.h>
63
+ #include <ProcessManagement/Spawn.h>
64
64
  #include <Utils/ScopeGuard.h>
65
65
  #include <Utils/IOUtils.h>
66
66
  #include <Utils/StringScanning.h>
@@ -249,6 +249,17 @@ private:
249
249
  return result;
250
250
  }
251
251
 
252
+ static void afterFork() {
253
+ // Make ps nicer, we want to have as little impact on the rest
254
+ // of the system as possible while collecting the metrics.
255
+ int prio = getpriority(PRIO_PROCESS, getpid());
256
+ prio++;
257
+ if (prio > 20) {
258
+ prio = 20;
259
+ }
260
+ setpriority(PRIO_PROCESS, getpid(), prio);
261
+ }
262
+
252
263
  public:
253
264
  ProcessMetricsCollector() {
254
265
  #ifdef __APPLE__
@@ -311,7 +322,8 @@ public:
311
322
 
312
323
  string psOutput = this->psOutput;
313
324
  if (psOutput.empty()) {
314
- psOutput = runCommandAndCaptureOutput(command);
325
+ SubprocessInfo info;
326
+ runCommandAndCaptureOutput(command, info, psOutput, true, afterFork);
315
327
  if (psOutput.empty()) {
316
328
  throw RuntimeException("The 'ps' command failed");
317
329
  }
@@ -106,6 +106,7 @@ void psg_watchdog_launcher_free(PsgWatchdogLauncher *launcher);
106
106
  #include <ResourceLocator.h>
107
107
  #include <LoggingKit/LoggingKit.h>
108
108
  #include <LoggingKit/Context.h>
109
+ #include <ProcessManagement/Utils.h>
109
110
  #include <Utils.h>
110
111
  #include <Utils/IOUtils.h>
111
112
  #include <Utils/MessageIO.h>
@@ -148,15 +149,6 @@ class WatchdogLauncher {
148
149
  P_RO_PROPERTY_CONST_REF(private, string, CoreAddress);
149
150
  P_RO_PROPERTY_CONST_REF(private, string, CorePassword);
150
151
 
151
- /**
152
- * The address on which the Passenger UstRouter listens, and the
153
- * corresponding password.
154
- *
155
- * Only valid when `getPid() != 0`.
156
- */
157
- P_RO_PROPERTY_CONST_REF(private, string, UstRouterAddress);
158
- P_RO_PROPERTY_CONST_REF(private, string, UstRouterPassword);
159
-
160
152
  /**
161
153
  * The path to the instance directory that the Watchdog has created.
162
154
  *
@@ -396,7 +388,7 @@ public:
396
388
 
397
389
  // Make sure the feedback fd is 3 and close all file descriptors
398
390
  // except stdin, stdout, stderr and 3.
399
- syscalls::close(fds[0]);
391
+ close(fds[0]);
400
392
  installFeedbackFd(fds[1]);
401
393
  closeAllFileDescriptors(FEEDBACK_FD);
402
394
 
@@ -498,8 +490,6 @@ public:
498
490
  mCoreAddress = info.get("core_address");
499
491
  mCorePassword = info.get("core_password");
500
492
  mInstanceDir = info.get("instance_dir");
501
- mUstRouterAddress = info.get("ust_router_address");
502
- mUstRouterPassword = info.get("ust_router_password");
503
493
  guard.clear();
504
494
  } else if (args[0] == "Watchdog startup error") {
505
495
  killProcessGroupAndWait(&pid, 5000);
@@ -210,7 +210,7 @@ public:
210
210
  unsigned int i = 0;
211
211
 
212
212
  // We make a copy so that the handles aren't destroyed prematurely.
213
- threads.reserve(nthreads);
213
+ threads.resize(nthreads);
214
214
  thread_handles_copy = thread_handles;
215
215
  for (it = thread_handles.begin(); it != thread_handles.end(); it++, i++) {
216
216
  handle = *it;
@@ -235,7 +235,7 @@ public:
235
235
  unsigned int i = 0;
236
236
 
237
237
  // We make a copy so that the handles aren't destroyed prematurely.
238
- threads.reserve(nthreads);
238
+ threads.resize(nthreads);
239
239
  thread_handles_copy = thread_handles;
240
240
  for (it = thread_handles.begin(); it != thread_handles.end(); it++, i++) {
241
241
  handle = *it;
@@ -231,6 +231,7 @@ license you like.
231
231
 
232
232
  #endif // if !defined(JSON_IS_AMALGAMATION)
233
233
 
234
+ namespace Passenger {
234
235
  namespace Json {
235
236
  typedef int Int;
236
237
  typedef unsigned int UInt;
@@ -265,6 +266,7 @@ typedef UInt64 LargestUInt;
265
266
  #define JSONCPP_ISTREAM std::istream
266
267
  #endif // if JSONCPP_USING_SECURE_MEMORY
267
268
  } // end namespace Json
269
+ } // end namespace Passenger
268
270
 
269
271
  #endif // JSON_CONFIG_H_INCLUDED
270
272
 
@@ -293,6 +295,7 @@ typedef UInt64 LargestUInt;
293
295
  #include "config.h"
294
296
  #endif // if !defined(JSON_IS_AMALGAMATION)
295
297
 
298
+ namespace Passenger {
296
299
  namespace Json {
297
300
 
298
301
  // writer.h
@@ -316,6 +319,7 @@ class ValueIterator;
316
319
  class ValueConstIterator;
317
320
 
318
321
  } // namespace Json
322
+ } // namespace Passenger
319
323
 
320
324
  #endif // JSON_FORWARDS_H_INCLUDED
321
325
 
@@ -264,6 +264,7 @@ license you like.
264
264
 
265
265
  #endif // if !defined(JSON_IS_AMALGAMATION)
266
266
 
267
+ namespace Passenger {
267
268
  namespace Json {
268
269
  typedef int Int;
269
270
  typedef unsigned int UInt;
@@ -298,6 +299,7 @@ typedef UInt64 LargestUInt;
298
299
  #define JSONCPP_ISTREAM std::istream
299
300
  #endif // if JSONCPP_USING_SECURE_MEMORY
300
301
  } // end namespace Json
302
+ } // end namespace Passenger
301
303
 
302
304
  #endif // JSON_CONFIG_H_INCLUDED
303
305
 
@@ -326,6 +328,7 @@ typedef UInt64 LargestUInt;
326
328
  #include "config.h"
327
329
  #endif // if !defined(JSON_IS_AMALGAMATION)
328
330
 
331
+ namespace Passenger {
329
332
  namespace Json {
330
333
 
331
334
  // writer.h
@@ -349,6 +352,7 @@ class ValueIterator;
349
352
  class ValueConstIterator;
350
353
 
351
354
  } // namespace Json
355
+ } // namespace Passenger
352
356
 
353
357
  #endif // JSON_FORWARDS_H_INCLUDED
354
358
 
@@ -379,6 +383,7 @@ class ValueConstIterator;
379
383
 
380
384
  #pragma pack(push, 8)
381
385
 
386
+ namespace Passenger {
382
387
  namespace Json {
383
388
 
384
389
  /** \brief Configuration passed to reader and writer.
@@ -422,6 +427,7 @@ public:
422
427
  };
423
428
 
424
429
  } // namespace Json
430
+ } // namespace Passenger
425
431
 
426
432
  #pragma pack(pop)
427
433
 
@@ -488,6 +494,7 @@ public:
488
494
 
489
495
  /** \brief JSON (JavaScript Object Notation).
490
496
  */
497
+ namespace Passenger {
491
498
  namespace Json {
492
499
 
493
500
  /** Base class for all exceptions we throw.
@@ -1295,12 +1302,13 @@ public:
1295
1302
  };
1296
1303
 
1297
1304
  } // namespace Json
1305
+ } // namespace Passenger
1298
1306
 
1299
1307
 
1300
1308
  namespace std {
1301
1309
  /// Specialize std::swap() for Json::Value.
1302
1310
  template<>
1303
- inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
1311
+ inline void swap(Passenger::Json::Value& a, Passenger::Json::Value& b) { a.swap(b); }
1304
1312
  }
1305
1313
 
1306
1314
  #pragma pack(pop)
@@ -1351,6 +1359,7 @@ inline void swap(Json::Value& a, Json::Value& b) { a.swap(b); }
1351
1359
 
1352
1360
  #pragma pack(push, 8)
1353
1361
 
1362
+ namespace Passenger {
1354
1363
  namespace Json {
1355
1364
 
1356
1365
  /** \brief Unserialize a <a HREF="http://www.json.org">JSON</a> document into a
@@ -1610,6 +1619,7 @@ public:
1610
1619
 
1611
1620
  Usage:
1612
1621
  \code
1622
+ using namespace Passenger;
1613
1623
  using namespace Json;
1614
1624
  CharReaderBuilder builder;
1615
1625
  builder["collectComments"] = false;
@@ -1724,6 +1734,7 @@ bool JSON_API parseFromStream(
1724
1734
  JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
1725
1735
 
1726
1736
  } // namespace Json
1737
+ } // namespace Passenger
1727
1738
 
1728
1739
  #pragma pack(pop)
1729
1740
 
@@ -1770,6 +1781,7 @@ JSON_API JSONCPP_ISTREAM& operator>>(JSONCPP_ISTREAM&, Value&);
1770
1781
 
1771
1782
  #pragma pack(push, 8)
1772
1783
 
1784
+ namespace Passenger {
1773
1785
  namespace Json {
1774
1786
 
1775
1787
  class Value;
@@ -1778,6 +1790,7 @@ class Value;
1778
1790
 
1779
1791
  Usage:
1780
1792
  \code
1793
+ using namespace Passenger;
1781
1794
  using namespace Json;
1782
1795
  void writeToStdout(StreamWriter::Factory const& factory, Value const& value) {
1783
1796
  std::unique_ptr<StreamWriter> const writer(
@@ -1823,6 +1836,7 @@ JSONCPP_STRING JSON_API writeString(StreamWriter::Factory const& factory, Value
1823
1836
 
1824
1837
  Usage:
1825
1838
  \code
1839
+ using namespace Passenger;
1826
1840
  using namespace Json;
1827
1841
  Value value = ...;
1828
1842
  StreamWriterBuilder builder;
@@ -2073,6 +2087,7 @@ JSONCPP_STRING JSON_API valueToQuotedString(const char* value);
2073
2087
  JSON_API JSONCPP_OSTREAM& operator<<(JSONCPP_OSTREAM&, const Value& root);
2074
2088
 
2075
2089
  } // namespace Json
2090
+ } // namespace Passenger
2076
2091
 
2077
2092
  #pragma pack(pop)
2078
2093