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
@@ -23,37 +23,46 @@
23
23
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24
24
  * THE SOFTWARE.
25
25
  */
26
- #ifndef _PASSENGER_AGENT_BASE_H_
27
- #define _PASSENGER_AGENT_BASE_H_
26
+ #ifndef _PASSENGER_AGENT_FUNDAMENTALS_INITIALIZATION_H_
27
+ #define _PASSENGER_AGENT_FUNDAMENTALS_INITIALIZATION_H_
28
28
 
29
29
  /** Common initialization code for all agents. */
30
30
 
31
31
  #include <cstddef>
32
32
  #include <Utils/VariantMap.h>
33
+ #include <Shared/Fundamentals/AbortHandler.h>
33
34
 
34
35
  namespace Passenger {
36
+ namespace Agent {
37
+ namespace Fundamentals {
38
+
39
+
40
+ struct Context {
41
+ ResourceLocator *resourceLocator;
42
+ unsigned int randomSeed;
43
+ int origArgc;
44
+ char **origArgv;
45
+ bool feedbackFdAvailable;
46
+ AbortHandlerConfig abortHandlerConfig;
47
+ };
35
48
 
36
- typedef void (*DiagnosticsDumper)(void *userData);
37
49
  typedef void (*OptionParserFunc)(int argc, const char **argv, VariantMap &options);
38
50
  typedef void (*PreinitializationFunc)(VariantMap &options);
39
51
 
40
- const char *getEnvString(const char *name, const char *defaultValue = NULL);
41
- bool hasEnvOption(const char *name, bool defaultValue = false);
52
+ extern Context *context;
53
+
42
54
 
43
- bool feedbackFdAvailable();
44
55
  VariantMap initializeAgent(int argc, char **argv[], const char *processName,
45
56
  OptionParserFunc optionParser = NULL, PreinitializationFunc preinit = NULL,
46
57
  int argStartIndex = 1);
47
- void initializeAgentOptions(const char *processName, VariantMap &options,
48
- PreinitializationFunc preinit = NULL);
49
- void storeArgvCopy(int argc, char *argv[]);
50
- void installAgentAbortHandler();
51
- void installDiagnosticsDumper(DiagnosticsDumper func, void *userData);
52
-
53
58
  void shutdownAgent(VariantMap *agentOptions);
54
59
 
60
+ bool feedbackFdAvailable();
55
61
  void restoreOomScore(VariantMap *agentOptions);
56
62
 
57
- }
58
63
 
59
- #endif /* _PASSENGER_AGENT_BASE_H_ */
64
+ } // namespace Fundamentals
65
+ } // namespace Agent
66
+ } // namespace Passenger
67
+
68
+ #endif /* _PASSENGER_AGENT_FUNDAMENTALS_INITIALIZATION_H_ */
@@ -0,0 +1,127 @@
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
+
27
+ #include <Shared/Fundamentals/Utils.h>
28
+ #include <oxt/backtrace.hpp>
29
+ #include <cstdlib>
30
+ #include <cstring>
31
+ #include <signal.h>
32
+ #include <fcntl.h>
33
+ #include <unistd.h>
34
+
35
+ namespace Passenger {
36
+ namespace Agent {
37
+ namespace Fundamentals {
38
+
39
+ using namespace std;
40
+
41
+
42
+ const char *
43
+ getEnvString(const char *name, const char *defaultValue) {
44
+ const char *value = getenv(name);
45
+ if (value != NULL && *value != '\0') {
46
+ return value;
47
+ } else {
48
+ return defaultValue;
49
+ }
50
+ }
51
+
52
+ bool
53
+ getEnvBool(const char *name, bool defaultValue) {
54
+ const char *value = getEnvString(name);
55
+ if (value != NULL) {
56
+ return strcmp(value, "yes") == 0
57
+ || strcmp(value, "y") == 0
58
+ || strcmp(value, "1") == 0
59
+ || strcmp(value, "on") == 0
60
+ || strcmp(value, "true") == 0;
61
+ } else {
62
+ return defaultValue;
63
+ }
64
+ }
65
+
66
+ void
67
+ ignoreSigpipe() {
68
+ struct sigaction action;
69
+ action.sa_handler = SIG_IGN;
70
+ action.sa_flags = 0;
71
+ sigemptyset(&action.sa_mask);
72
+ sigaction(SIGPIPE, &action, NULL);
73
+ }
74
+
75
+ /**
76
+ * Linux-only way to change OOM killer configuration for
77
+ * current process. Requires root privileges, which we
78
+ * should have.
79
+ *
80
+ * Returns 0 on success, or an errno code on error.
81
+ *
82
+ * This function is async signal-safe.
83
+ */
84
+ int
85
+ tryRestoreOomScore(const StaticString &scoreString, bool &isLegacy) {
86
+ TRACE_POINT();
87
+ if (scoreString.empty()) {
88
+ return 0;
89
+ }
90
+
91
+ int fd, ret, e;
92
+ size_t written = 0;
93
+ StaticString score;
94
+
95
+ if (scoreString.at(0) == 'l') {
96
+ isLegacy = true;
97
+ score = scoreString.substr(1);
98
+ fd = open("/proc/self/oom_adj", O_WRONLY | O_TRUNC, 0600);
99
+ } else {
100
+ isLegacy = false;
101
+ score = scoreString;
102
+ fd = open("/proc/self/oom_score_adj", O_WRONLY | O_TRUNC, 0600);
103
+ }
104
+
105
+ if (fd == -1) {
106
+ return errno;
107
+ }
108
+
109
+ do {
110
+ ret = write(fd, score.data() + written, score.size() - written);
111
+ if (ret != -1) {
112
+ written += ret;
113
+ }
114
+ } while (ret == -1 && errno != EAGAIN && written < score.size());
115
+ e = errno;
116
+ close(fd);
117
+ if (ret == -1) {
118
+ return e;
119
+ } else {
120
+ return 0;
121
+ }
122
+ }
123
+
124
+
125
+ } // namespace Fundamentals
126
+ } // namespace Agent
127
+ } // namespace Passenger
@@ -0,0 +1,46 @@
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_AGENT_FUNDAMENTALS_UTILS_H_
27
+ #define _PASSENGER_AGENT_FUNDAMENTALS_UTILS_H_
28
+
29
+ #include <StaticString.h>
30
+
31
+ namespace Passenger {
32
+ namespace Agent {
33
+ namespace Fundamentals {
34
+
35
+
36
+ const char *getEnvString(const char *name, const char *defaultValue = NULL);
37
+ bool getEnvBool(const char *name, bool defaultValue = false);
38
+ void ignoreSigpipe();
39
+ int tryRestoreOomScore(const StaticString &score, bool &isLegacy);
40
+
41
+
42
+ } // namespace Fundamentals
43
+ } // namespace Agent
44
+ } // namespace Passenger
45
+
46
+ #endif /* _PASSENGER_AGENT_FUNDAMENTALS_UTILS_H_ */
@@ -73,7 +73,7 @@ static sig_atomic_t shouldIgnoreNextTermSignal = 0;
73
73
 
74
74
  static void
75
75
  usage() {
76
- printf("Usage: " AGENT_EXE " temp-dir-watcher <DIRECTORY> [OPTIONS...]\n");
76
+ printf("Usage: " AGENT_EXE " temp-dir-toucher <DIRECTORY> [OPTIONS...]\n");
77
77
  printf("Touches everything in a directory every 30 minutes, to "
78
78
  "prevent /tmp cleaners from removing the directory.\n");
79
79
  printf("\n");
@@ -24,6 +24,8 @@
24
24
  * THE SOFTWARE.
25
25
  */
26
26
 
27
+ #include <Shared/Fundamentals/Utils.h>
28
+
27
29
  class CoreWatcher: public AgentWatcher {
28
30
  protected:
29
31
  string agentFilename;
@@ -37,7 +39,7 @@ protected:
37
39
  }
38
40
 
39
41
  virtual void execProgram() const {
40
- if (hasEnvOption("PASSENGER_RUN_CORE_IN_VALGRIND", false)) {
42
+ if (getEnvBool("PASSENGER_RUN_CORE_IN_VALGRIND", false)) {
41
43
  execlp("valgrind", "valgrind", "--dsymutil=yes", "--track-origins=yes", "--leak-check=full",
42
44
  agentFilename.c_str(), "core",
43
45
  // Some extra space to allow the child process to change its process title.
@@ -24,6 +24,10 @@
24
24
  * THE SOFTWARE.
25
25
  */
26
26
 
27
+ #include <boost/bind.hpp>
28
+ #include <Shared/Fundamentals/Utils.h>
29
+ #include <Utils/AsyncSignalSafeUtils.h>
30
+
27
31
  /**
28
32
  * Touch all files in the server instance dir every 6 hours in order to prevent /tmp
29
33
  * cleaners from weaking havoc:
@@ -34,68 +38,101 @@ private:
34
38
  WorkingObjectsPtr wo;
35
39
  oxt::thread *thr;
36
40
 
41
+ static void afterFork(const StaticString &originalOomScore, const char *workingDir) {
42
+ namespace ASSU = AsyncSignalSafeUtils;
43
+ int prio, ret, e;
44
+
45
+ // Make process nicer.
46
+ do {
47
+ prio = getpriority(PRIO_PROCESS, getpid());
48
+ } while (prio == -1 && errno == EINTR);
49
+ if (prio != -1) {
50
+ prio++;
51
+ if (prio > 20) {
52
+ prio = 20;
53
+ }
54
+ do {
55
+ ret = setpriority(PRIO_PROCESS, getpid(), prio);
56
+ } while (ret == -1 && errno == EINTR);
57
+ } else {
58
+ char buf[1024];
59
+ char *pos = buf;
60
+ const char *end = buf + sizeof(buf);
61
+
62
+ e = errno;
63
+ pos = ASSU::appendData(pos, end, "getpriority() failed: ");
64
+ pos = ASSU::appendData(pos, end, ASSU::limitedStrerror(e));
65
+ pos = ASSU::appendData(pos, end, " (errno=");
66
+ pos = ASSU::appendInteger<int, 10>(pos, end, e);
67
+ pos = ASSU::appendData(pos, end, ")");
68
+ ASSU::printError(buf, pos - buf);
69
+ }
70
+
71
+ do {
72
+ ret = chdir(workingDir);
73
+ } while (ret == -1 && errno == EINTR);
74
+ if (ret == -1) {
75
+ char buf[1024];
76
+ char *pos = buf;
77
+ const char *end = buf + sizeof(buf);
78
+
79
+ e = errno;
80
+ pos = ASSU::appendData(pos, end, "chdir(\"");
81
+ pos = ASSU::appendData(pos, end, workingDir);
82
+ pos = ASSU::appendData(pos, end, "\") failed: ");
83
+ pos = ASSU::appendData(pos, end, ASSU::limitedStrerror(e));
84
+ pos = ASSU::appendData(pos, end, " (errno=");
85
+ pos = ASSU::appendInteger<int, 10>(pos, end, e);
86
+ pos = ASSU::appendData(pos, end, ")");
87
+ ASSU::printError(buf, pos - buf);
88
+ _exit(1);
89
+ }
90
+
91
+ bool isLegacy;
92
+ ret = tryRestoreOomScore(originalOomScore, isLegacy);
93
+ if (ret != 0) {
94
+ char buf[1024];
95
+ char *pos = buf;
96
+ const char *end = buf + sizeof(buf);
97
+
98
+ pos = ASSU::appendData(pos, end, "Unable to set OOM score to ");
99
+ pos = ASSU::appendData(pos, end, originalOomScore.data(), originalOomScore.size());
100
+ pos = ASSU::appendData(pos, end, " (legacy: ");
101
+ pos = ASSU::appendData(pos, end, isLegacy ? "true" : "false");
102
+ pos = ASSU::appendData(pos, end, ") due to error: ");
103
+ pos = ASSU::appendData(pos, end, ASSU::limitedStrerror(ret));
104
+ pos = ASSU::appendData(pos, end, " (errno=");
105
+ pos = ASSU::appendInteger<int, 10>(pos, end, ret);
106
+ pos = ASSU::appendData(pos, end, "). Process will remain at inherited OOM score.");
107
+ ASSU::printError(buf, pos - buf);
108
+ }
109
+ }
110
+
37
111
  void
38
112
  threadMain() {
113
+ string originalOomScore = agentsOptions->get("original_oom_score", false);
114
+ string workingDir = wo->instanceDir->getPath().c_str();
115
+
39
116
  while (!boost::this_thread::interruption_requested()) {
40
117
  syscalls::sleep(60 * 60);
41
118
 
42
119
  begin_touch:
43
120
 
44
- boost::this_thread::disable_interruption di;
45
- boost::this_thread::disable_syscall_interruption dsi;
46
- // Fork a process which touches everything in the server instance dir.
47
- pid_t pid = syscalls::fork();
48
- if (pid == 0) {
49
- // Child
50
- int prio, ret, e;
51
-
52
- closeAllFileDescriptors(2);
53
-
54
- // Make process nicer.
55
- do {
56
- prio = getpriority(PRIO_PROCESS, getpid());
57
- } while (prio == -1 && errno == EINTR);
58
- if (prio != -1) {
59
- prio++;
60
- if (prio > 20) {
61
- prio = 20;
62
- }
63
- do {
64
- ret = setpriority(PRIO_PROCESS, getpid(), prio);
65
- } while (ret == -1 && errno == EINTR);
66
- } else {
67
- perror("getpriority");
68
- }
69
-
70
- do {
71
- ret = chdir(wo->instanceDir->getPath().c_str());
72
- } while (ret == -1 && errno == EINTR);
73
- if (ret == -1) {
74
- e = errno;
75
- fprintf(stderr, "chdir(\"%s\") failed: %s (%d)\n",
76
- wo->instanceDir->getPath().c_str(),
77
- strerror(e), e);
78
- fflush(stderr);
79
- _exit(1);
80
- }
81
- restoreOomScore(agentsOptions);
82
-
83
- execlp("/bin/sh", "/bin/sh", "-c", "find . | xargs touch", (char *) 0);
84
- e = errno;
85
- fprintf(stderr, "Cannot execute 'find . | xargs touch': %s (%d)\n",
86
- strerror(e), e);
87
- fflush(stderr);
88
- _exit(1);
89
- } else if (pid == -1) {
90
- // Error
91
- P_WARN("Could not touch the server instance directory because "
92
- "fork() failed. Retrying in 2 minutes...");
93
- boost::this_thread::restore_interruption si(di);
94
- boost::this_thread::restore_syscall_interruption rsi(dsi);
121
+ try {
122
+ const char *command[] = {
123
+ "/bin/sh",
124
+ "-c",
125
+ "find . | xargs touch",
126
+ NULL
127
+ };
128
+ SubprocessInfo info;
129
+ runCommand(command, info, true, true,
130
+ boost::bind(afterFork, originalOomScore, workingDir.c_str()));
131
+ } catch (const SystemException &e) {
132
+ P_WARN("Could not touch the " PROGRAM_NAME " instance directory ("
133
+ << e.what() << "). Retrying in 2 minutes...");
95
134
  syscalls::sleep(60 * 2);
96
135
  goto begin_touch;
97
- } else {
98
- syscalls::waitpid(pid, NULL, 0);
99
136
  }
100
137
  }
101
138
  }
@@ -43,7 +43,7 @@
43
43
  #endif
44
44
 
45
45
  #ifdef __linux__
46
- #include <sys/prctl.h>
46
+ #include <sys/prctl.h>
47
47
  #endif
48
48
  #include <sys/select.h>
49
49
  #include <sys/types.h>
@@ -62,10 +62,9 @@
62
62
  #include <cerrno>
63
63
 
64
64
  #include <jsoncpp/json.h>
65
- #include <Shared/Base.h>
65
+ #include <Shared/Fundamentals/Initialization.h>
66
66
  #include <Shared/ApiServerUtils.h>
67
67
  #include <Core/OptionParser.h>
68
- #include <UstRouter/OptionParser.h>
69
68
  #include <Watchdog/ApiServer.h>
70
69
  #include <Constants.h>
71
70
  #include <InstanceDirectory.h>
@@ -90,6 +89,7 @@ using namespace std;
90
89
  using namespace boost;
91
90
  using namespace oxt;
92
91
  using namespace Passenger;
92
+ using namespace Passenger::Agent::Fundamentals;
93
93
 
94
94
 
95
95
  enum OomFileType {
@@ -158,7 +158,6 @@ static void cleanup(const WorkingObjectsPtr &wo);
158
158
  #include "AgentWatcher.cpp"
159
159
  #include "InstanceDirToucher.cpp"
160
160
  #include "CoreWatcher.cpp"
161
- #include "UstRouterWatcher.cpp"
162
161
 
163
162
 
164
163
  /***** Functions *****/
@@ -654,7 +653,7 @@ parseOptions(int argc, const char *argv[], VariantMap &options) {
654
653
  || p.isFlag(argv[i], '\0', "--begin-core-args"))
655
654
  {
656
655
  break;
657
- } else if (!parseUstRouterOption(argc, argv, i, options)) {
656
+ } else {
658
657
  fprintf(stderr, "ERROR: unrecognized UstRouter argument %s. Please "
659
658
  "type '%s ust-router --help' for usage.\n", argv[i], argv[0]);
660
659
  exit(1);
@@ -949,9 +948,15 @@ lowerPrivilege() {
949
948
  "to that of user '" + userName + "' and group '" + groupName +
950
949
  "': cannot set user ID to " + toString(pwUser->pw_uid), e);
951
950
  }
952
- #ifdef __linux__
953
- prctl(PR_SET_DUMPABLE, 1);
954
- #endif
951
+ #ifdef __linux__
952
+ // When we change the uid, /proc/self/pid contents don't change owner,
953
+ // causing us to lose access to our own /proc/self/pid files.
954
+ // This prctl call changes those files' ownership.
955
+ // References:
956
+ // https://stackoverflow.com/questions/8337846/files-ownergroup-doesnt-change-at-location-proc-pid-after-setuid
957
+ // http://man7.org/linux/man-pages/man5/proc.5.html (search for "dumpable")
958
+ prctl(PR_SET_DUMPABLE, 1);
959
+ #endif
955
960
  setenv("USER", pwUser->pw_name, 1);
956
961
  setenv("HOME", pwUser->pw_dir, 1);
957
962
  setenv("UID", toString(gid).c_str(), 1);
@@ -1062,26 +1067,6 @@ initializeWorkingObjects(const WorkingObjectsPtr &wo, InstanceDirToucherPtr &ins
1062
1067
  options.setStrSet("core_api_addresses", strset);
1063
1068
 
1064
1069
  UPDATE_TRACE_POINT();
1065
- options.setDefault("ust_router_address",
1066
- "unix:" + wo->instanceDir->getPath() + "/agents.s/ust_router");
1067
- options.setDefault("ust_router_password",
1068
- wo->randomGenerator.generateAsciiString(24));
1069
-
1070
- strset = options.getStrSet("ust_router_api_addresses", false);
1071
- strset.insert(strset.begin(),
1072
- "unix:" + wo->instanceDir->getPath() + "/agents.s/ust_router_api");
1073
- options.setStrSet("ust_router_api_addresses", strset);
1074
-
1075
- UPDATE_TRACE_POINT();
1076
- strset = options.getStrSet("ust_router_authorizations", false);
1077
- strset.insert(strset.begin(),
1078
- "readonly:ro_admin:" + wo->instanceDir->getPath() +
1079
- "/read_only_admin_password.txt");
1080
- strset.insert(strset.begin(),
1081
- "full:admin:" + wo->instanceDir->getPath() +
1082
- "/full_admin_password.txt");
1083
- options.setStrSet("ust_router_authorizations", strset);
1084
-
1085
1070
  strset = options.getStrSet("core_authorizations", false);
1086
1071
  strset.insert(strset.begin(),
1087
1072
  "readonly:ro_admin:" + wo->instanceDir->getPath() +
@@ -1096,7 +1081,6 @@ static void
1096
1081
  initializeAgentWatchers(const WorkingObjectsPtr &wo, vector<AgentWatcherPtr> &watchers) {
1097
1082
  TRACE_POINT();
1098
1083
  watchers.push_back(boost::make_shared<CoreWatcher>(wo));
1099
- watchers.push_back(boost::make_shared<UstRouterWatcher>(wo));
1100
1084
  }
1101
1085
 
1102
1086
  static void