passenger 5.3.4 → 6.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG +69 -0
- data/CONTRIBUTORS +1 -0
- data/README.md +2 -1
- data/Rakefile +0 -5
- data/build/agent.rb +6 -3
- data/build/cxx_tests.rb +28 -19
- data/build/integration_tests.rb +6 -2
- data/build/misc.rb +2 -1
- data/build/packaging.rb +2 -0
- data/build/support/cplusplus.rb +2 -2
- data/build/support/cxx_dependency_map.rb +2651 -2189
- data/dev/colorize-logs +272 -0
- data/dev/show-latest-crashlog-dir +27 -0
- data/resources/templates/standalone/http.erb +2 -0
- data/resources/templates/standalone/server.erb +1 -0
- data/src/agent/AgentMain.cpp +4 -0
- data/src/agent/Core/AdminPanelConnector.h +6 -6
- data/src/agent/Core/ApiServer.h +4 -4
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +2 -2
- data/src/agent/Core/ApplicationPool/Context.h +5 -1
- data/src/agent/Core/ApplicationPool/Group/InternalUtils.cpp +2 -2
- data/src/agent/Core/ApplicationPool/Group/LifetimeAndBasics.cpp +5 -0
- data/src/agent/Core/ApplicationPool/Group/Miscellaneous.cpp +2 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +3 -3
- data/src/agent/Core/ApplicationPool/Group/ProcessListManagement.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/StateInspection.cpp +13 -20
- data/src/agent/Core/ApplicationPool/Group.h +4 -2
- data/src/agent/Core/ApplicationPool/Implementation.cpp +5 -5
- data/src/agent/Core/ApplicationPool/Options.h +42 -38
- data/src/agent/Core/ApplicationPool/Pool/GroupUtils.cpp +2 -1
- data/src/agent/Core/ApplicationPool/Pool.h +4 -4
- data/src/agent/Core/ApplicationPool/Process.h +13 -15
- data/src/agent/Core/ApplicationPool/Socket.h +5 -5
- data/src/agent/Core/ApplicationPool/TestSession.h +3 -3
- data/src/agent/Core/Config.h +50 -10
- data/src/agent/Core/ConfigChange.cpp +13 -1
- data/src/agent/Core/Controller/Config.h +41 -17
- data/src/agent/Core/Controller/ForwardResponse.cpp +4 -0
- data/src/agent/Core/Controller/InitRequest.cpp +14 -8
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +5 -0
- data/src/agent/Core/Controller/SendRequest.cpp +9 -9
- data/src/agent/Core/Controller/TurboCaching.h +2 -2
- data/src/agent/Core/Controller.h +7 -5
- data/src/agent/Core/CoreMain.cpp +204 -60
- data/src/agent/Core/OptionParser.h +20 -3
- data/src/agent/Core/ResponseCache.h +3 -3
- data/src/agent/Core/SecurityUpdateChecker.h +4 -2
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h +1 -1
- data/src/agent/Core/SpawningKit/Config.h +3 -2
- data/src/agent/Core/SpawningKit/Context.h +8 -2
- data/src/agent/Core/SpawningKit/DirectSpawner.h +4 -4
- data/src/agent/Core/SpawningKit/DummySpawner.h +3 -3
- data/src/agent/Core/SpawningKit/ErrorRenderer.h +1 -1
- data/src/agent/Core/SpawningKit/Exceptions.h +21 -14
- data/src/agent/Core/SpawningKit/Factory.h +1 -1
- data/src/agent/Core/SpawningKit/Handshake/BackgroundIOCapturer.h +1 -1
- data/src/agent/Core/SpawningKit/Handshake/Perform.h +14 -2
- data/src/agent/Core/SpawningKit/Handshake/Prepare.h +3 -3
- data/src/agent/Core/SpawningKit/Handshake/WorkDir.h +1 -1
- data/src/agent/Core/SpawningKit/Journey.h +4 -5
- data/src/agent/Core/SpawningKit/PipeWatcher.h +1 -1
- data/src/agent/Core/SpawningKit/README.md +34 -17
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h +1 -1
- data/src/agent/Core/SpawningKit/Result.h +20 -8
- data/src/agent/Core/SpawningKit/SmartSpawner.h +7 -7
- data/src/agent/Core/SpawningKit/Spawner.h +25 -8
- data/src/agent/Core/SpawningKit/UserSwitchingRules.h +17 -7
- data/src/agent/Core/TelemetryCollector.h +681 -0
- data/src/agent/ExecHelper/ExecHelperMain.cpp +1 -1
- data/src/agent/FileReadHelper/FileReadHelperMain.cpp +198 -0
- data/src/agent/README.md +1 -1
- data/src/agent/Shared/ApiAccountUtils.h +1 -1
- data/src/agent/Shared/ApiServerUtils.h +3 -3
- data/src/agent/Shared/ApplicationPoolApiKey.h +2 -2
- data/src/agent/Shared/Fundamentals/AbortHandler.cpp +324 -98
- data/src/agent/Shared/Fundamentals/AbortHandler.h +31 -4
- data/src/agent/Shared/Fundamentals/Initialization.cpp +4 -5
- data/src/agent/Shared/Fundamentals/Initialization.h +9 -1
- data/src/agent/SpawnEnvSetupper/SpawnEnvSetupperMain.cpp +1 -1
- data/src/agent/SystemMetrics/SystemMetricsMain.cpp +4 -3
- data/src/agent/TempDirToucher/TempDirToucherMain.cpp +3 -3
- data/src/agent/Watchdog/ApiServer.h +3 -3
- data/src/agent/Watchdog/Config.h +24 -5
- data/src/agent/Watchdog/CoreWatcher.cpp +2 -2
- data/src/agent/Watchdog/WatchdogMain.cpp +97 -28
- data/src/apache2_module/Config.cpp +14 -14
- data/src/apache2_module/Config.h +8 -16
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp +510 -481
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp.cxxcodebuilder +39 -17
- data/src/apache2_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/AutoGeneratedSetterFuncs.cpp +69 -1
- data/src/apache2_module/ConfigGeneral/AutoGeneratedSetterFuncs.cpp.cxxcodebuilder +31 -1
- data/src/apache2_module/ConfigGeneral/Common.h +45 -0
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp +17 -1
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp.cxxcodebuilder +16 -1
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp +19 -5
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp.cxxcodebuilder +26 -9
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp +19 -1
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp.cxxcodebuilder +10 -1
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp +14 -1
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp.cxxcodebuilder +11 -1
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h +36 -1
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h.cxxcodebuilder +34 -1
- data/src/apache2_module/DirectoryMapper.h +36 -37
- data/src/apache2_module/Hooks.cpp +27 -8
- data/src/apache2_module/ServerConfig/AutoGeneratedManifestGeneration.cpp +20 -0
- data/src/apache2_module/ServerConfig/AutoGeneratedStruct.h +48 -1
- data/src/apache2_module/ServerConfig/AutoGeneratedStruct.h.cxxcodebuilder +36 -1
- data/src/cxx_supportlib/{Utils → Algorithms}/Hasher.cpp +2 -2
- data/src/cxx_supportlib/{Utils → Algorithms}/Hasher.h +4 -4
- data/src/cxx_supportlib/AppLocalConfigFileUtils.h +148 -0
- data/src/cxx_supportlib/AppTypeDetector/CBindings.cpp +147 -0
- data/src/cxx_supportlib/AppTypeDetector/CBindings.h +75 -0
- data/src/cxx_supportlib/{AppTypes.h → AppTypeDetector/Detector.h} +92 -131
- data/src/cxx_supportlib/ConfigKit/README.md +90 -2
- data/src/cxx_supportlib/ConfigKit/Schema.h +60 -15
- data/src/cxx_supportlib/ConfigKit/Store.h +129 -5
- data/src/cxx_supportlib/Constants.h +1 -1
- data/src/cxx_supportlib/{Utils → DataStructures}/HashMap.h +4 -4
- data/src/cxx_supportlib/DataStructures/HashedStaticString.h +5 -5
- data/src/cxx_supportlib/DataStructures/LString.h +3 -3
- data/src/cxx_supportlib/{Utils → DataStructures}/StringMap.h +36 -36
- data/src/cxx_supportlib/FileTools/FileManip.cpp +1 -1
- data/src/cxx_supportlib/FileTools/PathManip.cpp +2 -2
- data/src/cxx_supportlib/FileTools/PathSecurityCheck.cpp +1 -1
- data/src/cxx_supportlib/Hooks.h +2 -2
- data/src/cxx_supportlib/{Utils → IOTools}/BufferedIO.h +5 -5
- data/src/cxx_supportlib/{Utils → IOTools}/IOUtils.cpp +4 -3
- data/src/cxx_supportlib/{Utils → IOTools}/IOUtils.h +3 -3
- data/src/cxx_supportlib/{Utils → IOTools}/MessageIO.h +7 -7
- data/src/cxx_supportlib/{MessageReadersWriters.h → IOTools/MessageSerialization.h} +5 -5
- data/src/cxx_supportlib/InstanceDirectory.h +4 -4
- data/src/cxx_supportlib/Integrations/LibevJsonUtils.h +3 -3
- data/src/cxx_supportlib/{Utils → JsonTools}/JsonUtils.h +5 -5
- data/src/cxx_supportlib/LoggingKit/Context.h +2 -2
- data/src/cxx_supportlib/LoggingKit/Implementation.cpp +3 -3
- data/src/cxx_supportlib/MemoryKit/mbuf.cpp +2 -2
- data/src/cxx_supportlib/ProcessManagement/Ruby.cpp +3 -3
- data/src/cxx_supportlib/ProcessManagement/Ruby.h +7 -2
- data/src/cxx_supportlib/ProcessManagement/Spawn.cpp +19 -12
- data/src/cxx_supportlib/ProcessManagement/Spawn.h +21 -2
- data/src/cxx_supportlib/ProcessManagement/Utils.h +10 -0
- data/src/cxx_supportlib/RandomGenerator.h +2 -2
- data/src/cxx_supportlib/ResourceLocator.h +1 -1
- data/src/cxx_supportlib/{Crypto.cpp → SecurityKit/Crypto.cpp} +4 -4
- data/src/cxx_supportlib/{Crypto.h → SecurityKit/Crypto.h} +4 -4
- data/src/cxx_supportlib/{Utils → SecurityKit}/MemZeroGuard.h +0 -0
- data/src/cxx_supportlib/ServerKit/AcceptLoadBalancer.h +2 -2
- data/src/cxx_supportlib/ServerKit/Channel.h +1 -1
- data/src/cxx_supportlib/ServerKit/ClientRef.h +17 -7
- data/src/cxx_supportlib/ServerKit/Context.h +2 -2
- data/src/cxx_supportlib/ServerKit/FileBufferedChannel.h +1 -1
- data/src/cxx_supportlib/ServerKit/HttpHeaderParser.h +3 -3
- data/src/cxx_supportlib/ServerKit/HttpHeaderParserState.h +2 -2
- data/src/cxx_supportlib/ServerKit/HttpRequestRef.h +17 -7
- data/src/cxx_supportlib/ServerKit/HttpServer.h +16 -10
- data/src/cxx_supportlib/ServerKit/Server.h +3 -4
- data/src/cxx_supportlib/{Utils → StrIntTools}/DateParsing.h +5 -5
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtils.cpp +3 -3
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtils.h +0 -0
- data/src/cxx_supportlib/{Utils → StrIntTools}/StrIntUtilsNoStrictAliasing.cpp +12 -12
- data/src/cxx_supportlib/{Utils → StrIntTools}/StringScanning.h +5 -5
- data/src/cxx_supportlib/{Utils → StrIntTools}/Template.h +30 -5
- data/src/cxx_supportlib/SystemTools/ContainerHelpers.h +88 -0
- data/src/cxx_supportlib/{Utils → SystemTools}/ProcessMetricsCollector.h +15 -12
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemMetricsCollector.h +3 -3
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemTime.cpp +1 -1
- data/src/cxx_supportlib/{Utils → SystemTools}/SystemTime.h +0 -0
- data/src/cxx_supportlib/SystemTools/UserDatabase.h +1 -1
- data/src/cxx_supportlib/Utils/CachedFileStat.hpp +3 -3
- data/src/cxx_supportlib/Utils/Curl.h +2 -2
- data/src/cxx_supportlib/Utils/FileChangeChecker.h +2 -2
- data/src/cxx_supportlib/Utils/MessagePassing.h +1 -1
- data/src/cxx_supportlib/Utils/SpeedMeter.h +2 -2
- data/src/cxx_supportlib/Utils/Timer.h +2 -2
- data/src/cxx_supportlib/Utils/VariantMap.h +3 -3
- data/src/cxx_supportlib/Utils.cpp +2 -2
- data/src/cxx_supportlib/WatchdogLauncher.h +3 -3
- data/src/cxx_supportlib/WebSocketCommandReverseServer.h +1 -1
- data/src/cxx_supportlib/WrapperRegistry/CBindings.cpp +85 -0
- data/src/cxx_supportlib/{Utils/MemoryBarrier.h → WrapperRegistry/CBindings.h} +30 -27
- data/src/cxx_supportlib/WrapperRegistry/Entry.h +112 -0
- data/src/cxx_supportlib/WrapperRegistry/README.md +37 -0
- data/src/cxx_supportlib/WrapperRegistry/Registry.h +309 -0
- data/src/cxx_supportlib/vendor-modified/psg_sysqueue.h +3 -0
- data/src/helper-scripts/download_binaries/extconf.rb +6 -2
- data/src/nginx_module/ConfigGeneral/AutoGeneratedDefinitions.c +32 -0
- data/src/nginx_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.c +12 -0
- data/src/nginx_module/ConfigGeneral/AutoGeneratedSetterFuncs.c +36 -0
- data/src/nginx_module/Configuration.c +23 -3
- data/src/nginx_module/ContentHandler.c +331 -32
- data/src/nginx_module/ContentHandler.h +8 -3
- data/src/nginx_module/LocationConfig/AutoGeneratedCreateFunction.c +10 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedManifestGeneration.c +27 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c +3 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedStruct.h +7 -0
- data/src/nginx_module/MainConfig/AutoGeneratedCreateFunction.c +11 -0
- data/src/nginx_module/MainConfig/AutoGeneratedManifestGeneration.c +23 -0
- data/src/nginx_module/MainConfig/AutoGeneratedStruct.h +8 -0
- data/src/nginx_module/config +2 -1
- data/src/nginx_module/ngx_http_passenger_module.c +9 -3
- data/src/nginx_module/ngx_http_passenger_module.h +10 -3
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +19 -0
- data/src/ruby_supportlib/phusion_passenger/common_library.rb +19 -16
- data/src/ruby_supportlib/phusion_passenger/config/agent_compiler.rb +4 -4
- data/src/ruby_supportlib/phusion_passenger/config/download_agent_command.rb +6 -2
- data/src/ruby_supportlib/phusion_passenger/config/download_nginx_engine_command.rb +6 -2
- data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +1 -1
- data/src/ruby_supportlib/phusion_passenger/message_channel.rb +2 -2
- data/src/ruby_supportlib/phusion_passenger/native_support.rb +7 -3
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +29 -0
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +20 -19
- data/src/ruby_supportlib/phusion_passenger/platform_info/apache.rb +22 -4
- data/src/ruby_supportlib/phusion_passenger/platform_info/ruby.rb +33 -13
- data/src/ruby_supportlib/phusion_passenger/standalone/app_finder.rb +1 -0
- data/src/ruby_supportlib/phusion_passenger/standalone/config_options_list.rb +22 -2
- data/src/ruby_supportlib/phusion_passenger/standalone/start_command/builtin_engine.rb +4 -1
- data/src/ruby_supportlib/phusion_passenger.rb +7 -5
- data/src/schema_printer/SchemaPrinterMain.cpp +2 -0
- metadata +40 -89
- data/.editorconfig +0 -134
- data/CODE_OF_CONDUCT.md +0 -52
- data/dev/boost-patches/0001-Patch-boost-thread-so-that-oxt-thread-can-use-it.patch +0 -48
- data/dev/boost-patches/0002-Make-boost-thread_interrupted-derive-from-oxt-tracab.patch +0 -33
- data/dev/boost-patches/0003-Disable-a-Clang-pragma-to-prevent-warnings-on-OS-X.patch +0 -25
- data/dev/ci/README.md +0 -134
- data/dev/ci/lib/functions.sh +0 -129
- data/dev/ci/lib/set-container-envvars.sh +0 -53
- data/dev/ci/lib/setup-container.sh +0 -46
- data/dev/ci/run-tests-natively +0 -24
- data/dev/ci/run-tests-with-docker +0 -42
- data/dev/ci/scripts/debug-console-wrapper.sh +0 -29
- data/dev/ci/scripts/docker-entrypoint-stage2.sh +0 -17
- data/dev/ci/scripts/docker-entrypoint.sh +0 -17
- data/dev/ci/scripts/inituidgid +0 -17
- data/dev/ci/scripts/run-tests-natively-stage2.sh +0 -17
- data/dev/ci/scripts/setup-host-natively.sh +0 -11
- data/dev/ci/setup-host +0 -56
- data/dev/ci/tests/apache2/run +0 -6
- data/dev/ci/tests/apache2/setup +0 -4
- data/dev/ci/tests/binaries/Jenkinsfile +0 -105
- data/dev/ci/tests/binaries/build-linux +0 -38
- data/dev/ci/tests/binaries/build-macos +0 -40
- data/dev/ci/tests/binaries/prepare-macos +0 -38
- data/dev/ci/tests/binaries/test-linux +0 -45
- data/dev/ci/tests/binaries/test-macos +0 -38
- data/dev/ci/tests/cxx/run +0 -9
- data/dev/ci/tests/cxx/setup +0 -4
- data/dev/ci/tests/debian/Jenkinsfile +0 -89
- data/dev/ci/tests/debian/run +0 -60
- data/dev/ci/tests/nginx/run +0 -5
- data/dev/ci/tests/nginx/setup +0 -4
- data/dev/ci/tests/nginx-dynamic/run +0 -20
- data/dev/ci/tests/nginx-dynamic/setup +0 -4
- data/dev/ci/tests/nodejs/run +0 -4
- data/dev/ci/tests/nodejs/setup +0 -4
- data/dev/ci/tests/rpm/Jenkinsfile +0 -68
- data/dev/ci/tests/rpm/run +0 -63
- data/dev/ci/tests/ruby/run +0 -4
- data/dev/ci/tests/ruby/setup +0 -4
- data/dev/ci/tests/source-packaging/run +0 -4
- data/dev/ci/tests/source-packaging/setup +0 -4
- data/dev/ci/tests/standalone/run +0 -4
- data/dev/ci/tests/standalone/setup +0 -4
- data/dev/configkit-schemas/index.json +0 -1748
- data/dev/configkit-schemas/update_schema_inline_comments.rb +0 -118
- data/dev/rack.test/config.ru +0 -5
- data/dev/rack.test/public/asset.txt +0 -1
- data/dev/vagrant/apache_default_site.conf +0 -35
- data/dev/vagrant/apache_passenger.conf +0 -5
- data/dev/vagrant/apache_passenger.load +0 -1
- data/dev/vagrant/apache_ports.conf +0 -24
- data/dev/vagrant/apache_rack_test.conf +0 -9
- data/dev/vagrant/bashrc +0 -23
- data/dev/vagrant/nginx.conf +0 -39
- data/dev/vagrant/nginx_rakefile +0 -33
- data/dev/vagrant/nginx_start +0 -32
- data/dev/vagrant/provision.sh +0 -117
- data/dev/vagrant/sudoers.conf +0 -5
- data/resources/templates/error_renderer/.editorconfig +0 -19
- data/src/cxx_supportlib/AppTypes.cpp +0 -109
- data/src/cxx_supportlib/vendor-modified/SmallVector.h +0 -653
@@ -0,0 +1,148 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2018 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_APP_LOCAL_CONFIG_FILE_UTILS_H_
|
27
|
+
#define _PASSENGER_APP_LOCAL_CONFIG_FILE_UTILS_H_
|
28
|
+
|
29
|
+
#include <oxt/system_calls.hpp>
|
30
|
+
#include <oxt/backtrace.hpp>
|
31
|
+
|
32
|
+
#include <cerrno>
|
33
|
+
#include <fcntl.h>
|
34
|
+
|
35
|
+
#include <jsoncpp/json.h>
|
36
|
+
|
37
|
+
#include <StaticString.h>
|
38
|
+
#include <Constants.h>
|
39
|
+
#include <Exceptions.h>
|
40
|
+
#include <IOTools/IOUtils.h>
|
41
|
+
#include <Utils/ScopeGuard.h>
|
42
|
+
|
43
|
+
namespace Passenger {
|
44
|
+
|
45
|
+
using namespace std;
|
46
|
+
|
47
|
+
|
48
|
+
struct AppLocalConfig {
|
49
|
+
string appStartCommand;
|
50
|
+
bool appSupportsKuriaProtocol;
|
51
|
+
|
52
|
+
AppLocalConfig()
|
53
|
+
: appSupportsKuriaProtocol(false)
|
54
|
+
{ }
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
inline AppLocalConfig
|
59
|
+
parseAppLocalConfigFile(const StaticString appRoot) {
|
60
|
+
TRACE_POINT();
|
61
|
+
string path = appRoot + "/Passengerfile.json";
|
62
|
+
|
63
|
+
// Reading from Passengerfile.json from a root process is unsafe
|
64
|
+
// because of symlink attacks and other kinds of attacks. See the
|
65
|
+
// comments for safeReadFile().
|
66
|
+
//
|
67
|
+
// We are unable to use safeReadFile() here because we do not
|
68
|
+
// control the safety of the directories leading up to appRoot.
|
69
|
+
//
|
70
|
+
// What we can do is preventing the contents of an arbitrary
|
71
|
+
// file read from leaking out. Therefore, our result struct
|
72
|
+
// only contains a limited number of fields, that are known
|
73
|
+
// not to contain sensitive information. We also don't propagate
|
74
|
+
// JSON parsing error messages, which may contain the content.
|
75
|
+
|
76
|
+
int fd = syscalls::open(path.c_str(), O_RDONLY | O_NONBLOCK);
|
77
|
+
if (fd == -1) {
|
78
|
+
if (errno == ENOENT) {
|
79
|
+
return AppLocalConfig();
|
80
|
+
} else {
|
81
|
+
int e = errno;
|
82
|
+
throw FileSystemException("Error opening '" + path
|
83
|
+
+ "' for reading", e, path);
|
84
|
+
}
|
85
|
+
}
|
86
|
+
|
87
|
+
UPDATE_TRACE_POINT();
|
88
|
+
FdGuard fdGuard(fd, __FILE__, __LINE__);
|
89
|
+
pair<string, bool> content;
|
90
|
+
try {
|
91
|
+
content = readAll(fd, 1024 * 512);
|
92
|
+
} catch (const SystemException &e) {
|
93
|
+
throw FileSystemException("Error reading from '" + path + "'",
|
94
|
+
e.code(), path);
|
95
|
+
}
|
96
|
+
if (!content.second) {
|
97
|
+
throw SecurityException("Error parsing " + path
|
98
|
+
+ ": file exceeds size limit of 512 KB");
|
99
|
+
}
|
100
|
+
fdGuard.runNow();
|
101
|
+
|
102
|
+
UPDATE_TRACE_POINT();
|
103
|
+
Json::Reader reader;
|
104
|
+
Json::Value config;
|
105
|
+
if (!reader.parse(content.first, config)) {
|
106
|
+
if (geteuid() == 0) {
|
107
|
+
throw RuntimeException("Error parsing " + path
|
108
|
+
+ " (error messages suppressed for security reasons)");
|
109
|
+
} else {
|
110
|
+
throw RuntimeException("Error parsing " + path + ": "
|
111
|
+
+ reader.getFormattedErrorMessages());
|
112
|
+
}
|
113
|
+
}
|
114
|
+
// We no longer need the raw data so free the memory.
|
115
|
+
content.first.resize(0);
|
116
|
+
|
117
|
+
|
118
|
+
UPDATE_TRACE_POINT();
|
119
|
+
AppLocalConfig result;
|
120
|
+
|
121
|
+
if (!config.isObject()) {
|
122
|
+
throw RuntimeException("Config file " + path
|
123
|
+
+ " is not valid: top-level JSON object expected");
|
124
|
+
}
|
125
|
+
if (config.isMember("app_start_command")) {
|
126
|
+
if (config["app_start_command"].isString()) {
|
127
|
+
result.appStartCommand = config["app_start_command"].asString();
|
128
|
+
} else {
|
129
|
+
throw RuntimeException("Config file " + path
|
130
|
+
+ " is not valid: key 'app_start_command' must be a boolean");
|
131
|
+
}
|
132
|
+
}
|
133
|
+
if (config.isMember("app_supports_kuria_protocol")) {
|
134
|
+
if (config["app_supports_kuria_protocol"].isBool()) {
|
135
|
+
result.appSupportsKuriaProtocol = config["app_supports_kuria_protocol"].asBool();
|
136
|
+
} else {
|
137
|
+
throw RuntimeException("Config file " + path
|
138
|
+
+ " is not valid: key 'app_supports_kuria_protocol' must be a boolean");
|
139
|
+
}
|
140
|
+
}
|
141
|
+
|
142
|
+
return result;
|
143
|
+
}
|
144
|
+
|
145
|
+
|
146
|
+
} // namespace Passenger
|
147
|
+
|
148
|
+
#endif /* _PASSENGER_APP_LOCAL_CONFIG_FILE_UTILS_H_ */
|
@@ -0,0 +1,147 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2018 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 <cstddef>
|
28
|
+
#include <new>
|
29
|
+
#include <exception>
|
30
|
+
|
31
|
+
#include <StaticString.h>
|
32
|
+
#include <AppTypeDetector/CBindings.h>
|
33
|
+
#include <AppTypeDetector/Detector.h>
|
34
|
+
|
35
|
+
using namespace Passenger;
|
36
|
+
using namespace Passenger::WrapperRegistry;
|
37
|
+
using namespace Passenger::AppTypeDetector;
|
38
|
+
|
39
|
+
|
40
|
+
size_t
|
41
|
+
psg_app_type_detector_result_get_object_size() {
|
42
|
+
return sizeof(Detector::Result);
|
43
|
+
}
|
44
|
+
|
45
|
+
PsgAppTypeDetectorResult *
|
46
|
+
psg_app_type_detector_result_init(void *memory) {
|
47
|
+
Detector::Result *cxxResult = new (memory) Detector::Result();
|
48
|
+
return static_cast<PsgAppTypeDetectorResult *>(cxxResult);
|
49
|
+
}
|
50
|
+
|
51
|
+
void
|
52
|
+
psg_app_type_detector_result_deinit(PsgAppTypeDetectorResult *result) {
|
53
|
+
Detector::Result *cxxResult = static_cast<Detector::Result *>(result);
|
54
|
+
cxxResult->~Result();
|
55
|
+
}
|
56
|
+
|
57
|
+
int
|
58
|
+
psg_app_type_detector_result_is_null(const PsgAppTypeDetectorResult *result) {
|
59
|
+
const Detector::Result *cxxResult = static_cast<const Detector::Result *>(result);
|
60
|
+
return (int) cxxResult->isNull();
|
61
|
+
}
|
62
|
+
|
63
|
+
const PsgWrapperRegistryEntry *
|
64
|
+
psg_app_type_detector_result_get_wrapper_registry_entry(const PsgAppTypeDetectorResult *result) {
|
65
|
+
const Detector::Result *cxxResult = static_cast<const Detector::Result *>(result);
|
66
|
+
return static_cast<const PsgWrapperRegistryEntry *>(cxxResult->wrapperRegistryEntry);
|
67
|
+
}
|
68
|
+
|
69
|
+
void
|
70
|
+
psg_app_type_detector_result_set_wrapper_registry_entry(PsgAppTypeDetectorResult *result,
|
71
|
+
const PsgWrapperRegistryEntry *entry)
|
72
|
+
{
|
73
|
+
Detector::Result *cxxResult = static_cast<Detector::Result *>(result);
|
74
|
+
cxxResult->wrapperRegistryEntry = static_cast<const WrapperRegistry::Entry *>(entry);
|
75
|
+
}
|
76
|
+
|
77
|
+
const char *
|
78
|
+
psg_app_type_detector_result_get_app_start_command(const PsgAppTypeDetectorResult *result,
|
79
|
+
size_t *len)
|
80
|
+
{
|
81
|
+
const Detector::Result *cxxResult = static_cast<const Detector::Result *>(result);
|
82
|
+
if (len != NULL) {
|
83
|
+
*len = cxxResult->appStartCommand.size();
|
84
|
+
}
|
85
|
+
return cxxResult->appStartCommand.data();
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
PsgAppTypeDetector *
|
90
|
+
psg_app_type_detector_new(const PsgWrapperRegistry *registry,
|
91
|
+
unsigned int throttleRate)
|
92
|
+
{
|
93
|
+
const Registry *cxxRegistry = static_cast<const Registry *>(registry);
|
94
|
+
try {
|
95
|
+
Detector *detector = new Detector(*cxxRegistry, NULL, NULL, throttleRate, NULL);
|
96
|
+
return static_cast<PsgAppTypeDetector *>(detector);
|
97
|
+
} catch (const std::bad_alloc &) {
|
98
|
+
return NULL;
|
99
|
+
}
|
100
|
+
}
|
101
|
+
|
102
|
+
void
|
103
|
+
psg_app_type_detector_free(PsgAppTypeDetector *detector) {
|
104
|
+
Detector *cxxDetector = static_cast<Detector *>(detector);
|
105
|
+
delete cxxDetector;
|
106
|
+
}
|
107
|
+
|
108
|
+
void
|
109
|
+
psg_app_type_detector_set_throttle_rate(PsgAppTypeDetector *detector,
|
110
|
+
unsigned int throttleRate)
|
111
|
+
{
|
112
|
+
Detector *cxxDetector = static_cast<Detector *>(detector);
|
113
|
+
cxxDetector->setThrottleRate(throttleRate);
|
114
|
+
}
|
115
|
+
|
116
|
+
void
|
117
|
+
psg_app_type_detector_check_document_root(
|
118
|
+
PsgAppTypeDetector *detector, PsgAppTypeDetectorResult *result,
|
119
|
+
const char *documentRoot, unsigned int len, int resolveFirstSymlink,
|
120
|
+
PP_Error *error)
|
121
|
+
{
|
122
|
+
Detector *cxxDetector = static_cast<Detector *>(detector);
|
123
|
+
Detector::Result *cxxResult = static_cast<Detector::Result *>(result);
|
124
|
+
try {
|
125
|
+
*cxxResult = cxxDetector->checkDocumentRoot(
|
126
|
+
StaticString(documentRoot, len), resolveFirstSymlink);
|
127
|
+
} catch (const std::exception &e) {
|
128
|
+
pp_error_set(e, error);
|
129
|
+
*cxxResult = Detector::Result();
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
void
|
134
|
+
psg_app_type_detector_check_app_root(
|
135
|
+
PsgAppTypeDetector *detector, PsgAppTypeDetectorResult *result,
|
136
|
+
const char *appRoot, unsigned int len, PP_Error *error)
|
137
|
+
{
|
138
|
+
Detector *cxxDetector = static_cast<Detector *>(detector);
|
139
|
+
Detector::Result *cxxResult = static_cast<Detector::Result *>(result);
|
140
|
+
try {
|
141
|
+
*cxxResult = cxxDetector->checkAppRoot(
|
142
|
+
StaticString(appRoot, len));
|
143
|
+
} catch (const std::exception &e) {
|
144
|
+
pp_error_set(e, error);
|
145
|
+
*cxxResult = Detector::Result();
|
146
|
+
}
|
147
|
+
}
|
@@ -0,0 +1,75 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2018 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_APP_TYPE_DETECTOR_CBINDINGS_H_
|
27
|
+
#define _PASSENGER_APP_TYPE_DETECTOR_CBINDINGS_H_
|
28
|
+
|
29
|
+
#include <stddef.h>
|
30
|
+
#include "../WrapperRegistry/CBindings.h"
|
31
|
+
#include "../Exceptions.h"
|
32
|
+
|
33
|
+
#ifdef __cplusplus
|
34
|
+
extern "C" {
|
35
|
+
#endif
|
36
|
+
|
37
|
+
|
38
|
+
typedef void PsgAppTypeDetectorResult;
|
39
|
+
|
40
|
+
size_t psg_app_type_detector_result_get_object_size();
|
41
|
+
PsgAppTypeDetectorResult *psg_app_type_detector_result_init(void *memory);
|
42
|
+
void psg_app_type_detector_result_deinit(PsgAppTypeDetectorResult *result);
|
43
|
+
|
44
|
+
int psg_app_type_detector_result_is_null(const PsgAppTypeDetectorResult *result);
|
45
|
+
const PsgWrapperRegistryEntry *psg_app_type_detector_result_get_wrapper_registry_entry(
|
46
|
+
const PsgAppTypeDetectorResult *result);
|
47
|
+
void psg_app_type_detector_result_set_wrapper_registry_entry(PsgAppTypeDetectorResult *result,
|
48
|
+
const PsgWrapperRegistryEntry *entry);
|
49
|
+
const char *psg_app_type_detector_result_get_app_start_command(const PsgAppTypeDetectorResult *result,
|
50
|
+
size_t *len);
|
51
|
+
|
52
|
+
|
53
|
+
typedef void PsgAppTypeDetector;
|
54
|
+
|
55
|
+
PsgAppTypeDetector *psg_app_type_detector_new(const PsgWrapperRegistry *registry,
|
56
|
+
unsigned int throttleRate);
|
57
|
+
void psg_app_type_detector_free(PsgAppTypeDetector *detector);
|
58
|
+
void psg_app_type_detector_set_throttle_rate(PsgAppTypeDetector *detector,
|
59
|
+
unsigned int throttleRate);
|
60
|
+
void psg_app_type_detector_check_document_root(
|
61
|
+
PsgAppTypeDetector *detector,
|
62
|
+
PsgAppTypeDetectorResult *result,
|
63
|
+
const char *documentRoot, unsigned int len, int resolveFirstSymlink,
|
64
|
+
PP_Error *error);
|
65
|
+
void psg_app_type_detector_check_app_root(
|
66
|
+
PsgAppTypeDetector *detector,
|
67
|
+
PsgAppTypeDetectorResult *result,
|
68
|
+
const char *appRoot, unsigned int len, PP_Error *error);
|
69
|
+
|
70
|
+
|
71
|
+
#ifdef __cplusplus
|
72
|
+
} // extern "C"
|
73
|
+
#endif
|
74
|
+
|
75
|
+
#endif /* _PASSENGER_APP_TYPE_DETECTOR_CBINDINGS_H_ */
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/*
|
2
2
|
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
-
* Copyright (c)
|
3
|
+
* Copyright (c) 2018 Phusion Holding B.V.
|
4
4
|
*
|
5
5
|
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
6
|
* trademarks of Phusion Holding B.V.
|
@@ -23,117 +23,115 @@
|
|
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
|
27
|
-
#define
|
28
|
-
|
29
|
-
/**
|
30
|
-
* Application type registry
|
31
|
-
*
|
32
|
-
* All supported application types (e.g. Rack, classic Rails, WSGI, etc)
|
33
|
-
* are registered here. The AppTypeDetector is responsible for checking
|
34
|
-
* what kind of application lives under the given directory.
|
35
|
-
*/
|
36
|
-
|
37
|
-
#include "Exceptions.h"
|
38
|
-
|
39
|
-
|
40
|
-
#ifdef __cplusplus
|
41
|
-
extern "C" {
|
42
|
-
#endif /* __cplusplus */
|
43
|
-
|
44
|
-
typedef enum {
|
45
|
-
PAT_RACK,
|
46
|
-
PAT_WSGI,
|
47
|
-
PAT_NODE,
|
48
|
-
PAT_METEOR,
|
49
|
-
PAT_NONE,
|
50
|
-
PAT_ERROR
|
51
|
-
} PassengerAppType;
|
52
|
-
|
53
|
-
typedef void PP_AppTypeDetector;
|
54
|
-
|
55
|
-
PP_AppTypeDetector *pp_app_type_detector_new(unsigned int throttleRate);
|
56
|
-
void pp_app_type_detector_free(PP_AppTypeDetector *detector);
|
57
|
-
void pp_app_type_detector_set_throttle_rate(PP_AppTypeDetector *detector,
|
58
|
-
unsigned int throttleRate);
|
59
|
-
PassengerAppType pp_app_type_detector_check_document_root(PP_AppTypeDetector *detector,
|
60
|
-
const char *documentRoot, unsigned int len, int resolveFirstSymlink,
|
61
|
-
PP_Error *error);
|
62
|
-
PassengerAppType pp_app_type_detector_check_app_root(PP_AppTypeDetector *detector,
|
63
|
-
const char *appRoot, unsigned int len, PP_Error *error);
|
64
|
-
|
65
|
-
const char *pp_get_app_type_name(PassengerAppType type);
|
66
|
-
PassengerAppType pp_get_app_type2(const char *name, unsigned int len);
|
67
|
-
|
68
|
-
#ifdef __cplusplus
|
69
|
-
}
|
70
|
-
#endif /* __cplusplus */
|
26
|
+
#ifndef _PASSENGER_APP_TYPE_DECTECTOR_H_
|
27
|
+
#define _PASSENGER_APP_TYPE_DECTECTOR_H_
|
71
28
|
|
29
|
+
#include <limits.h>
|
72
30
|
|
73
|
-
#
|
31
|
+
#include <boost/thread.hpp>
|
32
|
+
#include <boost/foreach.hpp>
|
74
33
|
#include <oxt/macros.hpp>
|
75
34
|
#include <oxt/backtrace.hpp>
|
76
|
-
|
77
|
-
#include <
|
78
|
-
#include <
|
35
|
+
|
36
|
+
#include <cassert>
|
37
|
+
#include <cstddef>
|
79
38
|
#include <string>
|
80
|
-
|
81
|
-
#include <
|
39
|
+
|
40
|
+
#include <Exceptions.h>
|
41
|
+
#include <AppLocalConfigFileUtils.h>
|
42
|
+
#include <WrapperRegistry/Registry.h>
|
82
43
|
#include <FileTools/PathManip.h>
|
83
44
|
#include <FileTools/FileManip.h>
|
45
|
+
#include <StrIntTools/StrIntUtils.h>
|
46
|
+
#include <DataStructures/StringKeyTable.h>
|
84
47
|
#include <Utils.h>
|
85
|
-
#include <Utils/StrIntUtils.h>
|
86
48
|
#include <Utils/CachedFileStat.hpp>
|
87
49
|
|
88
50
|
namespace Passenger {
|
51
|
+
namespace AppTypeDetector {
|
89
52
|
|
90
53
|
using namespace std;
|
91
54
|
|
55
|
+
typedef AppLocalConfig* AppLocalConfigPtr;
|
56
|
+
typedef StringKeyTable<AppLocalConfig> AppLocalConfigMap;
|
92
57
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
};
|
58
|
+
class Detector {
|
59
|
+
public:
|
60
|
+
struct Result {
|
61
|
+
const WrapperRegistry::Entry *wrapperRegistryEntry;
|
62
|
+
string appStartCommand;
|
99
63
|
|
100
|
-
|
64
|
+
Result()
|
65
|
+
: wrapperRegistryEntry(NULL)
|
66
|
+
{ }
|
101
67
|
|
68
|
+
bool isNull() const {
|
69
|
+
return wrapperRegistryEntry == NULL && appStartCommand.empty();
|
70
|
+
}
|
71
|
+
};
|
102
72
|
|
103
|
-
class AppTypeDetector {
|
104
73
|
private:
|
74
|
+
const WrapperRegistry::Registry ®istry;
|
105
75
|
CachedFileStat *cstat;
|
106
76
|
boost::mutex *cstatMutex;
|
107
77
|
unsigned int throttleRate;
|
108
78
|
bool ownsCstat;
|
79
|
+
AppLocalConfigMap appLocalConfigCache;
|
80
|
+
boost::mutex *configMutex;
|
81
|
+
StringKeyTable<time_t> appRootCheckTimes;
|
109
82
|
|
110
|
-
bool check(char *buf, const char *end, const StaticString &appRoot,
|
83
|
+
bool check(char *buf, const char *end, const StaticString &appRoot,
|
84
|
+
const StaticString &name)
|
85
|
+
{
|
111
86
|
char *pos = buf;
|
112
87
|
pos = appendData(pos, end, appRoot);
|
113
|
-
pos = appendData(pos, end, "/");
|
88
|
+
pos = appendData(pos, end, "/", 1);
|
114
89
|
pos = appendData(pos, end, name);
|
115
90
|
pos = appendData(pos, end, "\0", 1);
|
116
91
|
if (OXT_UNLIKELY(pos == end)) {
|
117
92
|
TRACE_POINT();
|
118
93
|
throw RuntimeException("Not enough buffer space");
|
119
94
|
}
|
120
|
-
return getFileType(StaticString(buf, pos - buf - 1),
|
95
|
+
return getFileType(StaticString(buf, pos - buf - 1),
|
96
|
+
cstat, cstatMutex, throttleRate) != FT_NONEXISTANT;
|
97
|
+
}
|
98
|
+
|
99
|
+
AppLocalConfigPtr getAppLocalConfigFromCache(const StaticString &appRoot) {
|
100
|
+
boost::unique_lock<boost::mutex> l;
|
101
|
+
time_t currentTime = SystemTime::get();
|
102
|
+
if (configMutex != NULL) {
|
103
|
+
l = boost::unique_lock<boost::mutex>(*configMutex);
|
104
|
+
}
|
105
|
+
if (!appLocalConfigCache.contains(appRoot)
|
106
|
+
|| currentTime >= (appRootCheckTimes.lookupCopy(appRoot) + throttleRate)) {
|
107
|
+
AppLocalConfig config = parseAppLocalConfigFile(appRoot);
|
108
|
+
appLocalConfigCache.insert(appRoot, config);
|
109
|
+
appRootCheckTimes.insert(appRoot, currentTime);
|
110
|
+
}
|
111
|
+
AppLocalConfigPtr appLocalConfig;
|
112
|
+
appLocalConfigCache.lookup(appRoot, &appLocalConfig);
|
113
|
+
return appLocalConfig;
|
121
114
|
}
|
122
115
|
|
123
116
|
public:
|
124
|
-
|
125
|
-
|
117
|
+
Detector(const WrapperRegistry::Registry &_registry,
|
118
|
+
CachedFileStat *_cstat = NULL, boost::mutex *_cstatMutex = NULL,
|
119
|
+
unsigned int _throttleRate = 1, boost::mutex *_configMutex = NULL)
|
120
|
+
: registry(_registry),
|
121
|
+
cstat(_cstat),
|
126
122
|
cstatMutex(_cstatMutex),
|
127
123
|
throttleRate(_throttleRate),
|
128
|
-
ownsCstat(false)
|
124
|
+
ownsCstat(false),
|
125
|
+
configMutex(_configMutex)
|
129
126
|
{
|
127
|
+
assert(_registry.isFinalized());
|
130
128
|
if (_cstat == NULL) {
|
131
129
|
cstat = new CachedFileStat();
|
132
130
|
ownsCstat = true;
|
133
131
|
}
|
134
132
|
}
|
135
133
|
|
136
|
-
~
|
134
|
+
~Detector() {
|
137
135
|
if (ownsCstat) {
|
138
136
|
delete cstat;
|
139
137
|
}
|
@@ -146,7 +144,7 @@ public:
|
|
146
144
|
/**
|
147
145
|
* Given a web server document root (that is, some subdirectory under the
|
148
146
|
* application root, e.g. "/webapps/foobar/public"), returns the type of
|
149
|
-
* application that lives there. Returns
|
147
|
+
* application that lives there. Returns a null result if it wasn't able to detect
|
150
148
|
* a supported application type.
|
151
149
|
*
|
152
150
|
* If `resolveFirstSymlink` is given, and `documentRoot` is a symlink, then
|
@@ -161,7 +159,7 @@ public:
|
|
161
159
|
* @throws TimeRetrievalException
|
162
160
|
* @throws boost::thread_interrupted
|
163
161
|
*/
|
164
|
-
|
162
|
+
const Result checkDocumentRoot(const StaticString &documentRoot,
|
165
163
|
bool resolveFirstSymlink = false,
|
166
164
|
string *appRoot = NULL)
|
167
165
|
{
|
@@ -193,83 +191,46 @@ public:
|
|
193
191
|
|
194
192
|
/**
|
195
193
|
* Returns the type of application that lives under the application
|
196
|
-
* directory `appRoot`. Returns
|
194
|
+
* directory `appRoot`. Returns a null result if it wasn't able to detect
|
197
195
|
* a supported application type.
|
198
196
|
*
|
199
197
|
* @throws FileSystemException Unable to check because of a filesystem error.
|
200
198
|
* @throws TimeRetrievalException
|
201
199
|
* @throws boost::thread_interrupted
|
202
200
|
*/
|
203
|
-
|
201
|
+
const Result checkAppRoot(const StaticString &appRoot) {
|
204
202
|
char buf[PATH_MAX + 32];
|
205
203
|
const char *end = buf + sizeof(buf) - 1;
|
206
|
-
const AppTypeDefinition *definition = &appTypeDefinitions[0];
|
207
|
-
|
208
|
-
while (definition->type != PAT_NONE) {
|
209
|
-
if (check(buf, end, appRoot, definition->startupFile)) {
|
210
|
-
return definition->type;
|
211
|
-
}
|
212
|
-
definition++;
|
213
|
-
}
|
214
|
-
return PAT_NONE;
|
215
|
-
}
|
216
|
-
};
|
217
204
|
|
205
|
+
AppLocalConfigPtr appLocalConfig = getAppLocalConfigFromCache(appRoot);
|
218
206
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
while (definition->type != PAT_NONE) {
|
224
|
-
if (definition->type == type) {
|
225
|
-
return definition->name;
|
207
|
+
if (!appLocalConfig->appStartCommand.empty()) {
|
208
|
+
Result result;
|
209
|
+
result.appStartCommand = appLocalConfig->appStartCommand;
|
210
|
+
return result;
|
226
211
|
}
|
227
|
-
definition++;
|
228
|
-
}
|
229
|
-
return NULL;
|
230
|
-
}
|
231
212
|
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
}
|
244
|
-
|
245
|
-
inline const char *
|
246
|
-
getAppTypeStartupFile(PassengerAppType type) {
|
247
|
-
const AppTypeDefinition *definition = &appTypeDefinitions[0];
|
248
|
-
|
249
|
-
while (definition->type != PAT_NONE) {
|
250
|
-
if (definition->type == type) {
|
251
|
-
return definition->startupFile;
|
213
|
+
WrapperRegistry::Registry::ConstIterator it(registry.getIterator());
|
214
|
+
while (*it != NULL) {
|
215
|
+
const WrapperRegistry::Entry &entry = it.getValue();
|
216
|
+
foreach (const StaticString &defaultStartupFile,
|
217
|
+
entry.defaultStartupFiles)
|
218
|
+
{
|
219
|
+
if (check(buf, end, appRoot, defaultStartupFile)) {
|
220
|
+
Result result;
|
221
|
+
result.wrapperRegistryEntry = &entry;
|
222
|
+
return result;
|
223
|
+
}
|
224
|
+
}
|
225
|
+
it.next();
|
252
226
|
}
|
253
|
-
definition++;
|
254
|
-
}
|
255
|
-
return NULL;
|
256
|
-
}
|
257
|
-
|
258
|
-
inline const char *
|
259
|
-
getAppTypeProcessTitle(PassengerAppType type) {
|
260
|
-
const AppTypeDefinition *definition = &appTypeDefinitions[0];
|
261
227
|
|
262
|
-
|
263
|
-
if (definition->type == type) {
|
264
|
-
return definition->processTitle;
|
265
|
-
}
|
266
|
-
definition++;
|
228
|
+
return Result();
|
267
229
|
}
|
268
|
-
|
269
|
-
}
|
230
|
+
};
|
270
231
|
|
271
232
|
|
233
|
+
} // namespace AppTypeDetector
|
272
234
|
} // namespace Passenger
|
273
|
-
#endif /* __cplusplus */
|
274
235
|
|
275
|
-
#endif /*
|
236
|
+
#endif /* _PASSENGER_APP_TYPE_DECTECTOR_H_ */
|