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
@@ -29,7 +29,7 @@
29
29
  #include <Core/SpawningKit/Spawner.h>
30
30
  #include <Core/SpawningKit/PipeWatcher.h>
31
31
  #include <Constants.h>
32
- #include <Logging.h>
32
+ #include <LoggingKit/LoggingKit.h>
33
33
  #include <LveLoggingDecorator.h>
34
34
 
35
35
  #include <adhoc_lve.h>
@@ -106,7 +106,7 @@ private:
106
106
  if (shouldLoadShellEnvvars(options, preparation)) {
107
107
  command.push_back(preparation.userSwitching.shell);
108
108
  command.push_back(preparation.userSwitching.shell);
109
- if (Passenger::getLogLevel() >= LVL_DEBUG3) {
109
+ if (LoggingKit::getLevel() >= LoggingKit::DEBUG3) {
110
110
  command.push_back("-lxc");
111
111
  } else {
112
112
  command.push_back("-lc");
@@ -710,7 +710,7 @@ protected:
710
710
  if (details.stderrCapturer != NULL) {
711
711
  details.stderrCapturer->appendToBuffer(result);
712
712
  }
713
- printAppOutput(details.pid, "stdout", line.data(), line.size());
713
+ LoggingKit::logAppOutput(details.pid, "stdout", line.data(), line.size());
714
714
  }
715
715
  }
716
716
  }
@@ -37,7 +37,7 @@
37
37
 
38
38
  #include <errno.h>
39
39
 
40
- #include <Logging.h>
40
+ #include <LoggingKit/LoggingKit.h>
41
41
  #include <Exceptions.h>
42
42
  #include <Utils/IOUtils.h>
43
43
  #include <Utils/MessageIO.h>
@@ -37,7 +37,7 @@
37
37
  #include <vector>
38
38
  #include <stdexcept>
39
39
 
40
- #include <Logging.h>
40
+ #include <LoggingKit/LoggingKit.h>
41
41
  #include <Exceptions.h>
42
42
  #include <StaticString.h>
43
43
  #include <Utils.h>
@@ -36,7 +36,7 @@
36
36
  #include <cstdio>
37
37
  #include <cassert>
38
38
 
39
- #include <Logging.h>
39
+ #include <LoggingKit/LoggingKit.h>
40
40
  #include <Exceptions.h>
41
41
  #include <StaticString.h>
42
42
  #include <Utils/IOUtils.h>
@@ -64,6 +64,7 @@
64
64
  #include <sys/types.h>
65
65
  #include <string>
66
66
  #include <vector>
67
+ #include <stdexcept>
67
68
  #include <cstddef>
68
69
  #include <cstring>
69
70
  #include <jsoncpp/json.h>
@@ -74,6 +75,8 @@
74
75
  #include <DataStructures/StringKeyTable.h>
75
76
  #include <ServerKit/Server.h>
76
77
  #include <ServerKit/HeaderTable.h>
78
+ #include <LoggingKit/LoggingKit.h>
79
+ #include <LoggingKit/Context.h>
77
80
  #include <Utils.h>
78
81
  #include <Utils/IOUtils.h>
79
82
  #include <Utils/BufferedIO.h>
@@ -763,12 +766,11 @@ apiServerProcessReopenLogs(Server *server, Client *client, Request *req) {
763
766
  if (req->method != HTTP_POST) {
764
767
  apiServerRespondWith405(server, client, req);
765
768
  } else if (authorizeAdminOperation(server, client, req)) {
766
- int e;
767
769
  ServerKit::HeaderTable headers;
768
770
  headers.insert(req->pool, "Content-Type", "application/json");
769
771
 
770
- string logFile = getLogFile();
771
- if (logFile.empty()) {
772
+ ConfigKit::Store config = LoggingKit::context->getConfig();
773
+ if (!config["target"].isMember("path")) {
772
774
  server->writeSimpleResponse(client, 500, &headers, "{ \"status\": \"error\", "
773
775
  "\"code\": \"NO_LOG_FILE\", "
774
776
  "\"message\": \"" PROGRAM_NAME " was not configured with a log file.\" }\n");
@@ -778,40 +780,56 @@ apiServerProcessReopenLogs(Server *server, Client *client, Request *req) {
778
780
  return;
779
781
  }
780
782
 
781
- if (!setLogFile(logFile, &e)) {
782
- unsigned int bufsize = 1024;
783
+ LoggingKit::ConfigChangeRequest configReq;
784
+ vector<ConfigKit::Error> errors;
785
+ bool ok;
786
+ try {
787
+ ok = LoggingKit::context->prepareConfigChange(Json::objectValue,
788
+ errors, configReq);
789
+ } catch (const SystemException &e) {
790
+ unsigned int bufsize = 2048;
783
791
  char *message = (char *) psg_pnalloc(req->pool, bufsize);
784
792
  snprintf(message, bufsize, "{ \"status\": \"error\", "
785
- "\"code\": \"LOG_FILE_OPEN_ERROR\", "
786
- "\"message\": \"Cannot reopen log file %s: %s (errno=%d)\" }",
787
- logFile.c_str(), strerror(e), e);
793
+ "\"code\": \"OS_ERROR\", "
794
+ "\"message\": \"Cannot reopen log files: %s\" }",
795
+ e.what());
796
+ server->writeSimpleResponse(client, 500, &headers, message);
797
+ if (!req->ended()) {
798
+ server->endRequest(&client, &req);
799
+ }
800
+ return;
801
+ } catch (const std::exception &e) {
802
+ unsigned int bufsize = 2048;
803
+ char *message = (char *) psg_pnalloc(req->pool, bufsize);
804
+ snprintf(message, bufsize, "{ \"status\": \"error\", "
805
+ "\"code\": \"GENERIC_ERROR\", "
806
+ "\"message\": \"Cannot reopen log files: %s\" }",
807
+ e.what());
788
808
  server->writeSimpleResponse(client, 500, &headers, message);
789
809
  if (!req->ended()) {
790
810
  server->endRequest(&client, &req);
791
811
  }
792
812
  return;
793
813
  }
794
- P_NOTICE("Log file reopened.");
795
-
796
- if (hasFileDescriptorLogFile()) {
797
- if (!setFileDescriptorLogFile(getFileDescriptorLogFile(), &e)) {
798
- unsigned int bufsize = 1024;
799
- char *message = (char *) psg_pnalloc(req->pool, bufsize);
800
- snprintf(message, bufsize, "{ \"status\": \"error\", "
801
- "\"code\": \"FD_LOG_FILE_OPEN_ERROR\", "
802
- "\"message\": \"Cannot reopen file descriptor log file %s: %s (errno=%d)\" }",
803
- getFileDescriptorLogFile().c_str(), strerror(e), e);
804
- server->writeSimpleResponse(client, 500, &headers, message);
805
- if (!req->ended()) {
806
- server->endRequest(&client, &req);
807
- }
808
- return;
814
+ if (!ok) {
815
+ unsigned int bufsize = 2048;
816
+ char *message = (char *) psg_pnalloc(req->pool, bufsize);
817
+ snprintf(message, bufsize, "{ \"status\": \"error\", "
818
+ "\"code\": \"CONFIG_VALIDATION_ERROR\", "
819
+ "\"message\": \"Cannot reopen log files:"
820
+ " invalid logging system configuration: %s\" }",
821
+ ConfigKit::toString(errors).c_str());
822
+ server->writeSimpleResponse(client, 500, &headers, message);
823
+ if (!req->ended()) {
824
+ server->endRequest(&client, &req);
809
825
  }
810
- P_NOTICE("File descriptor log file reopened.");
826
+ return;
811
827
  }
812
828
 
813
- server->writeSimpleResponse(client, 200, &headers, "{ \"status\": \"ok\" }\n");
829
+ LoggingKit::context->commitConfigChange(configReq);
830
+ P_NOTICE("All log file(s) reopened.");
814
831
 
832
+ server->writeSimpleResponse(client, 200, &headers, "{ \"status\": \"ok\" }\n");
815
833
  if (!req->ended()) {
816
834
  server->endRequest(&client, &req);
817
835
  }
@@ -838,8 +856,36 @@ _apiServerProcessReinheritLogsResponseBody(
838
856
  }
839
857
 
840
858
  int fd = readFileDescriptorWithNegotiation(io.getFd(), &req.timeout);
841
- setLogFileWithFd(logFilePath, fd);
842
- safelyClose(fd);
859
+ FdGuard guard(fd, __FILE__, __LINE__);
860
+ P_LOG_FILE_DESCRIPTOR_PURPOSE(fd, "Reinherited log file handle");
861
+
862
+ ConfigKit::Store oldConfig = LoggingKit::context->getConfig();
863
+ Json::Value config;
864
+ vector<ConfigKit::Error> errors;
865
+ LoggingKit::ConfigChangeRequest configReq;
866
+ bool ok;
867
+
868
+ config["target"] = oldConfig["target"];
869
+ config["target"]["fd"] = fd;
870
+ try {
871
+ ok = LoggingKit::context->prepareConfigChange(config,
872
+ errors, configReq);
873
+ } catch (const std::exception &e) {
874
+ resp.status = InternalResponse::ERROR_INTERNAL;
875
+ resp.errorLogs.append("Error reconfiguring logging system: ");
876
+ resp.errorLogs.append(e.what());
877
+ return;
878
+ }
879
+ if (!ok) {
880
+ resp.status = InternalResponse::ERROR_INTERNAL;
881
+ resp.errorLogs.append("Error reconfiguring logging system: ");
882
+ resp.errorLogs.append(ConfigKit::toString(errors));
883
+ return;
884
+ }
885
+
886
+ LoggingKit::context->commitConfigChange(configReq);
887
+ guard.clear();
888
+ P_NOTICE("All log file(s) reinherited.");
843
889
  }
844
890
 
845
891
  template<typename Server, typename Client, typename Request>
@@ -27,6 +27,7 @@
27
27
  #define _GNU_SOURCE
28
28
  #endif
29
29
 
30
+ #include <boost/cstdint.hpp>
30
31
  #include <oxt/initialize.hpp>
31
32
  #include <oxt/system_calls.hpp>
32
33
  #include <oxt/backtrace.hpp>
@@ -61,7 +62,8 @@
61
62
  #include <Shared/Base.h>
62
63
  #include <Constants.h>
63
64
  #include <Exceptions.h>
64
- #include <Logging.h>
65
+ #include <LoggingKit/LoggingKit.h>
66
+ #include <LoggingKit/Context.h>
65
67
  #include <ResourceLocator.h>
66
68
  #include <Utils.h>
67
69
  #include <Utils/SystemTime.h>
@@ -70,6 +72,8 @@
70
72
  #include <ResourceLocator.h>
71
73
  #endif
72
74
 
75
+ #include <jsoncpp/json.h>
76
+
73
77
  namespace Passenger {
74
78
 
75
79
 
@@ -246,24 +250,7 @@ appendIntegerAsHex(char *buf, IntegerType value) {
246
250
  // Must be async signal safe.
247
251
  static char *
248
252
  appendPointerAsString(char *buf, void *pointer) {
249
- // Use wierd union construction to avoid compiler warnings.
250
- if (sizeof(void *) == sizeof(unsigned int)) {
251
- union {
252
- void *pointer;
253
- unsigned int value;
254
- } u;
255
- u.pointer = pointer;
256
- return appendIntegerAsHex(appendText(buf, "0x"), u.value);
257
- } else if (sizeof(void *) == sizeof(unsigned long long)) {
258
- union {
259
- void *pointer;
260
- unsigned long long value;
261
- } u;
262
- u.pointer = pointer;
263
- return appendIntegerAsHex(appendText(buf, "0x"), u.value);
264
- } else {
265
- return appendText(buf, "(pointer size unsupported)");
266
- }
253
+ return appendIntegerAsHex(appendText(buf, "0x"), (boost::uintptr_t) pointer);
267
254
  }
268
255
 
269
256
  static char *
@@ -704,21 +691,21 @@ dumpDiagnostics(AbortHandlerState &state) {
704
691
  end = appendText(end, " ] " PROGRAM_NAME " version: " PASSENGER_VERSION "\n");
705
692
  write_nowarn(STDERR_FILENO, messageBuf, end - messageBuf);
706
693
 
707
- if (lastAssertionFailure.filename != NULL) {
694
+ if (LoggingKit::lastAssertionFailure.filename != NULL) {
708
695
  end = messageBuf;
709
696
  end = appendText(end, state.messagePrefix);
710
697
  end = appendText(end, " ] Last assertion failure: (");
711
- end = appendText(end, lastAssertionFailure.expression);
698
+ end = appendText(end, LoggingKit::lastAssertionFailure.expression);
712
699
  end = appendText(end, "), ");
713
- if (lastAssertionFailure.function != NULL) {
700
+ if (LoggingKit::lastAssertionFailure.function != NULL) {
714
701
  end = appendText(end, "function ");
715
- end = appendText(end, lastAssertionFailure.function);
702
+ end = appendText(end, LoggingKit::lastAssertionFailure.function);
716
703
  end = appendText(end, ", ");
717
704
  }
718
705
  end = appendText(end, "file ");
719
- end = appendText(end, lastAssertionFailure.filename);
706
+ end = appendText(end, LoggingKit::lastAssertionFailure.filename);
720
707
  end = appendText(end, ", line ");
721
- end = appendULL(end, lastAssertionFailure.line);
708
+ end = appendULL(end, LoggingKit::lastAssertionFailure.line);
722
709
  end = appendText(end, ".\n");
723
710
  write_nowarn(STDERR_FILENO, messageBuf, end - messageBuf);
724
711
  }
@@ -1031,10 +1018,10 @@ abortHandler(int signo, siginfo_t *info, void *ctx) {
1031
1018
  __assert_fail(__const char *__assertion, __const char *__file,
1032
1019
  unsigned int __line, __const char *__function)
1033
1020
  {
1034
- lastAssertionFailure.filename = __file;
1035
- lastAssertionFailure.line = __line;
1036
- lastAssertionFailure.function = __function;
1037
- lastAssertionFailure.expression = __assertion;
1021
+ LoggingKit::lastAssertionFailure.filename = __file;
1022
+ LoggingKit::lastAssertionFailure.line = __line;
1023
+ LoggingKit::lastAssertionFailure.function = __function;
1024
+ LoggingKit::lastAssertionFailure.expression = __assertion;
1038
1025
  fprintf(stderr, "Assertion failed! %s:%u: %s: %s\n", __file, __line, __function, __assertion);
1039
1026
  fflush(stderr);
1040
1027
  abort();
@@ -1056,10 +1043,10 @@ abortHandler(int signo, siginfo_t *info, void *ctx) {
1056
1043
 
1057
1044
  extern "C" void
1058
1045
  __assert_rtn(const char *func, const char *file, int line, const char *expr) {
1059
- lastAssertionFailure.filename = file;
1060
- lastAssertionFailure.line = line;
1061
- lastAssertionFailure.function = func;
1062
- lastAssertionFailure.expression = expr;
1046
+ LoggingKit::lastAssertionFailure.filename = file;
1047
+ LoggingKit::lastAssertionFailure.line = line;
1048
+ LoggingKit::lastAssertionFailure.function = func;
1049
+ LoggingKit::lastAssertionFailure.expression = expr;
1063
1050
  if (func) {
1064
1051
  fprintf(stderr, "Assertion failed: (%s), function %s, file %s, line %d.\n",
1065
1052
  expr, func, file, line);
@@ -1470,6 +1457,46 @@ extraArgumentsPassed(int argc, char *argv[], int argStartIndex) {
1470
1457
  || (argc == argStartIndex + 1 && !isBlank(argv[argStartIndex]));
1471
1458
  }
1472
1459
 
1460
+ static void
1461
+ initializeLoggingKit(const char *processName, VariantMap &options) {
1462
+ Json::Value config(Json::objectValue);
1463
+
1464
+ options.setDefaultInt("log_level", DEFAULT_LOG_LEVEL);
1465
+ config["level"] = options.get("log_level");
1466
+
1467
+ if (options.has("log_file")) {
1468
+ config["target"] = options.get("log_file");
1469
+ } else if (options.has("debug_log_file")) {
1470
+ config["target"] = options.get("debug_log_file");
1471
+ }
1472
+
1473
+ if (options.has("file_descriptor_log_file")) {
1474
+ config["file_descriptor_log_target"] =
1475
+ options.get("file_descriptor_log_file");
1476
+ }
1477
+
1478
+ LoggingKit::initialize(config);
1479
+
1480
+ if (options.has("file_descriptor_log_file")) {
1481
+ // This information helps ./dev/parse_file_descriptor_log.
1482
+ FastStringStream<> stream;
1483
+ LoggingKit::_prepareLogEntry(stream, LoggingKit::CRIT, __FILE__, __LINE__);
1484
+ stream << "Starting agent: " << processName << "\n";
1485
+ _writeFileDescriptorLogEntry(LoggingKit::context->getConfigRealization(),
1486
+ stream.data(), stream.size());
1487
+
1488
+ config = LoggingKit::context->getConfig().inspect();
1489
+ P_LOG_FILE_DESCRIPTOR_OPEN4(
1490
+ LoggingKit::context->getConfigRealization()->fileDescriptorLogTargetFd,
1491
+ __FILE__, __LINE__,
1492
+ "file descriptor log file "
1493
+ << config["file_descriptor_log_target"]["effective_value"]["path"].asString());
1494
+ } else {
1495
+ // This information helps ./dev/parse_file_descriptor_log.
1496
+ P_DEBUG("Starting agent: " << processName);
1497
+ }
1498
+ }
1499
+
1473
1500
  VariantMap
1474
1501
  initializeAgent(int argc, char **argv[], const char *processName,
1475
1502
  OptionParserFunc optionParser, PreinitializationFunc preinit,
@@ -1581,46 +1608,7 @@ initializeAgentOptions(const char *processName, VariantMap &options,
1581
1608
  preinit(options);
1582
1609
  }
1583
1610
 
1584
- options.setDefaultInt("log_level", DEFAULT_LOG_LEVEL);
1585
- setLogLevel(options.getInt("log_level"));
1586
- string logFile;
1587
- if (options.has("log_file")) {
1588
- logFile = options.get("log_file");
1589
- } else if (options.has("debug_log_file")) {
1590
- logFile = options.get("debug_log_file");
1591
- }
1592
- if (!logFile.empty()) {
1593
- try {
1594
- logFile = absolutizePath(logFile);
1595
- } catch (const SystemException &e) {
1596
- P_WARN("Cannot absolutize filename '" << logFile
1597
- << "': " << e.what());
1598
- }
1599
- setLogFile(logFile);
1600
- }
1601
-
1602
- if (options.has("file_descriptor_log_file")) {
1603
- logFile = options.get("file_descriptor_log_file");
1604
- try {
1605
- logFile = absolutizePath(logFile);
1606
- } catch (const SystemException &e) {
1607
- P_WARN("Cannot absolutize filename '" << logFile
1608
- << "': " << e.what());
1609
- }
1610
- setFileDescriptorLogFile(logFile);
1611
-
1612
- // This information helps dev/parse_file_descriptor_log.
1613
- FastStringStream<> stream;
1614
- _prepareLogEntry(stream, __FILE__, __LINE__);
1615
- stream << "Starting agent: " << processName << "\n";
1616
- _writeFileDescriptorLogEntry(stream.data(), stream.size());
1617
-
1618
- P_LOG_FILE_DESCRIPTOR_OPEN4(getFileDescriptorLogFileFd(), __FILE__, __LINE__,
1619
- "file descriptor log file " << options.get("file_descriptor_log_file"));
1620
- } else {
1621
- // This information helps dev/parse_file_descriptor_log.
1622
- P_DEBUG("Starting agent: " << processName);
1623
- }
1611
+ initializeLoggingKit(processName, options);
1624
1612
 
1625
1613
  if (hasEnvOption("PASSENGER_USE_FEEDBACK_FD")) {
1626
1614
  P_LOG_FILE_DESCRIPTOR_OPEN2(FEEDBACK_FD, "feedback FD");
@@ -27,11 +27,14 @@
27
27
  #define _PASSENGER_UST_ROUTER_API_SERVER_H_
28
28
 
29
29
  #include <string>
30
+ #include <exception>
30
31
  #include <jsoncpp/json.h>
31
32
  #include <modp_b64.h>
32
33
 
33
34
  #include <ServerKit/HttpServer.h>
34
35
  #include <DataStructures/LString.h>
36
+ #include <LoggingKit/LoggingKit.h>
37
+ #include <LoggingKit/Context.h>
35
38
  #include <Exceptions.h>
36
39
  #include <StaticString.h>
37
40
  #include <Utils/StrIntUtils.h>
@@ -94,19 +97,8 @@ private:
94
97
  }
95
98
 
96
99
  HeaderTable headers;
97
- Json::Value doc;
98
- string logFile = getLogFile();
99
- string fileDescriptorLogFile = getFileDescriptorLogFile();
100
-
100
+ Json::Value doc = LoggingKit::context->getConfig().inspect();
101
101
  headers.insert(req->pool, "Content-Type", "application/json");
102
- doc["log_level"] = getLogLevel();
103
- if (!logFile.empty()) {
104
- doc["log_file"] = logFile;
105
- }
106
- if (!fileDescriptorLogFile.empty()) {
107
- doc["file_descriptor_log_file"] = fileDescriptorLogFile;
108
- }
109
-
110
102
  writeSimpleResponse(client, 200, &headers, doc.toStyledString());
111
103
  if (!req->ended()) {
112
104
  endRequest(&client, &req);
@@ -125,46 +117,43 @@ private:
125
117
 
126
118
  void processConfigBody(Client *client, Request *req) {
127
119
  HeaderTable headers;
128
- Json::Value &json = req->jsonBody;
120
+ LoggingKit::ConfigChangeRequest configReq;
121
+ const Json::Value &json = req->jsonBody;
122
+ vector<ConfigKit::Error> errors;
123
+ bool ok;
129
124
 
130
125
  headers.insert(req->pool, "Content-Type", "application/json");
126
+ headers.insert(req->pool, "Cache-Control", "no-cache, no-store, must-revalidate");
131
127
 
132
- if (json.isMember("log_level")) {
133
- setLogLevel(json["log_level"].asInt());
134
- }
135
- if (json.isMember("log_file")) {
136
- string logFile = json["log_file"].asString();
137
- try {
138
- logFile = absolutizePath(logFile);
139
- } catch (const SystemException &e) {
140
- unsigned int bufsize = 1024;
141
- char *message = (char *) psg_pnalloc(req->pool, bufsize);
142
- snprintf(message, bufsize, "{ \"status\": \"error\", "
143
- "\"message\": \"Cannot absolutize log file filename: %s\" }",
144
- e.what());
145
- writeSimpleResponse(client, 500, &headers, message);
146
- if (!req->ended()) {
147
- endRequest(&client, &req);
148
- }
149
- return;
128
+ try {
129
+ ok = LoggingKit::context->prepareConfigChange(json,
130
+ errors, configReq);
131
+ } catch (const std::exception &e) {
132
+ unsigned int bufsize = 2048;
133
+ char *message = (char *) psg_pnalloc(req->pool, bufsize);
134
+ snprintf(message, bufsize, "{ \"status\": \"error\", "
135
+ "\"message\": \"Error reconfiguring logging system: %s\" }",
136
+ e.what());
137
+ writeSimpleResponse(client, 500, &headers, message);
138
+ if (!req->ended()) {
139
+ endRequest(&client, &req);
150
140
  }
151
-
152
- int e;
153
- if (!setLogFile(logFile, &e)) {
154
- unsigned int bufsize = 1024;
155
- char *message = (char *) psg_pnalloc(req->pool, bufsize);
156
- snprintf(message, bufsize, "{ \"status\": \"error\", "
157
- "\"message\": \"Cannot open log file: %s (errno=%d)\" }",
158
- strerror(e), e);
159
- writeSimpleResponse(client, 500, &headers, message);
160
- if (!req->ended()) {
161
- endRequest(&client, &req);
162
- }
163
- return;
141
+ return;
142
+ }
143
+ if (!ok) {
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
+ ConfigKit::toString(errors).c_str());
149
+ writeSimpleResponse(client, 500, &headers, message);
150
+ if (!req->ended()) {
151
+ endRequest(&client, &req);
164
152
  }
165
- P_NOTICE("Log file opened.");
153
+ return;
166
154
  }
167
155
 
156
+ LoggingKit::context->commitConfigChange(configReq);
168
157
  writeSimpleResponse(client, 200, &headers, "{ \"status\": \"ok\" }\n");
169
158
  if (!req->ended()) {
170
159
  endRequest(&client, &req);