passenger 5.1.7 → 5.1.8

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 (97) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG +13 -2
  3. data/CONTRIBUTING.md +1 -1
  4. data/build/agent.rb +1 -1
  5. data/build/cxx_tests.rb +6 -0
  6. data/build/support/cxx_dependency_map.rb +1286 -391
  7. data/build/support/general.rb +0 -26
  8. data/resources/templates/standalone/rails_asset_pipeline.erb +2 -2
  9. data/src/agent/Core/ApiServer.h +49 -44
  10. data/src/agent/Core/ApplicationPool/Pool.h +1 -1
  11. data/src/agent/Core/ApplicationPool/Process.h +1 -1
  12. data/src/agent/Core/ApplicationPool/Socket.h +1 -1
  13. data/src/agent/Core/Controller.h +16 -8
  14. data/src/agent/Core/Controller/CheckoutSession.cpp +1 -1
  15. data/src/agent/Core/Controller/Config.cpp +68 -0
  16. data/src/agent/Core/Controller/Config.h +70 -34
  17. data/src/agent/Core/Controller/ForwardResponse.cpp +5 -5
  18. data/src/agent/Core/Controller/Hooks.cpp +5 -14
  19. data/src/agent/Core/Controller/Implementation.cpp +1 -1
  20. data/src/agent/Core/Controller/InitRequest.cpp +31 -29
  21. data/src/agent/Core/Controller/InitializationAndShutdown.cpp +4 -4
  22. data/src/agent/Core/Controller/InternalUtils.cpp +3 -3
  23. data/src/agent/Core/Controller/Miscellaneous.cpp +1 -1
  24. data/src/agent/Core/Controller/Request.h +2 -2
  25. data/src/agent/Core/Controller/SendRequest.cpp +5 -5
  26. data/src/agent/Core/Controller/StateInspection.cpp +1 -1
  27. data/src/agent/Core/Controller/TurboCaching.h +2 -2
  28. data/src/agent/Core/CoreMain.cpp +2 -2
  29. data/src/agent/Core/ResponseCache.h +3 -3
  30. data/src/agent/Core/SpawningKit/BackgroundIOCapturer.h +3 -3
  31. data/src/agent/Core/SpawningKit/DirectSpawner.h +2 -2
  32. data/src/agent/Core/SpawningKit/PipeWatcher.h +3 -3
  33. data/src/agent/Core/SpawningKit/SmartSpawner.h +2 -2
  34. data/src/agent/Core/SpawningKit/Spawner.h +1 -1
  35. data/src/agent/Core/UnionStation/Connection.h +1 -1
  36. data/src/agent/Core/UnionStation/Context.h +1 -1
  37. data/src/agent/Core/UnionStation/Transaction.h +1 -1
  38. data/src/agent/Shared/ApiServerUtils.h +73 -27
  39. data/src/agent/Shared/Base.cpp +61 -73
  40. data/src/agent/UstRouter/ApiServer.h +34 -45
  41. data/src/agent/UstRouter/Controller.h +86 -60
  42. data/src/agent/UstRouter/RemoteSender.h +1 -1
  43. data/src/agent/UstRouter/RemoteSink.h +1 -1
  44. data/src/agent/Watchdog/ApiServer.h +42 -50
  45. data/src/agent/Watchdog/WatchdogMain.cpp +1 -1
  46. data/src/apache2_module/Configuration.hpp +1 -1
  47. data/src/apache2_module/Hooks.cpp +27 -13
  48. data/src/cxx_supportlib/AppTypes.h +1 -1
  49. data/src/cxx_supportlib/BackgroundEventLoop.cpp +1 -1
  50. data/src/cxx_supportlib/ConfigKit/AsyncUtils.h +86 -0
  51. data/src/cxx_supportlib/ConfigKit/Common.h +6 -3
  52. data/src/cxx_supportlib/ConfigKit/IN_PRACTICE.md +1039 -0
  53. data/src/cxx_supportlib/ConfigKit/README.md +112 -497
  54. data/src/cxx_supportlib/ConfigKit/Schema.h +78 -15
  55. data/src/cxx_supportlib/ConfigKit/Store.h +272 -53
  56. data/src/cxx_supportlib/ConfigKit/SubComponentUtils.h +59 -0
  57. data/src/cxx_supportlib/ConfigKit/Utils.h +26 -65
  58. data/src/cxx_supportlib/ConfigKit/ValidationUtils.h +69 -0
  59. data/src/cxx_supportlib/ConfigKit/VariantMapUtils.h +7 -4
  60. data/src/cxx_supportlib/Constants.h +4 -1
  61. data/src/cxx_supportlib/Crypto.cpp +1 -1
  62. data/src/cxx_supportlib/DataStructures/StringKeyTable.h +26 -7
  63. data/src/cxx_supportlib/FileDescriptor.h +1 -1
  64. data/src/cxx_supportlib/Hooks.h +1 -1
  65. data/src/cxx_supportlib/LoggingKit/Assert.h +130 -0
  66. data/src/cxx_supportlib/LoggingKit/Config.h +97 -0
  67. data/src/cxx_supportlib/LoggingKit/Context.h +94 -0
  68. data/src/cxx_supportlib/LoggingKit/Forward.h +95 -0
  69. data/src/cxx_supportlib/LoggingKit/Implementation.cpp +695 -0
  70. data/src/cxx_supportlib/LoggingKit/Logging.h +204 -0
  71. data/src/cxx_supportlib/LoggingKit/LoggingKit.h +33 -0
  72. data/src/cxx_supportlib/LveLoggingDecorator.h +1 -1
  73. data/src/cxx_supportlib/MemoryKit/mbuf.cpp +1 -1
  74. data/src/cxx_supportlib/RandomGenerator.h +1 -1
  75. data/src/cxx_supportlib/SafeLibev.h +1 -1
  76. data/src/cxx_supportlib/ServerKit/AcceptLoadBalancer.h +1 -1
  77. data/src/cxx_supportlib/ServerKit/Channel.h +1 -1
  78. data/src/cxx_supportlib/ServerKit/FileBufferedChannel.h +1 -1
  79. data/src/cxx_supportlib/ServerKit/FileBufferedFdSinkChannel.h +1 -1
  80. data/src/cxx_supportlib/ServerKit/HttpChunkedBodyParser.h +1 -1
  81. data/src/cxx_supportlib/ServerKit/HttpHeaderParser.h +1 -1
  82. data/src/cxx_supportlib/ServerKit/HttpServer.h +48 -15
  83. data/src/cxx_supportlib/ServerKit/Server.h +79 -52
  84. data/src/cxx_supportlib/StaticString.h +12 -0
  85. data/src/cxx_supportlib/Utils/Curl.h +16 -0
  86. data/src/cxx_supportlib/Utils/FastStringStream.h +6 -1
  87. data/src/cxx_supportlib/Utils/ScopeGuard.h +1 -1
  88. data/src/cxx_supportlib/Utils/StrIntUtils.cpp +2 -19
  89. data/src/cxx_supportlib/WatchdogLauncher.h +3 -2
  90. data/src/ruby_supportlib/phusion_passenger.rb +3 -3
  91. data/src/ruby_supportlib/phusion_passenger/common_library.rb +12 -12
  92. data/src/ruby_supportlib/phusion_passenger/constants.rb +6 -3
  93. data/src/ruby_supportlib/phusion_passenger/standalone/start_command.rb +1 -0
  94. data/src/ruby_supportlib/phusion_passenger/standalone/stop_command.rb +1 -0
  95. metadata +14 -4
  96. data/src/cxx_supportlib/Logging.cpp +0 -295
  97. data/src/cxx_supportlib/Logging.h +0 -385
@@ -39,7 +39,7 @@
39
39
  #include <ServerKit/Server.h>
40
40
  #include <StaticString.h>
41
41
  #include <Constants.h>
42
- #include <Logging.h>
42
+ #include <LoggingKit/LoggingKit.h>
43
43
  #include <UstRouter/Transaction.h>
44
44
  #include <UstRouter/Client.h>
45
45
  #include <UstRouter/FileSink.h>
@@ -61,6 +61,61 @@ using namespace oxt;
61
61
 
62
62
 
63
63
  class Controller: public ServerKit::BaseServer<Controller, Client> {
64
+ public:
65
+ class Schema: public ServerKit::BaseServerSchema {
66
+ private:
67
+ static Json::Value getDefaultValueForDefaultNodeName(const ConfigKit::Store &store) {
68
+ return getHostName();
69
+ }
70
+
71
+ public:
72
+ Schema()
73
+ : ServerKit::BaseServerSchema(false)
74
+ {
75
+ using namespace ConfigKit;
76
+
77
+ add("ust_router_username", STRING_TYPE, OPTIONAL);
78
+ add("ust_router_password", STRING_TYPE, OPTIONAL);
79
+ add("ust_router_dump_dir", STRING_TYPE, OPTIONAL, "/tmp");
80
+ addWithDynamicDefault(
81
+ "ust_router_default_node_name",
82
+ STRING_TYPE, OPTIONAL | CACHE_DEFAULT_VALUE,
83
+ getDefaultValueForDefaultNodeName);
84
+ add("ust_router_dev_mode", BOOL_TYPE, OPTIONAL, false);
85
+ add("union_station_gateway_address", STRING_TYPE, OPTIONAL | READ_ONLY, DEFAULT_UNION_STATION_GATEWAY_ADDRESS);
86
+ add("union_station_gateway_port", UINT_TYPE, OPTIONAL | READ_ONLY, DEFAULT_UNION_STATION_GATEWAY_PORT);
87
+ add("union_station_gateway_cert", STRING_TYPE, OPTIONAL | READ_ONLY);
88
+ add("union_station_proxy_address", STRING_TYPE, OPTIONAL | READ_ONLY);
89
+ add("analytics_sink_flush_timer_interval", UINT_TYPE, OPTIONAL, 5);
90
+ add("analytics_sink_flush_interval", UINT_TYPE, OPTIONAL, 0);
91
+
92
+ finalize();
93
+ }
94
+ };
95
+
96
+ struct ConfigRealization {
97
+ bool devMode;
98
+ unsigned int sinkFlushTimerInterval;
99
+ unsigned int sinkFlushInterval;
100
+
101
+ ConfigRealization(const ConfigKit::Store &config)
102
+ : devMode(config["ust_router_dev_mode"].asBool()),
103
+ sinkFlushTimerInterval(config["analytics_sink_flush_timer_interval"].asUInt()),
104
+ sinkFlushInterval(config["analytics_sink_flush_interval"].asUInt())
105
+ { }
106
+
107
+ void swap(ConfigRealization &other) BOOST_NOEXCEPT_OR_NOTHROW {
108
+ std::swap(devMode, other.devMode);
109
+ std::swap(sinkFlushTimerInterval, other.sinkFlushTimerInterval);
110
+ std::swap(sinkFlushInterval, other.sinkFlushInterval);
111
+ }
112
+ };
113
+
114
+ struct ConfigChangeRequest {
115
+ ServerKit::BaseServerConfigChangeRequest forParent;
116
+ boost::scoped_ptr<ConfigRealization> configRlz;
117
+ };
118
+
64
119
  private:
65
120
  static const unsigned int GARBAGE_COLLECTION_TIMEOUT = 60; // 1 minute
66
121
  static const unsigned int LOG_SINK_MAX_IDLE_TIME = 5 * 60; // 5 minutes
@@ -77,6 +132,7 @@ private:
77
132
  typedef StringMap<TransactionPtr> TransactionMap;
78
133
  typedef StringMap<LogSinkPtr> LogSinkCache;
79
134
 
135
+ ConfigRealization configRlz;
80
136
  RandomGenerator randomGenerator;
81
137
  TransactionMap transactions;
82
138
  LogSinkCache logSinkCache;
@@ -85,8 +141,6 @@ private:
85
141
 
86
142
  ev::timer gcTimer;
87
143
  ev::timer flushTimer;
88
- bool devMode;
89
- int sinkFlushInterval;
90
144
 
91
145
 
92
146
  /****** Handshake and authentication ******/
@@ -320,8 +374,9 @@ private:
320
374
  void processLogMessageBody(Client *client, const StaticString &body) {
321
375
  // In here we process the scalar message that's expected to come
322
376
  // after the "log" command.
377
+ LoggingKit::Level level = LoggingKit::getLevel();
323
378
 
324
- if (getLogLevel() == LVL_DEBUG) {
379
+ if (level == LoggingKit::DEBUG) {
325
380
  string truncatedBody;
326
381
  if (body.size() > 97) {
327
382
  string truncatedBody = body.substr(0, 97);
@@ -332,7 +387,7 @@ private:
332
387
  SKC_DEBUG(client, "Processing message body (" << body.size() <<
333
388
  " bytes): " << body);
334
389
  }
335
- } else if (getLogLevel() >= LVL_DEBUG2) {
390
+ } else if (level >= LoggingKit::DEBUG2) {
336
391
  SKC_TRACE(client, 2, "Processing message body (" << body.size() <<
337
392
  " bytes): " << body);
338
393
  }
@@ -687,7 +742,7 @@ private:
687
742
 
688
743
  LogSinkCache::iterator it;
689
744
  LogSinkCache::iterator end = logSinkCache.end();
690
- ev_tstamp threshold = ev_now(getLoop()) - sinkFlushInterval;
745
+ ev_tstamp threshold = ev_now(getLoop()) - configRlz.sinkFlushInterval;
691
746
 
692
747
  for (it = logSinkCache.begin(); it != end; it++) {
693
748
  const LogSinkPtr &sink = it->second;
@@ -947,7 +1002,7 @@ private:
947
1002
  void closeTransaction(Client *client, const TransactionPtr &transaction) {
948
1003
  if (!transaction->isDiscarded() && passesFilter(transaction)) {
949
1004
  LogSinkPtr logSink;
950
- if (devMode) {
1005
+ if (configRlz.devMode) {
951
1006
  logSink = openLogFile(client, transaction->getCategory());
952
1007
  } else {
953
1008
  logSink = openRemoteSink(transaction->getUnionStationKey(),
@@ -1054,16 +1109,6 @@ private:
1054
1109
  return *filter;
1055
1110
  }
1056
1111
 
1057
- void applyConfigUpdates() {
1058
- devMode = config["ust_router_dev_mode"].asBool();
1059
-
1060
- unsigned int sinkFlushTimerInterval =
1061
- config["analytics_sink_flush_timer_interval"].asUInt();
1062
- sinkFlushInterval = config["analytics_sink_flush_interval"].asUInt();
1063
- flushTimer.stop();
1064
- flushTimer.start(sinkFlushTimerInterval, sinkFlushTimerInterval);
1065
- }
1066
-
1067
1112
  protected:
1068
1113
  virtual void reinitializeClient(Client *client, int fd) {
1069
1114
  ParentClass::reinitializeClient(client, fd);
@@ -1135,11 +1180,6 @@ protected:
1135
1180
  }
1136
1181
  }
1137
1182
 
1138
- virtual void onConfigChange(const ConfigKit::Store *oldConfig) {
1139
- ParentClass::onConfigChange(oldConfig);
1140
- applyConfigUpdates();
1141
- }
1142
-
1143
1183
  virtual void onShutdown(bool forceDisconnect) {
1144
1184
  gcTimer.stop();
1145
1185
  flushTimer.stop();
@@ -1147,56 +1187,22 @@ protected:
1147
1187
  }
1148
1188
 
1149
1189
  public:
1150
- class Schema: public ServerKit::BaseServerSchema {
1151
- private:
1152
- static Json::Value getDefaultValueForDefaultNodeName(const ConfigKit::Store &store) {
1153
- return getHostName();
1154
- }
1155
-
1156
- public:
1157
- Schema()
1158
- : ServerKit::BaseServerSchema(false)
1159
- {
1160
- using namespace ConfigKit;
1161
-
1162
- add("ust_router_username", STRING_TYPE, OPTIONAL);
1163
- add("ust_router_password", STRING_TYPE, OPTIONAL);
1164
- add("ust_router_dump_dir", STRING_TYPE, OPTIONAL, "/tmp");
1165
- addWithDynamicDefault(
1166
- "ust_router_default_node_name",
1167
- STRING_TYPE, OPTIONAL | CACHE_DEFAULT_VALUE,
1168
- getDefaultValueForDefaultNodeName);
1169
- add("ust_router_dev_mode", BOOL_TYPE, OPTIONAL, false);
1170
- add("union_station_gateway_address", STRING_TYPE, OPTIONAL | READ_ONLY, DEFAULT_UNION_STATION_GATEWAY_ADDRESS);
1171
- add("union_station_gateway_port", UINT_TYPE, OPTIONAL | READ_ONLY, DEFAULT_UNION_STATION_GATEWAY_PORT);
1172
- add("union_station_gateway_cert", STRING_TYPE, OPTIONAL | READ_ONLY);
1173
- add("union_station_proxy_address", STRING_TYPE, OPTIONAL | READ_ONLY);
1174
- add("analytics_sink_flush_timer_interval", UINT_TYPE, OPTIONAL, 5);
1175
- add("analytics_sink_flush_interval", UINT_TYPE, OPTIONAL, 0);
1176
-
1177
- finalize();
1178
- }
1179
- };
1180
-
1181
1190
  Controller(ServerKit::Context *context, const Schema &schema,
1182
1191
  const Json::Value &initialConfig)
1183
1192
  : ServerKit::BaseServer<Controller, Client>(context, schema, initialConfig),
1193
+ configRlz(config),
1184
1194
  remoteSender(
1185
1195
  config["union_station_gateway_address"].asString(),
1186
1196
  config["union_station_gateway_port"].asUInt(),
1187
1197
  config["union_station_gateway_cert"].asString(),
1188
1198
  config["union_station_proxy_address"].asString()),
1189
1199
  gcTimer(getLoop()),
1190
- flushTimer(getLoop()),
1191
- devMode(false),
1192
- sinkFlushInterval(0)
1200
+ flushTimer(getLoop())
1193
1201
  {
1194
1202
  gcTimer.set<Controller, &Controller::garbageCollect>(this);
1195
1203
  gcTimer.start(GARBAGE_COLLECTION_TIMEOUT, GARBAGE_COLLECTION_TIMEOUT);
1196
1204
 
1197
1205
  flushTimer.set<Controller, &Controller::flushSomeSinks>(this);
1198
-
1199
- applyConfigUpdates();
1200
1206
  }
1201
1207
 
1202
1208
  virtual StaticString getServerName() const {
@@ -1212,12 +1218,32 @@ public:
1212
1218
  return pos - buf;
1213
1219
  }
1214
1220
 
1221
+ bool prepareConfigChange(const Json::Value &updates,
1222
+ vector<ConfigKit::Error> &errors, ConfigChangeRequest &req)
1223
+ {
1224
+ if (ParentClass::prepareConfigChange(updates, errors, req.forParent)) {
1225
+ req.configRlz.reset(new ConfigRealization(*req.forParent.config));
1226
+ }
1227
+ return errors.empty();
1228
+ }
1229
+
1230
+ void commitConfigChange(ConfigChangeRequest &req)
1231
+ BOOST_NOEXCEPT_OR_NOTHROW
1232
+ {
1233
+ ParentClass::commitConfigChange(req.forParent);
1234
+ configRlz.swap(*req.configRlz);
1235
+
1236
+ flushTimer.stop();
1237
+ flushTimer.start(configRlz.sinkFlushTimerInterval,
1238
+ configRlz.sinkFlushTimerInterval);
1239
+ }
1240
+
1215
1241
  virtual Json::Value inspectStateAsJson() const {
1216
1242
  Json::Value doc = ParentClass::inspectStateAsJson();
1217
- doc["dev_mode"] = devMode;
1243
+ doc["dev_mode"] = configRlz.devMode;
1218
1244
  doc["log_sink_cache"] = inspectLogSinkCacheStateAsJson();
1219
1245
  doc["transactions"] = inspectTransactionsStateAsJson();
1220
- if (devMode) {
1246
+ if (configRlz.devMode) {
1221
1247
  doc["dump_dir"] = config["ust_router_dump_dir"];
1222
1248
  } else {
1223
1249
  doc["remote_sender"] = remoteSender.inspectStateAsJson();
@@ -41,7 +41,7 @@
41
41
  #include <jsoncpp/json.h>
42
42
  #include <modp_b64.h>
43
43
 
44
- #include <Logging.h>
44
+ #include <LoggingKit/LoggingKit.h>
45
45
  #include <StaticString.h>
46
46
  #include <Utils.h>
47
47
  #include <Utils/BlockingQueue.h>
@@ -30,7 +30,7 @@
30
30
  #include <cstring>
31
31
  #include <ctime>
32
32
  #include <ev++.h>
33
- #include <Logging.h>
33
+ #include <LoggingKit/LoggingKit.h>
34
34
  #include <UstRouter/LogSink.h>
35
35
  #include <UstRouter/RemoteSender.h>
36
36
 
@@ -26,8 +26,8 @@
26
26
  #ifndef _PASSENGER_WATCHDOG_AGENT_API_SERVER_H_
27
27
  #define _PASSENGER_WATCHDOG_AGENT_API_SERVER_H_
28
28
 
29
- #include <sstream>
30
29
  #include <string>
30
+ #include <exception>
31
31
  #include <cstring>
32
32
  #include <jsoncpp/json.h>
33
33
  #include <modp_b64.h>
@@ -37,7 +37,7 @@
37
37
  #include <DataStructures/LString.h>
38
38
  #include <Exceptions.h>
39
39
  #include <StaticString.h>
40
- #include <Logging.h>
40
+ #include <LoggingKit/LoggingKit.h>
41
41
  #include <Constants.h>
42
42
  #include <Utils/StrIntUtils.h>
43
43
  #include <Utils/MessageIO.h>
@@ -109,19 +109,8 @@ private:
109
109
  }
110
110
 
111
111
  HeaderTable headers;
112
- Json::Value doc;
113
- string logFile = getLogFile();
114
- string fileDescriptorLogFile = getFileDescriptorLogFile();
115
-
112
+ Json::Value doc = LoggingKit::context->getConfig().inspect();
116
113
  headers.insert(req->pool, "Content-Type", "application/json");
117
- doc["log_level"] = getLogLevel();
118
- if (!logFile.empty()) {
119
- doc["log_file"] = logFile;
120
- }
121
- if (!fileDescriptorLogFile.empty()) {
122
- doc["file_descriptor_log_file"] = fileDescriptorLogFile;
123
- }
124
-
125
114
  writeSimpleResponse(client, 200, &headers, doc.toStyledString());
126
115
  if (!req->ended()) {
127
116
  endRequest(&client, &req);
@@ -140,46 +129,43 @@ private:
140
129
 
141
130
  void processConfigBody(Client *client, Request *req) {
142
131
  HeaderTable headers;
143
- Json::Value &json = req->jsonBody;
132
+ LoggingKit::ConfigChangeRequest configReq;
133
+ const Json::Value &json = req->jsonBody;
134
+ vector<ConfigKit::Error> errors;
135
+ bool ok;
144
136
 
145
137
  headers.insert(req->pool, "Content-Type", "application/json");
138
+ headers.insert(req->pool, "Cache-Control", "no-cache, no-store, must-revalidate");
146
139
 
147
- if (json.isMember("log_level")) {
148
- setLogLevel(json["log_level"].asInt());
149
- }
150
- if (json.isMember("log_file")) {
151
- string logFile = json["log_file"].asString();
152
- try {
153
- logFile = absolutizePath(logFile);
154
- } catch (const SystemException &e) {
155
- unsigned int bufsize = 1024;
156
- char *message = (char *) psg_pnalloc(req->pool, bufsize);
157
- snprintf(message, bufsize, "{ \"status\": \"error\", "
158
- "\"message\": \"Cannot absolutize log file filename: %s\" }",
159
- e.what());
160
- writeSimpleResponse(client, 500, &headers, message);
161
- if (!req->ended()) {
162
- endRequest(&client, &req);
163
- }
164
- return;
140
+ try {
141
+ ok = LoggingKit::context->prepareConfigChange(json,
142
+ errors, configReq);
143
+ } catch (const std::exception &e) {
144
+ unsigned int bufsize = 2048;
145
+ char *message = (char *) psg_pnalloc(req->pool, bufsize);
146
+ snprintf(message, bufsize, "{ \"status\": \"error\", "
147
+ "\"message\": \"Error reconfiguring logging system: %s\" }",
148
+ e.what());
149
+ writeSimpleResponse(client, 500, &headers, message);
150
+ if (!req->ended()) {
151
+ endRequest(&client, &req);
165
152
  }
166
-
167
- int e;
168
- if (!setLogFile(logFile, &e)) {
169
- unsigned int bufsize = 1024;
170
- char *message = (char *) psg_pnalloc(req->pool, bufsize);
171
- snprintf(message, bufsize, "{ \"status\": \"error\", "
172
- "\"message\": \"Cannot open log file: %s (errno=%d)\" }",
173
- strerror(e), e);
174
- writeSimpleResponse(client, 500, &headers, message);
175
- if (!req->ended()) {
176
- endRequest(&client, &req);
177
- }
178
- return;
153
+ return;
154
+ }
155
+ if (!ok) {
156
+ unsigned int bufsize = 2048;
157
+ char *message = (char *) psg_pnalloc(req->pool, bufsize);
158
+ snprintf(message, bufsize, "{ \"status\": \"error\", "
159
+ "\"message\": \"Error reconfiguring logging system: %s\" }",
160
+ ConfigKit::toString(errors).c_str());
161
+ writeSimpleResponse(client, 500, &headers, message);
162
+ if (!req->ended()) {
163
+ endRequest(&client, &req);
179
164
  }
180
- P_NOTICE("Log file opened.");
165
+ return;
181
166
  }
182
167
 
168
+ LoggingKit::context->commitConfigChange(configReq);
183
169
  writeSimpleResponse(client, 200, &headers, "{ \"status\": \"ok\" }");
184
170
  if (!req->ended()) {
185
171
  endRequest(&client, &req);
@@ -201,10 +187,14 @@ private:
201
187
  if (req->method != HTTP_GET) {
202
188
  apiServerRespondWith405(this, client, req);
203
189
  } else if (authorizeFdPassingOperation(client, req)) {
190
+ ConfigKit::Store config = LoggingKit::context->getConfig();
204
191
  HeaderTable headers;
205
192
  headers.insert(req->pool, "Cache-Control", "no-cache, no-store, must-revalidate");
206
193
  headers.insert(req->pool, "Content-Type", "text/plain");
207
- headers.insert(req->pool, "Filename", getLogFile());
194
+ if (config["target"].isMember("path")) {
195
+ headers.insert(req->pool, "Filename",
196
+ psg_pstrdup(req->pool, config["target"]["path"].asString()));
197
+ }
208
198
  req->wantKeepAlive = false;
209
199
  writeSimpleResponse(client, 200, &headers, "");
210
200
  if (req->ended()) {
@@ -213,9 +203,11 @@ private:
213
203
 
214
204
  unsigned long long timeout = 1000000;
215
205
  setBlocking(client->getFd());
216
- writeFileDescriptorWithNegotiation(client->getFd(), STDERR_FILENO,
206
+ ScopeGuard guard(boost::bind(setNonBlocking, client->getFd()));
207
+ writeFileDescriptorWithNegotiation(client->getFd(),
208
+ LoggingKit::context->getConfigRealization()->targetFd,
217
209
  &timeout);
218
- setNonBlocking(client->getFd());
210
+ guard.runNow();
219
211
 
220
212
  if (!req->ended()) {
221
213
  endRequest(&client, &req);
@@ -72,7 +72,7 @@
72
72
  #include <FileDescriptor.h>
73
73
  #include <RandomGenerator.h>
74
74
  #include <BackgroundEventLoop.h>
75
- #include <Logging.h>
75
+ #include <LoggingKit/LoggingKit.h>
76
76
  #include <Exceptions.h>
77
77
  #include <StaticString.h>
78
78
  #include <Hooks.h>
@@ -26,7 +26,7 @@
26
26
  #ifndef _PASSENGER_CONFIGURATION_HPP_
27
27
  #define _PASSENGER_CONFIGURATION_HPP_
28
28
 
29
- #include <Logging.h>
29
+ #include <LoggingKit/LoggingKit.h>
30
30
  #include <Constants.h>
31
31
  #include <Utils.h>
32
32
  #include <Utils/VariantMap.h>
@@ -61,7 +61,7 @@
61
61
  #include <Utils/SystemTime.h>
62
62
  #include <Utils/HttpConstants.h>
63
63
  #include <Utils/ReleaseableScopedPointer.h>
64
- #include <Logging.h>
64
+ #include <LoggingKit/LoggingKit.h>
65
65
  #include <WatchdogLauncher.h>
66
66
  #include <Constants.h>
67
67
 
@@ -1239,20 +1239,33 @@ public:
1239
1239
  {
1240
1240
  passenger_postprocess_config(s);
1241
1241
 
1242
- Passenger::setLogLevel(serverConfig.logLevel);
1242
+ Json::Value loggingConfig;
1243
+ loggingConfig["level"] = LoggingKit::Level(serverConfig.logLevel);
1244
+ loggingConfig["redirect_stderr"] = false;
1243
1245
  if (serverConfig.logFile != NULL) {
1244
- int errcode;
1245
- if (!Passenger::setLogFileWithoutRedirectingStderr(serverConfig.logFile, &errcode)) {
1246
- fprintf(stderr,
1247
- "ERROR: cannot open log file %s: %s (errno=%d)\n",
1248
- serverConfig.logFile,
1249
- strerror(errcode),
1250
- errcode);
1251
- }
1246
+ loggingConfig["target"] = serverConfig.logFile;
1252
1247
  }
1253
1248
  if (serverConfig.fileDescriptorLogFile != NULL) {
1254
- Passenger::setFileDescriptorLogFile(serverConfig.fileDescriptorLogFile);
1249
+ loggingConfig["file_descriptor_log_target"] =
1250
+ serverConfig.fileDescriptorLogFile;
1251
+ }
1252
+
1253
+ vector<ConfigKit::Error> errors;
1254
+ LoggingKit::ConfigChangeRequest req;
1255
+ bool ok;
1256
+ try {
1257
+ ok = LoggingKit::context->prepareConfigChange(loggingConfig,
1258
+ errors, req);
1259
+ } catch (const std::exception &e) {
1260
+ fprintf(stderr, "ERROR: unable to configure logging system: %s\n", e.what());
1261
+ }
1262
+ if (ok) {
1263
+ LoggingKit::context->commitConfigChange(req);
1264
+ } else {
1265
+ fprintf(stderr, "ERROR: unable to configuring logging system: %s\n",
1266
+ ConfigKit::toString(errors).c_str());
1255
1267
  }
1268
+
1256
1269
  m_hasModRewrite = UNKNOWN;
1257
1270
  m_hasModDir = UNKNOWN;
1258
1271
  m_hasModAutoIndex = UNKNOWN;
@@ -1596,6 +1609,7 @@ init_module(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *
1596
1609
  */
1597
1610
  if (hooks == NULL) {
1598
1611
  oxt::initialize();
1612
+ LoggingKit::initialize();
1599
1613
  SystemTime::initialize();
1600
1614
  } else {
1601
1615
  P_DEBUG("Restarting Phusion Passenger....");
@@ -1609,13 +1623,13 @@ init_module(apr_pool_t *pconf, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *
1609
1623
  apr_pool_cleanup_null);
1610
1624
  return OK;
1611
1625
 
1612
- } catch (const thread_interrupted &e) {
1626
+ } catch (const boost::thread_interrupted &e) {
1613
1627
  P_TRACE(2, "A system call was interrupted during mod_passenger "
1614
1628
  "initialization. Apache might be restarting or shutting "
1615
1629
  "down. Backtrace:\n" << e.backtrace());
1616
1630
  return DECLINED;
1617
1631
 
1618
- } catch (const thread_resource_error &e) {
1632
+ } catch (const boost::thread_resource_error &e) {
1619
1633
  struct rlimit lim;
1620
1634
  string pthread_threads_max;
1621
1635
  int ret;