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
@@ -53,7 +53,7 @@ private:
53
53
  string docDir;
54
54
  string rubyLibDir;
55
55
  string nodeLibDir;
56
-
56
+
57
57
  static string getOption(const string &file, const IniFileSectionPtr &section, const string &key) {
58
58
  if (section->hasKey(key)) {
59
59
  return section->get(key);
@@ -61,7 +61,7 @@ private:
61
61
  throw RuntimeException("Option '" + key + "' missing in file '" + file + "'");
62
62
  }
63
63
  }
64
-
64
+
65
65
  public:
66
66
  ResourceLocator(const string &rootOrFile) {
67
67
  root = rootOrFile;
@@ -86,27 +86,27 @@ public:
86
86
  nodeLibDir = root + "/node_lib";
87
87
  }
88
88
  }
89
-
89
+
90
90
  string getRoot() const {
91
91
  return root;
92
92
  }
93
-
93
+
94
94
  string getAgentsDir() const {
95
95
  return agentsDir;
96
96
  }
97
-
97
+
98
98
  string getHelperScriptsDir() const {
99
99
  return helperScriptsDir;
100
100
  }
101
-
101
+
102
102
  string getResourcesDir() const {
103
103
  return resourcesDir;
104
104
  }
105
-
105
+
106
106
  string getDocDir() const {
107
107
  return docDir;
108
108
  }
109
-
109
+
110
110
  // Can be empty.
111
111
  string getRubyLibDir() const {
112
112
  return rubyLibDir;
@@ -1,6 +1,6 @@
1
1
  /*
2
2
  * Phusion Passenger - https://www.phusionpassenger.com/
3
- * Copyright (c) 2010, 2011, 2012 Phusion
3
+ * Copyright (c) 2010-2014 Phusion
4
4
  *
5
5
  * "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
6
6
  *
@@ -29,11 +29,11 @@
29
29
  #include <vector>
30
30
  #include <list>
31
31
  #include <memory>
32
- #include <climits>
33
32
  #include <boost/thread.hpp>
34
33
  #include <boost/shared_ptr.hpp>
35
34
  #include <boost/function.hpp>
36
35
  #include <boost/bind.hpp>
36
+ #include <oxt/thread.hpp>
37
37
 
38
38
  namespace Passenger {
39
39
 
@@ -46,27 +46,33 @@ using namespace boost;
46
46
  */
47
47
  class SafeLibev {
48
48
  private:
49
+ // 2^28-1. Command IDs are 28-bit so that we can pack DataSource's state and
50
+ // its planId in 32-bits total.
51
+ static const unsigned int MAX_COMMAND_ID = 268435455;
52
+
49
53
  typedef boost::function<void ()> Callback;
50
54
 
51
55
  struct Command {
52
- int id;
53
56
  Callback callback;
57
+ unsigned int id: 31;
58
+ bool canceled: 1;
54
59
 
55
60
  Command(unsigned int _id, const Callback &_callback)
56
- : id(_id),
57
- callback(_callback)
61
+ : callback(_callback),
62
+ id(_id),
63
+ canceled(false)
58
64
  { }
59
65
  };
60
66
 
61
67
  struct ev_loop *loop;
62
68
  pthread_t loopThread;
63
69
  ev_async async;
64
-
70
+
65
71
  boost::mutex syncher;
66
72
  boost::condition_variable cond;
67
73
  vector<Command> commands;
68
74
  unsigned int nextCommandId;
69
-
75
+
70
76
  static void asyncHandler(EV_P_ ev_async *w, int revents) {
71
77
  SafeLibev *self = (SafeLibev *) w->data;
72
78
  self->runCommands();
@@ -82,13 +88,15 @@ private:
82
88
  vector<Command> commands = this->commands;
83
89
  this->commands.clear();
84
90
  l.unlock();
85
-
91
+
86
92
  vector<Command>::const_iterator it, end = commands.end();
87
93
  for (it = commands.begin(); it != end; it++) {
88
- it->callback();
94
+ if (!it->canceled) {
95
+ it->callback();
96
+ }
89
97
  }
90
98
  }
91
-
99
+
92
100
  template<typename Watcher>
93
101
  void startWatcherAndNotify(Watcher *watcher, bool *done) {
94
102
  watcher->set(loop);
@@ -97,7 +105,7 @@ private:
97
105
  *done = true;
98
106
  cond.notify_all();
99
107
  }
100
-
108
+
101
109
  template<typename Watcher>
102
110
  void stopWatcherAndNotify(Watcher *watcher, bool *done) {
103
111
  watcher->stop();
@@ -105,7 +113,7 @@ private:
105
113
  *done = true;
106
114
  cond.notify_all();
107
115
  }
108
-
116
+
109
117
  void runAndNotify(const Callback *callback, bool *done) {
110
118
  (*callback)();
111
119
  boost::unique_lock<boost::mutex> l(syncher);
@@ -114,26 +122,26 @@ private:
114
122
  }
115
123
 
116
124
  void incNextCommandId() {
117
- if (nextCommandId == INT_MAX) {
118
- nextCommandId = 0;
125
+ if (nextCommandId == MAX_COMMAND_ID) {
126
+ nextCommandId = 1;
119
127
  } else {
120
128
  nextCommandId++;
121
129
  }
122
130
  }
123
-
131
+
124
132
  public:
125
133
  /** SafeLibev takes over ownership of the loop object. */
126
134
  SafeLibev(struct ev_loop *loop) {
127
135
  this->loop = loop;
128
136
  loopThread = pthread_self();
129
- nextCommandId = 0;
130
-
137
+ nextCommandId = 1;
138
+
131
139
  ev_async_init(&async, asyncHandler);
132
140
  ev_set_priority(&async, EV_MAXPRI);
133
141
  async.data = this;
134
142
  ev_async_start(loop, &async);
135
143
  }
136
-
144
+
137
145
  ~SafeLibev() {
138
146
  destroy();
139
147
  ev_loop_destroy(loop);
@@ -142,19 +150,36 @@ public:
142
150
  void destroy() {
143
151
  ev_async_stop(loop, &async);
144
152
  }
145
-
153
+
146
154
  struct ev_loop *getLoop() const {
147
155
  return loop;
148
156
  }
149
-
157
+
150
158
  void setCurrentThread() {
151
159
  loopThread = pthread_self();
160
+ #ifdef OXT_THREAD_LOCAL_KEYWORD_SUPPORTED
161
+ oxt::thread_signature = this;
162
+ #endif
152
163
  }
153
164
 
154
165
  pthread_t getCurrentThread() const {
155
166
  return loopThread;
156
167
  }
157
-
168
+
169
+ bool onEventLoopThread() const {
170
+ #ifdef OXT_THREAD_LOCAL_KEYWORD_SUPPORTED
171
+ // Avoid double reads of the thread-local variable.
172
+ const void *sig = oxt::thread_signature;
173
+ if (OXT_UNLIKELY(sig == NULL)) {
174
+ return pthread_equal(pthread_self(), loopThread);
175
+ } else {
176
+ return sig == this;
177
+ }
178
+ #else
179
+ return pthread_equal(pthread_self(), loopThread);
180
+ #endif
181
+ }
182
+
158
183
  template<typename Watcher>
159
184
  void start(Watcher &watcher) {
160
185
  if (pthread_equal(pthread_self(), loopThread)) {
@@ -173,7 +198,7 @@ public:
173
198
  }
174
199
  }
175
200
  }
176
-
201
+
177
202
  template<typename Watcher>
178
203
  void stop(Watcher &watcher) {
179
204
  if (pthread_equal(pthread_self(), loopThread)) {
@@ -191,7 +216,7 @@ public:
191
216
  }
192
217
  }
193
218
  }
194
-
219
+
195
220
  void run(const Callback &callback) {
196
221
  assert(callback != NULL);
197
222
  if (pthread_equal(pthread_self(), loopThread)) {
@@ -251,14 +276,18 @@ public:
251
276
  * in the future, while a return value of false means that the callback has already
252
277
  * been called or is currently being called.
253
278
  */
254
- bool cancelCommand(int id) {
279
+ bool cancelCommand(unsigned int id) {
280
+ if (id == 0) {
281
+ return false;
282
+ }
283
+
255
284
  boost::unique_lock<boost::mutex> l(syncher);
256
285
  // TODO: we can do a binary search because the command ID
257
286
  // is monotically increasing except on overflow.
258
287
  vector<Command>::iterator it, end = commands.end();
259
288
  for (it = commands.begin(); it != end; it++) {
260
289
  if (it->id == id) {
261
- commands.erase(it);
290
+ it->canceled = true;
262
291
  return true;
263
292
  }
264
293
  }
@@ -64,17 +64,17 @@ public:
64
64
  class Generation: public noncopyable {
65
65
  private:
66
66
  friend class ServerInstanceDir;
67
-
67
+
68
68
  string path;
69
69
  unsigned int number;
70
70
  bool owner;
71
-
71
+
72
72
  Generation(const string &serverInstanceDir, unsigned int number) {
73
73
  path = serverInstanceDir + "/generation-" + toString(number);
74
74
  this->number = number;
75
75
  owner = false;
76
76
  }
77
-
77
+
78
78
  void create(bool userSwitching, const string &defaultUser,
79
79
  const string &defaultGroup, uid_t webServerWorkerUid,
80
80
  gid_t webServerWorkerGid)
@@ -84,7 +84,7 @@ public:
84
84
  struct passwd *defaultUserEntry;
85
85
  uid_t defaultUid;
86
86
  gid_t defaultGid;
87
-
87
+
88
88
  defaultUserEntry = getpwnam(defaultUser.c_str());
89
89
  if (defaultUserEntry == NULL) {
90
90
  throw NonExistentUserException("Default user '" + defaultUser +
@@ -96,26 +96,26 @@ public:
96
96
  throw NonExistentGroupException("Default group '" + defaultGroup +
97
97
  "' does not exist.");
98
98
  }
99
-
99
+
100
100
  /* We set a very tight permission here: no read or write access for
101
101
  * anybody except the owner. The individual files and subdirectories
102
102
  * decide for themselves whether they're readable by anybody.
103
103
  */
104
104
  makeDirTree(path, "u=rwx,g=x,o=x");
105
-
105
+
106
106
  /* Write structure version file. */
107
107
  string structureVersionFile = path + "/structure_version.txt";
108
108
  createFile(structureVersionFile,
109
109
  toString(SERVER_INSTANCE_DIR_GENERATION_STRUCTURE_MAJOR_VERSION) + "." +
110
110
  toString(SERVER_INSTANCE_DIR_GENERATION_STRUCTURE_MINOR_VERSION),
111
111
  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
112
-
112
+
113
113
  string passengerVersionFile = path + "/passenger_version.txt";
114
114
  createFile(passengerVersionFile,
115
115
  PASSENGER_VERSION "\n",
116
116
  S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
117
-
118
-
117
+
118
+
119
119
  /* We want the upload buffer directory to be only writable by the web
120
120
  * server's worker processs. Other users may not have any access to this
121
121
  * directory.
@@ -126,7 +126,7 @@ public:
126
126
  } else {
127
127
  makeDirTree(path + "/buffered_uploads", "u=rwx,g=,o=");
128
128
  }
129
-
129
+
130
130
  /* The HelperAgent must be able to connect to an application. */
131
131
  if (runningAsRoot) {
132
132
  if (userSwitching) {
@@ -153,10 +153,10 @@ public:
153
153
  */
154
154
  makeDirTree(path + "/backends", "u=rwx,g=,o=");
155
155
  }
156
-
156
+
157
157
  owner = true;
158
158
  }
159
-
159
+
160
160
  public:
161
161
  ~Generation() {
162
162
  destroy();
@@ -167,30 +167,30 @@ public:
167
167
  removeDirTree(path);
168
168
  }
169
169
  }
170
-
170
+
171
171
  unsigned int getNumber() const {
172
172
  return number;
173
173
  }
174
-
174
+
175
175
  // The 'const strng &' here is on purpose. The AgentsStarter C
176
176
  // functions return the string pointer directly.
177
177
  const string &getPath() const {
178
178
  return path;
179
179
  }
180
-
180
+
181
181
  void detach() {
182
182
  owner = false;
183
183
  }
184
184
  };
185
-
185
+
186
186
  typedef boost::shared_ptr<Generation> GenerationPtr;
187
-
187
+
188
188
  private:
189
189
  string path;
190
190
  bool owner;
191
-
191
+
192
192
  friend class Generation;
193
-
193
+
194
194
  void initialize(const string &path, bool owner) {
195
195
  TRACE_POINT();
196
196
  struct stat buf;
@@ -198,7 +198,7 @@ private:
198
198
 
199
199
  this->path = path;
200
200
  this->owner = owner;
201
-
201
+
202
202
  /* Create the server instance directory. We only need to write to this
203
203
  * directory for these reasons:
204
204
  * 1. Initial population of structure files (structure_version.txt, instance.pid).
@@ -288,7 +288,7 @@ private:
288
288
  path + ", but it has wrong owner and group");
289
289
  }
290
290
  }
291
-
291
+
292
292
  bool isDirectory(const string &dir, struct dirent *entry) const {
293
293
  #ifdef DT_DIR
294
294
  if (entry->d_type == DT_DIR) {
@@ -303,12 +303,12 @@ private:
303
303
  path.append(entry->d_name);
304
304
  return getFileType(path) == FT_DIRECTORY;
305
305
  }
306
-
306
+
307
307
  public:
308
308
  ServerInstanceDir(const string &path, bool owner = true) {
309
309
  initialize(path, owner);
310
310
  }
311
-
311
+
312
312
  ~ServerInstanceDir() {
313
313
  destroy();
314
314
  }
@@ -330,17 +330,17 @@ public:
330
330
  }
331
331
  }
332
332
  }
333
-
333
+
334
334
  // The 'const strng &' here is on purpose. The AgentsStarter C
335
335
  // functions return the string pointer directly.
336
336
  const string &getPath() const {
337
337
  return path;
338
338
  }
339
-
339
+
340
340
  void detach() {
341
341
  owner = false;
342
342
  }
343
-
343
+
344
344
  GenerationPtr newGeneration(bool userSwitching, const string &defaultUser,
345
345
  const string &defaultGroup, uid_t webServerWorkerUid,
346
346
  gid_t webServerWorkerGid)
@@ -352,24 +352,24 @@ public:
352
352
  } else {
353
353
  newNumber = 0;
354
354
  }
355
-
355
+
356
356
  GenerationPtr generation(new Generation(path, newNumber));
357
357
  generation->create(userSwitching, defaultUser, defaultGroup,
358
358
  webServerWorkerUid, webServerWorkerGid);
359
359
  return generation;
360
360
  }
361
-
361
+
362
362
  GenerationPtr getGeneration(unsigned int number) const {
363
363
  // Must not used boost::make_shared() here because Watchdog.cpp
364
364
  // deletes the raw pointer in cleanupAgentsInBackground().
365
365
  return ptr(new Generation(path, number));
366
366
  }
367
-
367
+
368
368
  GenerationPtr getNewestGeneration() const {
369
369
  DIR *dir = opendir(path.c_str());
370
370
  struct dirent *entry;
371
371
  int result = -1;
372
-
372
+
373
373
  if (dir == NULL) {
374
374
  int e = errno;
375
375
  throw FileSystemException("Cannot open directory " + path,
@@ -386,7 +386,7 @@ public:
386
386
  }
387
387
  }
388
388
  closedir(dir);
389
-
389
+
390
390
  if (result == -1) {
391
391
  return GenerationPtr();
392
392
  } else {