passenger 5.2.3 → 5.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG +13 -0
- data/CONTRIBUTORS +5 -1
- data/build/agent.rb +22 -2
- data/build/cxx_tests.rb +41 -5
- data/build/misc.rb +4 -1
- data/build/support/cxx_dependency_map.rb +1746 -908
- data/build/support/vendor/cxx_hinted_parser/CxxHintedParser.sublime-project +8 -0
- data/build/support/vendor/cxx_hinted_parser/Gemfile +5 -0
- data/build/support/vendor/cxx_hinted_parser/Gemfile.lock +30 -0
- data/{src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core → build/support/vendor/cxx_hinted_parser}/LICENSE.md +1 -1
- data/build/support/vendor/cxx_hinted_parser/README.md +95 -0
- data/build/support/vendor/cxx_hinted_parser/Rakefile +4 -0
- data/{src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/initialize.rb → build/support/vendor/cxx_hinted_parser/lib/cxx_hinted_parser.rb} +2 -9
- data/build/support/vendor/cxx_hinted_parser/lib/cxx_hinted_parser/parser.rb +239 -0
- data/dev/ci/README.md +15 -2
- data/dev/ci/lib/set-container-envvars.sh +6 -0
- data/dev/ci/lib/setup-container.sh +4 -1
- data/dev/ci/scripts/debug-console-wrapper.sh +3 -1
- data/dev/ci/setup-host +5 -0
- data/dev/ci/tests/binaries/Jenkinsfile +105 -0
- data/dev/ci/tests/binaries/build-linux +38 -0
- data/dev/ci/tests/binaries/build-macos +40 -0
- data/dev/ci/tests/binaries/prepare-macos +38 -0
- data/dev/ci/tests/binaries/test-linux +45 -0
- data/dev/ci/tests/binaries/test-macos +38 -0
- data/dev/ci/tests/debian/Jenkinsfile +2 -2
- data/dev/ci/tests/rpm/Jenkinsfile +1 -1
- data/dev/configkit-schemas/index.json +3 -24
- data/dev/vagrant/nginx_rakefile +0 -1
- data/package.json +15 -5
- data/resources/templates/error_renderer/.editorconfig +19 -0
- data/resources/templates/error_renderer/with_details/README.md +9 -0
- data/resources/templates/error_renderer/with_details/dist/bundle.js +33 -0
- data/resources/templates/error_renderer/with_details/dist/styles.css +17 -0
- data/resources/templates/error_renderer/with_details/src/DetailsView.jsx +52 -0
- data/resources/templates/error_renderer/with_details/src/GetHelpView.jsx +61 -0
- data/resources/templates/error_renderer/with_details/src/JourneyView.css +50 -0
- data/resources/templates/error_renderer/with_details/src/JourneyView.jsx +621 -0
- data/resources/templates/error_renderer/with_details/src/PageMain.css +114 -0
- data/resources/templates/error_renderer/with_details/src/PageMain.jsx +136 -0
- data/resources/templates/error_renderer/with_details/src/ProblemDescriptionView.jsx +14 -0
- data/resources/templates/error_renderer/with_details/src/ProcessDetailsView.jsx +56 -0
- data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.css +5 -0
- data/resources/templates/error_renderer/with_details/src/SolutionDescriptionView.jsx +15 -0
- data/resources/templates/error_renderer/with_details/src/SummaryView.jsx +35 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentView.css +34 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentView.jsx +168 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentsView.css +13 -0
- data/resources/templates/error_renderer/with_details/src/SystemComponentsView.jsx +116 -0
- data/resources/templates/error_renderer/with_details/src/Tab.jsx +12 -0
- data/resources/templates/error_renderer/with_details/src/Tabs.jsx +104 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.css +3446 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/bootstrap.js +293 -0
- data/resources/templates/error_renderer/with_details/src/bootstrap/config.json +401 -0
- data/resources/templates/error_renderer/with_details/src/index.html.template +22 -0
- data/resources/templates/error_renderer/with_details/src/index.jsx +23 -0
- data/resources/templates/error_renderer/with_details/webpack.config.js +47 -0
- data/resources/templates/error_renderer/without_details/dist/bundle.js +1 -0
- data/resources/templates/error_renderer/without_details/dist/styles.css +1 -0
- data/resources/templates/{undisclosed_error.html.template → error_renderer/without_details/src/index.html.template} +7 -11
- data/resources/templates/error_renderer/without_details/src/index.js +1 -0
- data/resources/templates/{error_layout.css → error_renderer/without_details/src/main.css} +5 -2
- data/resources/templates/error_renderer/without_details/webpack.config.js +42 -0
- data/src/agent/AgentMain.cpp +3 -3
- data/src/agent/Core/ApplicationPool/BasicProcessInfo.h +13 -0
- data/src/agent/Core/ApplicationPool/Common.h +3 -4
- data/src/agent/Core/ApplicationPool/Context.h +27 -17
- data/src/agent/Core/ApplicationPool/Group.h +3 -1
- data/src/agent/Core/ApplicationPool/Group/InitializationAndShutdown.cpp +2 -12
- data/src/agent/Core/ApplicationPool/Group/InternalUtils.cpp +55 -10
- data/src/agent/Core/ApplicationPool/Group/LifetimeAndBasics.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/OutOfBandWork.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Group/SpawningAndRestarting.cpp +13 -6
- data/src/agent/Core/ApplicationPool/Implementation.cpp +16 -100
- data/src/agent/Core/ApplicationPool/Options.h +8 -65
- data/src/agent/Core/ApplicationPool/Pool.h +4 -21
- data/src/agent/Core/ApplicationPool/Pool/AnalyticsCollection.cpp +1 -60
- data/src/agent/Core/ApplicationPool/Pool/GeneralUtils.cpp +10 -13
- data/src/agent/Core/ApplicationPool/Pool/InitializationAndShutdown.cpp +3 -8
- data/src/agent/Core/ApplicationPool/Pool/Miscellaneous.cpp +2 -34
- data/src/agent/Core/ApplicationPool/Pool/StateInspection.cpp +1 -1
- data/src/agent/Core/ApplicationPool/Process.cpp +17 -12
- data/src/agent/Core/ApplicationPool/Process.h +146 -93
- data/src/agent/Core/ApplicationPool/Session.h +2 -2
- data/src/agent/Core/ApplicationPool/Socket.h +28 -27
- data/src/agent/Core/Config.h +1 -3
- data/src/agent/Core/ConfigChange.cpp +2 -4
- data/src/agent/Core/Controller.h +2 -8
- data/src/agent/Core/Controller/BufferBody.cpp +0 -2
- data/src/agent/Core/Controller/CheckoutSession.cpp +12 -24
- data/src/agent/Core/Controller/Config.h +1 -9
- data/src/agent/Core/Controller/ForwardResponse.cpp +0 -34
- data/src/agent/Core/Controller/Hooks.cpp +0 -7
- data/src/agent/Core/Controller/InitRequest.cpp +0 -43
- data/src/agent/Core/Controller/InitializationAndShutdown.cpp +0 -4
- data/src/agent/Core/Controller/Request.h +1 -35
- data/src/agent/Core/Controller/SendRequest.cpp +0 -32
- data/src/agent/Core/CoreMain.cpp +19 -32
- data/src/agent/Core/SpawningKit/Config.h +329 -55
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h +369 -0
- data/src/agent/Core/SpawningKit/Config/AutoGeneratedCode.h.cxxcodebuilder +307 -0
- data/src/agent/Core/SpawningKit/Context.h +211 -0
- data/src/agent/Core/SpawningKit/DirectSpawner.h +112 -122
- data/src/agent/Core/SpawningKit/DummySpawner.h +59 -20
- data/src/agent/Core/SpawningKit/ErrorRenderer.h +117 -0
- data/src/agent/Core/SpawningKit/Exceptions.h +1157 -0
- data/src/agent/Core/SpawningKit/Factory.h +24 -17
- data/src/agent/Core/SpawningKit/{BackgroundIOCapturer.h → Handshake/BackgroundIOCapturer.h} +48 -18
- data/src/agent/Core/SpawningKit/Handshake/Perform.h +1650 -0
- data/src/agent/Core/SpawningKit/Handshake/Prepare.h +582 -0
- data/src/agent/Core/SpawningKit/Handshake/Session.h +91 -0
- data/src/agent/Core/SpawningKit/Handshake/WorkDir.h +100 -0
- data/src/agent/Core/SpawningKit/Journey.h +561 -0
- data/src/agent/Core/SpawningKit/PipeWatcher.h +41 -18
- data/src/agent/Core/SpawningKit/README.md +534 -0
- data/src/agent/Core/SpawningKit/Result.h +182 -7
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h +69 -0
- data/src/agent/Core/SpawningKit/Result/AutoGeneratedCode.h.cxxcodebuilder +110 -0
- data/src/agent/Core/SpawningKit/SmartSpawner.h +1027 -562
- data/src/agent/Core/SpawningKit/Spawner.h +70 -1134
- data/src/agent/Core/SpawningKit/UserSwitchingRules.h +3 -33
- data/src/agent/README.md +2 -3
- data/src/agent/Shared/ApiServerUtils.h +2 -3
- data/src/agent/SpawnEnvSetupper/SpawnEnvSetupperMain.cpp +932 -0
- data/src/agent/Watchdog/Config.h +1 -3
- data/src/agent/Watchdog/WatchdogMain.cpp +2 -1
- data/src/apache2_module/ConfigGeneral/AutoGeneratedDefinitions.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.cpp +5 -0
- data/src/apache2_module/ConfigGeneral/ManifestGeneration.h +22 -13
- data/src/apache2_module/DirConfig/AutoGeneratedCreateFunction.cpp +5 -0
- data/src/apache2_module/DirConfig/AutoGeneratedHeaderSerialization.cpp +3 -0
- data/src/apache2_module/DirConfig/AutoGeneratedManifestGeneration.cpp +13 -0
- data/src/apache2_module/DirConfig/AutoGeneratedMergeFunction.cpp +7 -0
- data/src/apache2_module/DirConfig/AutoGeneratedStruct.h +13 -0
- data/src/cxx_supportlib/Constants.h +3 -1
- data/src/cxx_supportlib/Exceptions.h +0 -121
- data/src/cxx_supportlib/LoggingKit/Implementation.cpp +7 -6
- data/src/cxx_supportlib/LoggingKit/Logging.h +3 -1
- data/src/cxx_supportlib/Utils.cpp +42 -0
- data/src/cxx_supportlib/Utils.h +7 -0
- data/src/cxx_supportlib/Utils/IOUtils.cpp +58 -0
- data/src/cxx_supportlib/Utils/IOUtils.h +13 -0
- data/src/cxx_supportlib/Utils/JsonUtils.h +130 -23
- data/src/cxx_supportlib/Utils/ScopeGuard.h +9 -4
- data/src/cxx_supportlib/Utils/StrIntUtils.cpp +7 -0
- data/src/cxx_supportlib/Utils/StrIntUtils.h +1 -0
- data/src/cxx_supportlib/Utils/SystemTime.h +1 -1
- data/src/cxx_supportlib/Utils/Timer.h +1 -1
- data/src/cxx_supportlib/WebSocketCommandReverseServer.h +6 -4
- data/src/cxx_supportlib/vendor-copy/adhoc_lve.h +1 -0
- data/src/helper-scripts/node-loader.js +54 -59
- data/src/helper-scripts/rack-loader.rb +63 -60
- data/src/helper-scripts/rack-preloader.rb +125 -72
- data/src/helper-scripts/wsgi-loader.py +100 -43
- data/src/nginx_module/ConfigGeneral/AutoGeneratedDefinitions.c +120 -112
- data/src/nginx_module/ConfigGeneral/AutoGeneratedManifestDefaultsInitialization.c +15 -8
- data/src/nginx_module/ConfigGeneral/AutoGeneratedSetterFuncs.c +142 -142
- data/src/nginx_module/ConfigGeneral/ManifestGeneration.c +26 -15
- data/src/nginx_module/ConfigGeneral/ManifestGeneration.h +3 -0
- data/src/nginx_module/LocationConfig/AutoGeneratedCreateFunction.c +76 -70
- data/src/nginx_module/LocationConfig/AutoGeneratedHeaderSerialization.c +114 -99
- data/src/nginx_module/LocationConfig/AutoGeneratedManifestGeneration.c +170 -156
- data/src/nginx_module/LocationConfig/AutoGeneratedMergeFunction.c +38 -35
- data/src/nginx_module/LocationConfig/AutoGeneratedStruct.h +5 -1
- data/src/ruby_supportlib/phusion_passenger.rb +5 -5
- data/src/ruby_supportlib/phusion_passenger/admin_tools/instance.rb +14 -1
- data/src/ruby_supportlib/phusion_passenger/apache2/config_options.rb +8 -0
- data/src/ruby_supportlib/phusion_passenger/common_library.rb +0 -3
- data/src/ruby_supportlib/phusion_passenger/config/nginx_engine_compiler.rb +0 -1
- data/src/ruby_supportlib/phusion_passenger/constants.rb +2 -0
- data/src/ruby_supportlib/phusion_passenger/loader_shared_helpers.rb +646 -238
- data/src/ruby_supportlib/phusion_passenger/nginx/config_options.rb +117 -95
- data/src/ruby_supportlib/phusion_passenger/packaging.rb +0 -1
- data/src/ruby_supportlib/phusion_passenger/platform_info/depcheck_specs/apache2.rb +5 -1
- data/src/ruby_supportlib/phusion_passenger/preloader_shared_helpers.rb +92 -69
- data/src/ruby_supportlib/phusion_passenger/public_api.rb +0 -17
- data/src/ruby_supportlib/phusion_passenger/rack/thread_handler_extension.rb +0 -3
- data/src/ruby_supportlib/phusion_passenger/request_handler.rb +4 -5
- data/src/ruby_supportlib/phusion_passenger/request_handler/thread_handler.rb +0 -22
- metadata +64 -67
- data/resources/templates/error_layout.html.template +0 -86
- data/resources/templates/general_error.html.template +0 -1
- data/resources/templates/general_error_with_html.html.template +0 -1
- data/src/agent/Core/ApplicationPool/ErrorRenderer.h +0 -131
- data/src/agent/Core/SpawningKit/Options.h +0 -41
- data/src/agent/Core/UnionStation/Connection.h +0 -173
- data/src/agent/Core/UnionStation/Context.h +0 -536
- data/src/agent/Core/UnionStation/StopwatchLog.h +0 -147
- data/src/agent/Core/UnionStation/Transaction.h +0 -249
- data/src/agent/SpawnPreparer/SpawnPreparerMain.cpp +0 -208
- data/src/cxx_supportlib/UnionStationFilterSupport.cpp +0 -67
- data/src/cxx_supportlib/UnionStationFilterSupport.h +0 -1622
- data/src/nodejs_supportlib/phusion_passenger/log_express.js +0 -106
- data/src/nodejs_supportlib/phusion_passenger/log_mongodb.js +0 -202
- data/src/nodejs_supportlib/phusion_passenger/ustreporter.js +0 -227
- data/src/nodejs_supportlib/phusion_passenger/ustrouter_connector.js +0 -448
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/CONFIG.md +0 -37
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile +0 -17
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Gemfile.lock +0 -59
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README-API.md +0 -5
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/README.md +0 -117
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/Rakefile +0 -115
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core.rb +0 -423
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/api.rb +0 -238
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/connection.rb +0 -67
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/context.rb +0 -281
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/lock.rb +0 -62
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/log.rb +0 -66
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/message_channel.rb +0 -157
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter.rb +0 -150
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/basics.rb +0 -199
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/controllers.rb +0 -187
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/misc.rb +0 -303
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/request_reporter/view_rendering.rb +0 -91
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/simple_json.rb +0 -396
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/spec_helper.rb +0 -279
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/time_point.rb +0 -39
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/transaction.rb +0 -173
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/utils.rb +0 -177
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version.rb +0 -32
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/lib/union_station_hooks_core/version_data.rb +0 -44
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.example +0 -16
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis +0 -20
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/ruby_versions.yml.travis-with-sudo +0 -18
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_core/union_station_hooks_core.gemspec +0 -23
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile +0 -14
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Gemfile.lock +0 -45
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/LICENSE.md +0 -19
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/README.md +0 -104
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/Rakefile +0 -160
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails.rb +0 -200
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_controller_extension.rb +0 -45
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/action_view_subscriber.rb +0 -55
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_record_subscriber.rb +0 -41
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_benchmarkable_extension.rb +0 -47
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/active_support_cache_subscriber.rb +0 -79
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/exception_logger.rb +0 -57
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version.rb +0 -32
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/lib/union_station_hooks_rails/version_data.rb +0 -44
- data/src/ruby_supportlib/phusion_passenger/vendor/union_station_hooks_rails/union_station_hooks_rails.gemspec +0 -34
@@ -0,0 +1,91 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2016-2017 Phusion Holding B.V.
|
4
|
+
*
|
5
|
+
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
+
* trademarks of Phusion Holding B.V.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
#ifndef _PASSENGER_SPAWNING_KIT_HANDSHAKE_SESSION_H_
|
27
|
+
#define _PASSENGER_SPAWNING_KIT_HANDSHAKE_SESSION_H_
|
28
|
+
|
29
|
+
#include <boost/scoped_ptr.hpp>
|
30
|
+
#include <string>
|
31
|
+
|
32
|
+
#include <Utils.h>
|
33
|
+
#include <Core/SpawningKit/Context.h>
|
34
|
+
#include <Core/SpawningKit/Config.h>
|
35
|
+
#include <Core/SpawningKit/Journey.h>
|
36
|
+
#include <Core/SpawningKit/Result.h>
|
37
|
+
#include <Core/SpawningKit/Handshake/WorkDir.h>
|
38
|
+
|
39
|
+
|
40
|
+
namespace Passenger {
|
41
|
+
namespace SpawningKit {
|
42
|
+
|
43
|
+
using namespace std;
|
44
|
+
|
45
|
+
|
46
|
+
struct HandshakeSession {
|
47
|
+
Context *context;
|
48
|
+
Config *config;
|
49
|
+
|
50
|
+
boost::scoped_ptr<HandshakeWorkDir> workDir;
|
51
|
+
string responseDir;
|
52
|
+
string envDumpDir;
|
53
|
+
Journey journey;
|
54
|
+
Result result;
|
55
|
+
|
56
|
+
uid_t uid;
|
57
|
+
gid_t gid;
|
58
|
+
string homedir;
|
59
|
+
string shell;
|
60
|
+
|
61
|
+
unsigned long long timeoutUsec;
|
62
|
+
|
63
|
+
/**
|
64
|
+
* The port that the application is expected to start on. Only meaningful
|
65
|
+
* if `config->genericApp || config->findFreePort`.
|
66
|
+
*/
|
67
|
+
unsigned int expectedStartPort;
|
68
|
+
|
69
|
+
HandshakeSession(Context &_context, Config &_config, JourneyType journeyType)
|
70
|
+
: context(&_context),
|
71
|
+
config(&_config),
|
72
|
+
journey(journeyType, !_config.genericApp && _config.startsUsingWrapper),
|
73
|
+
uid(USER_NOT_GIVEN),
|
74
|
+
gid(GROUP_NOT_GIVEN),
|
75
|
+
timeoutUsec(_config.startTimeoutMsec * 1000),
|
76
|
+
expectedStartPort(0)
|
77
|
+
{ }
|
78
|
+
|
79
|
+
~HandshakeSession() {
|
80
|
+
if (config->debugWorkDir && workDir != NULL) {
|
81
|
+
string path = workDir->dontRemoveOnDestruction();
|
82
|
+
P_NOTICE("Work directory " << path << " preserved for debugging");
|
83
|
+
}
|
84
|
+
}
|
85
|
+
};
|
86
|
+
|
87
|
+
|
88
|
+
} // namespace SpawningKit
|
89
|
+
} // namespace Passenger
|
90
|
+
|
91
|
+
#endif /* _PASSENGER_SPAWNING_KIT_HANDSHAKE_SESSION_H_ */
|
@@ -0,0 +1,100 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2011-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_SPAWNING_KIT_HANDSHAKE_WORKDIR_H_
|
27
|
+
#define _PASSENGER_SPAWNING_KIT_HANDSHAKE_WORKDIR_H_
|
28
|
+
|
29
|
+
#include <oxt/system_calls.hpp>
|
30
|
+
#include <string>
|
31
|
+
#include <cerrno>
|
32
|
+
|
33
|
+
#include <sys/types.h>
|
34
|
+
#include <limits.h>
|
35
|
+
#include <unistd.h>
|
36
|
+
|
37
|
+
#include <Exceptions.h>
|
38
|
+
#include <Utils.h>
|
39
|
+
#include <Utils/StrIntUtils.h>
|
40
|
+
|
41
|
+
namespace Passenger {
|
42
|
+
namespace SpawningKit {
|
43
|
+
|
44
|
+
using namespace std;
|
45
|
+
|
46
|
+
|
47
|
+
/**
|
48
|
+
* A temporary directory for handshaking with a child process
|
49
|
+
* during spawning. It is removed after spawning is finished
|
50
|
+
* or has failed.
|
51
|
+
*/
|
52
|
+
class HandshakeWorkDir {
|
53
|
+
private:
|
54
|
+
string path;
|
55
|
+
|
56
|
+
public:
|
57
|
+
HandshakeWorkDir(uid_t uid, gid_t gid) {
|
58
|
+
char buf[PATH_MAX + 1];
|
59
|
+
char *pos = buf;
|
60
|
+
const char *end = buf + PATH_MAX;
|
61
|
+
|
62
|
+
pos = appendData(pos, end, getSystemTempDir());
|
63
|
+
pos = appendData(pos, end, "/passenger.spawn.XXXXXXXXXX");
|
64
|
+
*pos = '\0';
|
65
|
+
|
66
|
+
const char *result = mkdtemp(buf);
|
67
|
+
if (result == NULL) {
|
68
|
+
int e = errno;
|
69
|
+
throw SystemException("Cannot create a temporary directory "
|
70
|
+
"in the format of '" + StaticString(buf) + "'", e);
|
71
|
+
} else {
|
72
|
+
path = result;
|
73
|
+
boost::this_thread::disable_interruption di;
|
74
|
+
boost::this_thread::disable_syscall_interruption dsi;
|
75
|
+
syscalls::chown(result, uid, gid);
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
~HandshakeWorkDir() {
|
80
|
+
if (!path.empty()) {
|
81
|
+
removeDirTree(path);
|
82
|
+
}
|
83
|
+
}
|
84
|
+
|
85
|
+
const string &getPath() const {
|
86
|
+
return path;
|
87
|
+
}
|
88
|
+
|
89
|
+
string dontRemoveOnDestruction() {
|
90
|
+
string result = path;
|
91
|
+
path.clear();
|
92
|
+
return result;
|
93
|
+
}
|
94
|
+
};
|
95
|
+
|
96
|
+
|
97
|
+
} // namespace SpawningKit
|
98
|
+
} // namespace Passenger
|
99
|
+
|
100
|
+
#endif /* _PASSENGER_SPAWNING_KIT_HANDSHAKE_WORKDIR_H_ */
|
@@ -0,0 +1,561 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - https://www.phusionpassenger.com/
|
3
|
+
* Copyright (c) 2017 Phusion Holding B.V.
|
4
|
+
*
|
5
|
+
* "Passenger", "Phusion Passenger" and "Union Station" are registered
|
6
|
+
* trademarks of Phusion Holding B.V.
|
7
|
+
*
|
8
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
9
|
+
* of this software and associated documentation files (the "Software"), to deal
|
10
|
+
* in the Software without restriction, including without limitation the rights
|
11
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the Software is
|
13
|
+
* furnished to do so, subject to the following conditions:
|
14
|
+
*
|
15
|
+
* The above copyright notice and this permission notice shall be included in
|
16
|
+
* all copies or substantial portions of the Software.
|
17
|
+
*
|
18
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
19
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
20
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
21
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
22
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
23
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
24
|
+
* THE SOFTWARE.
|
25
|
+
*/
|
26
|
+
#ifndef _PASSENGER_SPAWNING_KIT_HANDSHAKE_JOURNEY_H_
|
27
|
+
#define _PASSENGER_SPAWNING_KIT_HANDSHAKE_JOURNEY_H_
|
28
|
+
|
29
|
+
#include <map>
|
30
|
+
#include <utility>
|
31
|
+
|
32
|
+
#include <oxt/macros.hpp>
|
33
|
+
#include <oxt/backtrace.hpp>
|
34
|
+
|
35
|
+
#include <jsoncpp/json.h>
|
36
|
+
|
37
|
+
#include <LoggingKit/LoggingKit.h>
|
38
|
+
#include <StaticString.h>
|
39
|
+
#include <Utils/SystemTime.h>
|
40
|
+
#include <Utils/JsonUtils.h>
|
41
|
+
#include <Utils/StrIntUtils.h>
|
42
|
+
#include <Utils/SystemTime.h>
|
43
|
+
|
44
|
+
namespace Passenger {
|
45
|
+
namespace SpawningKit {
|
46
|
+
|
47
|
+
using namespace std;
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* As explained in README.md, there are three possible journeys,
|
52
|
+
* although each journey can have small variations (based on whether
|
53
|
+
* a wrapper is used or not).
|
54
|
+
*/
|
55
|
+
enum JourneyType {
|
56
|
+
SPAWN_DIRECTLY,
|
57
|
+
START_PRELOADER,
|
58
|
+
SPAWN_THROUGH_PRELOADER
|
59
|
+
};
|
60
|
+
|
61
|
+
enum JourneyStep {
|
62
|
+
// Steps in Passenger Core / SpawningKit
|
63
|
+
SPAWNING_KIT_PREPARATION,
|
64
|
+
SPAWNING_KIT_FORK_SUBPROCESS,
|
65
|
+
SPAWNING_KIT_CONNECT_TO_PRELOADER,
|
66
|
+
SPAWNING_KIT_SEND_COMMAND_TO_PRELOADER,
|
67
|
+
SPAWNING_KIT_READ_RESPONSE_FROM_PRELOADER,
|
68
|
+
SPAWNING_KIT_PARSE_RESPONSE_FROM_PRELOADER,
|
69
|
+
SPAWNING_KIT_PROCESS_RESPONSE_FROM_PRELOADER,
|
70
|
+
SPAWNING_KIT_HANDSHAKE_PERFORM,
|
71
|
+
SPAWNING_KIT_FINISH,
|
72
|
+
|
73
|
+
// Steps in preloader (when spawning a worker process)
|
74
|
+
PRELOADER_PREPARATION,
|
75
|
+
PRELOADER_FORK_SUBPROCESS,
|
76
|
+
PRELOADER_SEND_RESPONSE,
|
77
|
+
PRELOADER_FINISH,
|
78
|
+
|
79
|
+
// Steps in subprocess
|
80
|
+
SUBPROCESS_BEFORE_FIRST_EXEC,
|
81
|
+
SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL,
|
82
|
+
SUBPROCESS_OS_SHELL,
|
83
|
+
SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL,
|
84
|
+
SUBPROCESS_EXEC_WRAPPER,
|
85
|
+
SUBPROCESS_WRAPPER_PREPARATION,
|
86
|
+
SUBPROCESS_APP_LOAD_OR_EXEC,
|
87
|
+
SUBPROCESS_PREPARE_AFTER_FORKING_FROM_PRELOADER,
|
88
|
+
SUBPROCESS_LISTEN,
|
89
|
+
SUBPROCESS_FINISH,
|
90
|
+
|
91
|
+
// Other
|
92
|
+
UNKNOWN_JOURNEY_STEP
|
93
|
+
};
|
94
|
+
|
95
|
+
enum JourneyStepState {
|
96
|
+
/**
|
97
|
+
* This step has not started yet. Will be visualized with an empty
|
98
|
+
* placeholder.
|
99
|
+
*/
|
100
|
+
STEP_NOT_STARTED,
|
101
|
+
|
102
|
+
/**
|
103
|
+
* This step is currently in progress. Will be visualized with a spinner.
|
104
|
+
*/
|
105
|
+
STEP_IN_PROGRESS,
|
106
|
+
|
107
|
+
/**
|
108
|
+
* This step has already been performed successfully. Will be
|
109
|
+
* visualized with a green tick.
|
110
|
+
*/
|
111
|
+
STEP_PERFORMED,
|
112
|
+
|
113
|
+
/**
|
114
|
+
* This step has failed. Will be visualized with a red mark.
|
115
|
+
*/
|
116
|
+
STEP_ERRORED,
|
117
|
+
|
118
|
+
UNKNOWN_JOURNEY_STEP_STATE
|
119
|
+
};
|
120
|
+
|
121
|
+
|
122
|
+
inline OXT_PURE StaticString journeyTypeToString(JourneyType type);
|
123
|
+
inline OXT_PURE StaticString journeyStepToString(JourneyStep step);
|
124
|
+
inline OXT_PURE string journeyStepToStringLowerCase(JourneyStep step);
|
125
|
+
inline OXT_PURE StaticString journeyStepStateToString(JourneyStepState state);
|
126
|
+
inline OXT_PURE JourneyStepState stringToJourneyStepState(const StaticString &value);
|
127
|
+
|
128
|
+
inline OXT_PURE JourneyStep getFirstCoreJourneyStep() { return SPAWNING_KIT_PREPARATION; }
|
129
|
+
inline OXT_PURE JourneyStep getLastCoreJourneyStep() { return SPAWNING_KIT_FINISH; }
|
130
|
+
inline OXT_PURE JourneyStep getFirstPreloaderJourneyStep() { return PRELOADER_PREPARATION; }
|
131
|
+
inline OXT_PURE JourneyStep getLastPreloaderJourneyStep() { return PRELOADER_FINISH; }
|
132
|
+
inline OXT_PURE JourneyStep getFirstSubprocessJourneyStep() { return SUBPROCESS_BEFORE_FIRST_EXEC; }
|
133
|
+
inline OXT_PURE JourneyStep getLastSubprocessJourneyStep() { return SUBPROCESS_FINISH; }
|
134
|
+
|
135
|
+
|
136
|
+
class JourneyStepInfo {
|
137
|
+
private:
|
138
|
+
MonotonicTimeUsec getEndTime(const JourneyStepInfo *nextStepInfo) const {
|
139
|
+
if (nextStepInfo != NULL && nextStepInfo->beginTime != 0) {
|
140
|
+
return nextStepInfo->beginTime;
|
141
|
+
} else {
|
142
|
+
return endTime;
|
143
|
+
}
|
144
|
+
}
|
145
|
+
|
146
|
+
public:
|
147
|
+
JourneyStep step, nextStep;
|
148
|
+
JourneyStepState state;
|
149
|
+
MonotonicTimeUsec beginTime;
|
150
|
+
MonotonicTimeUsec endTime;
|
151
|
+
|
152
|
+
JourneyStepInfo(JourneyStep _step, JourneyStepState _state = STEP_NOT_STARTED)
|
153
|
+
: step(_step),
|
154
|
+
nextStep(UNKNOWN_JOURNEY_STEP),
|
155
|
+
state(_state),
|
156
|
+
beginTime(0),
|
157
|
+
endTime(0)
|
158
|
+
{ }
|
159
|
+
|
160
|
+
unsigned long long usecDuration(const JourneyStepInfo *nextStepInfo) const {
|
161
|
+
if (getEndTime(nextStepInfo) >= beginTime) {
|
162
|
+
return getEndTime(nextStepInfo) - beginTime;
|
163
|
+
} else {
|
164
|
+
return 0;
|
165
|
+
}
|
166
|
+
}
|
167
|
+
|
168
|
+
Json::Value inspectAsJson(const JourneyStepInfo *nextStepInfo, MonotonicTimeUsec monoNow,
|
169
|
+
unsigned long long now) const
|
170
|
+
{
|
171
|
+
Json::Value doc;
|
172
|
+
|
173
|
+
doc["state"] = journeyStepStateToString(state).toString();
|
174
|
+
if (beginTime != 0) {
|
175
|
+
doc["begin_time"] = monoTimeToJson(beginTime, monoNow, now);
|
176
|
+
}
|
177
|
+
if (endTime != 0) {
|
178
|
+
doc["end_time"] = monoTimeToJson(endTime, monoNow, now);
|
179
|
+
doc["duration"] = usecDuration(nextStepInfo) / 1000000.0;
|
180
|
+
}
|
181
|
+
return doc;
|
182
|
+
}
|
183
|
+
};
|
184
|
+
|
185
|
+
|
186
|
+
/**
|
187
|
+
* For an introduction see README.md, sections:
|
188
|
+
*
|
189
|
+
* - "The Journey class"
|
190
|
+
* - "Subprocess journey logging"
|
191
|
+
*/
|
192
|
+
class Journey {
|
193
|
+
public:
|
194
|
+
typedef map<JourneyStep, JourneyStepInfo> Map;
|
195
|
+
|
196
|
+
private:
|
197
|
+
JourneyType type;
|
198
|
+
bool usingWrapper;
|
199
|
+
Map steps;
|
200
|
+
|
201
|
+
void insertStep(JourneyStep step, bool first = false) {
|
202
|
+
steps.insert(make_pair(step, JourneyStepInfo(step)));
|
203
|
+
if (!first) {
|
204
|
+
Map::iterator prev = steps.end();
|
205
|
+
prev--;
|
206
|
+
prev--;
|
207
|
+
prev->second.nextStep = step;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
|
211
|
+
void fillInStepsForSpawnDirectlyJourney() {
|
212
|
+
insertStep(SPAWNING_KIT_PREPARATION, true);
|
213
|
+
insertStep(SPAWNING_KIT_FORK_SUBPROCESS);
|
214
|
+
insertStep(SPAWNING_KIT_HANDSHAKE_PERFORM);
|
215
|
+
insertStep(SPAWNING_KIT_FINISH);
|
216
|
+
|
217
|
+
insertStep(SUBPROCESS_BEFORE_FIRST_EXEC, true);
|
218
|
+
insertStep(SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL);
|
219
|
+
insertStep(SUBPROCESS_OS_SHELL);
|
220
|
+
insertStep(SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL);
|
221
|
+
if (usingWrapper) {
|
222
|
+
insertStep(SUBPROCESS_EXEC_WRAPPER);
|
223
|
+
insertStep(SUBPROCESS_WRAPPER_PREPARATION);
|
224
|
+
}
|
225
|
+
insertStep(SUBPROCESS_APP_LOAD_OR_EXEC);
|
226
|
+
insertStep(SUBPROCESS_LISTEN);
|
227
|
+
insertStep(SUBPROCESS_FINISH);
|
228
|
+
}
|
229
|
+
|
230
|
+
void fillInStepsForPreloaderStartJourney() {
|
231
|
+
insertStep(SPAWNING_KIT_PREPARATION, true);
|
232
|
+
insertStep(SPAWNING_KIT_FORK_SUBPROCESS);
|
233
|
+
insertStep(SPAWNING_KIT_HANDSHAKE_PERFORM);
|
234
|
+
insertStep(SPAWNING_KIT_FINISH);
|
235
|
+
|
236
|
+
insertStep(SUBPROCESS_BEFORE_FIRST_EXEC, true);
|
237
|
+
insertStep(SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL);
|
238
|
+
insertStep(SUBPROCESS_OS_SHELL);
|
239
|
+
insertStep(SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL);
|
240
|
+
if (usingWrapper) {
|
241
|
+
insertStep(SUBPROCESS_EXEC_WRAPPER);
|
242
|
+
insertStep(SUBPROCESS_WRAPPER_PREPARATION);
|
243
|
+
}
|
244
|
+
insertStep(SUBPROCESS_APP_LOAD_OR_EXEC);
|
245
|
+
insertStep(SUBPROCESS_LISTEN);
|
246
|
+
insertStep(SUBPROCESS_FINISH);
|
247
|
+
}
|
248
|
+
|
249
|
+
void fillInStepsForSpawnThroughPreloaderJourney() {
|
250
|
+
insertStep(SPAWNING_KIT_PREPARATION, true);
|
251
|
+
insertStep(SPAWNING_KIT_CONNECT_TO_PRELOADER);
|
252
|
+
insertStep(SPAWNING_KIT_SEND_COMMAND_TO_PRELOADER);
|
253
|
+
insertStep(SPAWNING_KIT_READ_RESPONSE_FROM_PRELOADER);
|
254
|
+
insertStep(SPAWNING_KIT_PARSE_RESPONSE_FROM_PRELOADER);
|
255
|
+
insertStep(SPAWNING_KIT_PROCESS_RESPONSE_FROM_PRELOADER);
|
256
|
+
insertStep(SPAWNING_KIT_HANDSHAKE_PERFORM);
|
257
|
+
insertStep(SPAWNING_KIT_FINISH);
|
258
|
+
|
259
|
+
insertStep(PRELOADER_PREPARATION, true);
|
260
|
+
insertStep(PRELOADER_FORK_SUBPROCESS);
|
261
|
+
insertStep(PRELOADER_SEND_RESPONSE);
|
262
|
+
insertStep(PRELOADER_FINISH);
|
263
|
+
|
264
|
+
insertStep(SUBPROCESS_PREPARE_AFTER_FORKING_FROM_PRELOADER, true);
|
265
|
+
insertStep(SUBPROCESS_LISTEN);
|
266
|
+
insertStep(SUBPROCESS_FINISH);
|
267
|
+
}
|
268
|
+
|
269
|
+
JourneyStepInfo &getStepInfoMutable(JourneyStep step) {
|
270
|
+
Map::iterator it = steps.find(step);
|
271
|
+
if (it == steps.end()) {
|
272
|
+
throw RuntimeException("Invalid step " + journeyStepToString(step));
|
273
|
+
}
|
274
|
+
|
275
|
+
return it->second;
|
276
|
+
}
|
277
|
+
|
278
|
+
public:
|
279
|
+
Journey(JourneyType _type, bool _usingWrapper)
|
280
|
+
: type(_type),
|
281
|
+
usingWrapper(_usingWrapper)
|
282
|
+
{
|
283
|
+
switch (_type) {
|
284
|
+
case SPAWN_DIRECTLY:
|
285
|
+
fillInStepsForSpawnDirectlyJourney();
|
286
|
+
break;
|
287
|
+
case START_PRELOADER:
|
288
|
+
fillInStepsForPreloaderStartJourney();
|
289
|
+
break;
|
290
|
+
case SPAWN_THROUGH_PRELOADER:
|
291
|
+
fillInStepsForSpawnThroughPreloaderJourney();
|
292
|
+
break;
|
293
|
+
default:
|
294
|
+
P_BUG("Unknown journey type " << toString((int) _type));
|
295
|
+
break;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
JourneyType getType() const {
|
300
|
+
return type;
|
301
|
+
}
|
302
|
+
|
303
|
+
bool isUsingWrapper() const {
|
304
|
+
return usingWrapper;
|
305
|
+
}
|
306
|
+
|
307
|
+
bool hasStep(JourneyStep step) const {
|
308
|
+
Map::const_iterator it = steps.find(step);
|
309
|
+
return it != steps.end();
|
310
|
+
}
|
311
|
+
|
312
|
+
const JourneyStepInfo &getStepInfo(JourneyStep step) const {
|
313
|
+
Map::const_iterator it = steps.find(step);
|
314
|
+
if (it == steps.end()) {
|
315
|
+
throw RuntimeException("Invalid step " + journeyStepToString(step));
|
316
|
+
}
|
317
|
+
|
318
|
+
return it->second;
|
319
|
+
}
|
320
|
+
|
321
|
+
JourneyStep getFirstFailedStep() const {
|
322
|
+
Map::const_iterator it, end = steps.end();
|
323
|
+
for (it = steps.begin(); it != end; it++) {
|
324
|
+
if (it->second.state == STEP_ERRORED) {
|
325
|
+
return it->first;
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
329
|
+
return UNKNOWN_JOURNEY_STEP;
|
330
|
+
}
|
331
|
+
|
332
|
+
void setStepNotStarted(JourneyStep step, bool force = false) {
|
333
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
334
|
+
if (info.state == STEP_NOT_STARTED || info.state == STEP_IN_PROGRESS || force) {
|
335
|
+
info.state = STEP_NOT_STARTED;
|
336
|
+
info.beginTime = 0;
|
337
|
+
info.endTime = 0;
|
338
|
+
} else {
|
339
|
+
throw RuntimeException("Unable to change state for journey step "
|
340
|
+
+ journeyStepToString(step) + " because it wasn't already in progress");
|
341
|
+
}
|
342
|
+
}
|
343
|
+
|
344
|
+
void setStepInProgress(JourneyStep step, bool force = false) {
|
345
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
346
|
+
if (info.state == STEP_IN_PROGRESS) {
|
347
|
+
return;
|
348
|
+
} else if (info.state == STEP_NOT_STARTED || force) {
|
349
|
+
info.state = STEP_IN_PROGRESS;
|
350
|
+
// When `force` is true, we don't want to overwrite the previous endTime.
|
351
|
+
if (info.endTime == 0) {
|
352
|
+
info.beginTime =
|
353
|
+
SystemTime::getMonotonicUsecWithGranularity<SystemTime::GRAN_10MSEC>();
|
354
|
+
}
|
355
|
+
} else {
|
356
|
+
throw RuntimeException("Unable to change state for journey step "
|
357
|
+
+ journeyStepToString(step)
|
358
|
+
+ " because it was already in progress or completed");
|
359
|
+
}
|
360
|
+
}
|
361
|
+
|
362
|
+
void setStepPerformed(JourneyStep step, bool force = false) {
|
363
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
364
|
+
if (info.state == STEP_PERFORMED) {
|
365
|
+
return;
|
366
|
+
} else if (info.state == STEP_IN_PROGRESS || true) {
|
367
|
+
info.state = STEP_PERFORMED;
|
368
|
+
// When `force` is true, we don't want to overwrite the previous endTime.
|
369
|
+
if (info.endTime == 0) {
|
370
|
+
info.endTime =
|
371
|
+
SystemTime::getMonotonicUsecWithGranularity<SystemTime::GRAN_10MSEC>();
|
372
|
+
if (info.beginTime == 0) {
|
373
|
+
info.beginTime = info.endTime;
|
374
|
+
}
|
375
|
+
}
|
376
|
+
} else {
|
377
|
+
throw RuntimeException("Unable to change state for journey step "
|
378
|
+
+ journeyStepToString(step) + " because it wasn't already in progress");
|
379
|
+
}
|
380
|
+
}
|
381
|
+
|
382
|
+
void setStepErrored(JourneyStep step, bool force = false) {
|
383
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
384
|
+
if (info.state == STEP_ERRORED) {
|
385
|
+
return;
|
386
|
+
} else if (info.state == STEP_IN_PROGRESS || force) {
|
387
|
+
info.state = STEP_ERRORED;
|
388
|
+
// When `force` is true, we don't want to overwrite the previous endTime.
|
389
|
+
if (info.endTime == 0) {
|
390
|
+
info.endTime =
|
391
|
+
SystemTime::getMonotonicUsecWithGranularity<SystemTime::GRAN_10MSEC>();
|
392
|
+
if (info.beginTime == 0) {
|
393
|
+
info.beginTime = info.endTime;
|
394
|
+
}
|
395
|
+
}
|
396
|
+
} else {
|
397
|
+
throw RuntimeException("Unable to change state for journey step "
|
398
|
+
+ journeyStepToString(step) + " because it wasn't already in progress");
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
void setStepBeginTime(JourneyStep step, MonotonicTimeUsec timestamp) {
|
403
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
404
|
+
info.beginTime = timestamp;
|
405
|
+
}
|
406
|
+
|
407
|
+
void setStepEndTime(JourneyStep step, MonotonicTimeUsec timestamp) {
|
408
|
+
JourneyStepInfo &info = getStepInfoMutable(step);
|
409
|
+
info.endTime = timestamp;
|
410
|
+
}
|
411
|
+
|
412
|
+
void reset() {
|
413
|
+
Map::iterator it, end = steps.end();
|
414
|
+
for (it = steps.begin(); it != end; it++) {
|
415
|
+
it->second.state = STEP_NOT_STARTED;
|
416
|
+
it->second.beginTime = 0;
|
417
|
+
it->second.endTime = 0;
|
418
|
+
}
|
419
|
+
}
|
420
|
+
|
421
|
+
Json::Value inspectAsJson() const {
|
422
|
+
Json::Value doc, steps;
|
423
|
+
MonotonicTimeUsec monoNow = SystemTime::getMonotonicUsec();
|
424
|
+
unsigned long long now = SystemTime::getUsec();
|
425
|
+
|
426
|
+
doc["type"] = journeyTypeToString(type).toString();
|
427
|
+
|
428
|
+
Map::const_iterator it, end = this->steps.end();
|
429
|
+
for (it = this->steps.begin(); it != end; it++) {
|
430
|
+
const JourneyStep step = it->first;
|
431
|
+
const JourneyStepInfo &info = it->second;
|
432
|
+
const JourneyStepInfo *nextStepInfo = NULL;
|
433
|
+
if (info.nextStep != UNKNOWN_JOURNEY_STEP) {
|
434
|
+
nextStepInfo = &this->steps.find(info.nextStep)->second;
|
435
|
+
}
|
436
|
+
steps[journeyStepToString(step).toString()] =
|
437
|
+
info.inspectAsJson(nextStepInfo, monoNow, now);
|
438
|
+
}
|
439
|
+
doc["steps"] = steps;
|
440
|
+
|
441
|
+
return doc;
|
442
|
+
}
|
443
|
+
};
|
444
|
+
|
445
|
+
|
446
|
+
inline OXT_PURE StaticString
|
447
|
+
journeyTypeToString(JourneyType type) {
|
448
|
+
switch (type) {
|
449
|
+
case SPAWN_DIRECTLY:
|
450
|
+
return P_STATIC_STRING("SPAWN_DIRECTLY");
|
451
|
+
case START_PRELOADER:
|
452
|
+
return P_STATIC_STRING("START_PRELOADER");
|
453
|
+
case SPAWN_THROUGH_PRELOADER:
|
454
|
+
return P_STATIC_STRING("SPAWN_THROUGH_PRELOADER");
|
455
|
+
default:
|
456
|
+
return P_STATIC_STRING("UNKNOWN_JOURNEY_TYPE");
|
457
|
+
}
|
458
|
+
}
|
459
|
+
|
460
|
+
inline OXT_PURE StaticString
|
461
|
+
journeyStepToString(JourneyStep step) {
|
462
|
+
switch (step) {
|
463
|
+
case SPAWNING_KIT_PREPARATION:
|
464
|
+
return P_STATIC_STRING("SPAWNING_KIT_PREPARATION");
|
465
|
+
case SPAWNING_KIT_FORK_SUBPROCESS:
|
466
|
+
return P_STATIC_STRING("SPAWNING_KIT_FORK_SUBPROCESS");
|
467
|
+
case SPAWNING_KIT_CONNECT_TO_PRELOADER:
|
468
|
+
return P_STATIC_STRING("SPAWNING_KIT_CONNECT_TO_PRELOADER");
|
469
|
+
case SPAWNING_KIT_SEND_COMMAND_TO_PRELOADER:
|
470
|
+
return P_STATIC_STRING("SPAWNING_KIT_SEND_COMMAND_TO_PRELOADER");
|
471
|
+
case SPAWNING_KIT_READ_RESPONSE_FROM_PRELOADER:
|
472
|
+
return P_STATIC_STRING("SPAWNING_KIT_READ_RESPONSE_FROM_PRELOADER");
|
473
|
+
case SPAWNING_KIT_PARSE_RESPONSE_FROM_PRELOADER:
|
474
|
+
return P_STATIC_STRING("SPAWNING_KIT_PARSE_RESPONSE_FROM_PRELOADER");
|
475
|
+
case SPAWNING_KIT_PROCESS_RESPONSE_FROM_PRELOADER:
|
476
|
+
return P_STATIC_STRING("SPAWNING_KIT_PROCESS_RESPONSE_FROM_PRELOADER");
|
477
|
+
case SPAWNING_KIT_HANDSHAKE_PERFORM:
|
478
|
+
return P_STATIC_STRING("SPAWNING_KIT_HANDSHAKE_PERFORM");
|
479
|
+
case SPAWNING_KIT_FINISH:
|
480
|
+
return P_STATIC_STRING("SPAWNING_KIT_FINISH");
|
481
|
+
|
482
|
+
case PRELOADER_PREPARATION:
|
483
|
+
return P_STATIC_STRING("PRELOADER_PREPARATION");
|
484
|
+
case PRELOADER_FORK_SUBPROCESS:
|
485
|
+
return P_STATIC_STRING("PRELOADER_FORK_SUBPROCESS");
|
486
|
+
case PRELOADER_SEND_RESPONSE:
|
487
|
+
return P_STATIC_STRING("PRELOADER_SEND_RESPONSE");
|
488
|
+
case PRELOADER_FINISH:
|
489
|
+
return P_STATIC_STRING("PRELOADER_FINISH");
|
490
|
+
|
491
|
+
case SUBPROCESS_BEFORE_FIRST_EXEC:
|
492
|
+
return P_STATIC_STRING("SUBPROCESS_BEFORE_FIRST_EXEC");
|
493
|
+
case SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL:
|
494
|
+
return P_STATIC_STRING("SUBPROCESS_SPAWN_ENV_SETUPPER_BEFORE_SHELL");
|
495
|
+
case SUBPROCESS_OS_SHELL:
|
496
|
+
return P_STATIC_STRING("SUBPROCESS_OS_SHELL");
|
497
|
+
case SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL:
|
498
|
+
return P_STATIC_STRING("SUBPROCESS_SPAWN_ENV_SETUPPER_AFTER_SHELL");
|
499
|
+
case SUBPROCESS_EXEC_WRAPPER:
|
500
|
+
return P_STATIC_STRING("SUBPROCESS_EXEC_WRAPPER");
|
501
|
+
case SUBPROCESS_WRAPPER_PREPARATION:
|
502
|
+
return P_STATIC_STRING("SUBPROCESS_WRAPPER_PREPARATION");
|
503
|
+
case SUBPROCESS_APP_LOAD_OR_EXEC:
|
504
|
+
return P_STATIC_STRING("SUBPROCESS_APP_LOAD_OR_EXEC");
|
505
|
+
case SUBPROCESS_PREPARE_AFTER_FORKING_FROM_PRELOADER:
|
506
|
+
return P_STATIC_STRING("SUBPROCESS_PREPARE_AFTER_FORKING_FROM_PRELOADER");
|
507
|
+
case SUBPROCESS_LISTEN:
|
508
|
+
return P_STATIC_STRING("SUBPROCESS_LISTEN");
|
509
|
+
case SUBPROCESS_FINISH:
|
510
|
+
return P_STATIC_STRING("SUBPROCESS_FINISH");
|
511
|
+
|
512
|
+
default:
|
513
|
+
return P_STATIC_STRING("UNKNOWN_JOURNEY_STEP");
|
514
|
+
}
|
515
|
+
}
|
516
|
+
|
517
|
+
inline OXT_PURE string
|
518
|
+
journeyStepToStringLowerCase(JourneyStep step) {
|
519
|
+
StaticString stepString = journeyStepToString(step);
|
520
|
+
DynamicBuffer stepStringLcBuffer(stepString.size());
|
521
|
+
convertLowerCase((const unsigned char *) stepString.data(),
|
522
|
+
(unsigned char *) stepStringLcBuffer.data, stepString.size());
|
523
|
+
return string(stepStringLcBuffer.data, stepString.size());
|
524
|
+
}
|
525
|
+
|
526
|
+
inline OXT_PURE StaticString
|
527
|
+
journeyStepStateToString(JourneyStepState state) {
|
528
|
+
switch (state) {
|
529
|
+
case STEP_NOT_STARTED:
|
530
|
+
return P_STATIC_STRING("STEP_NOT_STARTED");
|
531
|
+
case STEP_IN_PROGRESS:
|
532
|
+
return P_STATIC_STRING("STEP_IN_PROGRESS");
|
533
|
+
case STEP_PERFORMED:
|
534
|
+
return P_STATIC_STRING("STEP_PERFORMED");
|
535
|
+
case STEP_ERRORED:
|
536
|
+
return P_STATIC_STRING("STEP_ERRORED");
|
537
|
+
default:
|
538
|
+
return P_STATIC_STRING("UNKNOWN_JOURNEY_STEP_STATE");
|
539
|
+
}
|
540
|
+
}
|
541
|
+
|
542
|
+
inline OXT_PURE JourneyStepState
|
543
|
+
stringToJourneyStepState(const StaticString &value) {
|
544
|
+
if (value == P_STATIC_STRING("STEP_NOT_STARTED")) {
|
545
|
+
return STEP_NOT_STARTED;
|
546
|
+
} else if (value == P_STATIC_STRING("STEP_IN_PROGRESS")) {
|
547
|
+
return STEP_IN_PROGRESS;
|
548
|
+
} else if (value == P_STATIC_STRING("STEP_PERFORMED")) {
|
549
|
+
return STEP_PERFORMED;
|
550
|
+
} else if (value == P_STATIC_STRING("STEP_ERRORED")) {
|
551
|
+
return STEP_ERRORED;
|
552
|
+
} else {
|
553
|
+
return UNKNOWN_JOURNEY_STEP_STATE;
|
554
|
+
}
|
555
|
+
}
|
556
|
+
|
557
|
+
|
558
|
+
} // namespace SpawningKit
|
559
|
+
} // namespace Passenger
|
560
|
+
|
561
|
+
#endif /* _PASSENGER_SPAWNING_KIT_HANDSHAKE_JOURNEY_H_ */
|