passenger 2.2.2 → 2.2.3
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.
- data/DEVELOPERS.TXT +13 -3
- data/Rakefile +42 -33
- data/bin/passenger-install-apache2-module +1 -2
- data/bin/passenger-install-nginx-module +7 -19
- data/bin/passenger-status +64 -15
- data/bin/passenger-stress-test +2 -2
- data/doc/ApplicationPool algorithm.txt +26 -22
- data/doc/Users guide Apache.html +374 -149
- data/doc/Users guide Apache.txt +318 -51
- data/doc/Users guide Nginx.html +13 -13
- data/doc/Users guide Nginx.txt +7 -2
- data/doc/cxxapi/Bucket_8h-source.html +62 -25
- data/doc/cxxapi/Configuration_8h-source.html +343 -326
- data/doc/cxxapi/DirectoryMapper_8h-source.html +12 -12
- data/doc/cxxapi/Hooks_8h-source.html +1 -1
- data/doc/cxxapi/annotated.html +1 -1
- data/doc/cxxapi/classHooks-members.html +1 -1
- data/doc/cxxapi/classHooks.html +1 -1
- data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +2 -2
- data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +9 -9
- data/doc/cxxapi/classes.html +1 -1
- data/doc/cxxapi/definitions_8h-source.html +1 -1
- data/doc/cxxapi/files.html +1 -1
- data/doc/cxxapi/functions.html +2 -2
- data/doc/cxxapi/functions_func.html +2 -2
- data/doc/cxxapi/graph_legend.html +1 -1
- data/doc/cxxapi/group__Configuration.html +1 -1
- data/doc/cxxapi/group__Core.html +1 -1
- data/doc/cxxapi/group__Hooks.html +1 -1
- data/doc/cxxapi/group__Support.html +1 -1
- data/doc/cxxapi/main.html +1 -1
- data/doc/cxxapi/modules.html +1 -1
- data/doc/rdoc/classes/ConditionVariable.html +194 -0
- data/doc/rdoc/classes/Exception.html +120 -0
- data/doc/rdoc/classes/GC.html +113 -0
- data/doc/rdoc/classes/IO.html +169 -0
- data/doc/rdoc/classes/PhusionPassenger.html +238 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractInstaller.html +153 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractRequestHandler.html +517 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer.html +719 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerAlreadyStarted.html +97 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerError.html +96 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer/ServerNotStarted.html +97 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServer/UnknownMessage.html +96 -0
- data/doc/rdoc/classes/PhusionPassenger/AbstractServerCollection.html +598 -0
- data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +140 -0
- data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +317 -0
- data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess/Instance.html +138 -0
- data/doc/rdoc/classes/PhusionPassenger/AppInitError.html +154 -0
- data/doc/rdoc/classes/PhusionPassenger/Application.html +283 -0
- data/doc/rdoc/classes/PhusionPassenger/ConsoleTextTemplate.html +172 -0
- data/doc/rdoc/classes/PhusionPassenger/FrameworkInitError.html +145 -0
- data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +175 -0
- data/doc/rdoc/classes/PhusionPassenger/InitializationError.html +141 -0
- data/doc/rdoc/classes/PhusionPassenger/InvalidPath.html +92 -0
- data/doc/rdoc/classes/PhusionPassenger/MessageChannel.html +489 -0
- data/doc/rdoc/classes/PhusionPassenger/NativeSupport.html +350 -0
- data/doc/rdoc/classes/PhusionPassenger/Rack.html +91 -0
- data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner.html +188 -0
- data/doc/rdoc/classes/PhusionPassenger/Rack/RequestHandler.html +194 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz.html +95 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner.html +442 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner/Error.html +98 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/CGIFixed.html +200 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner.html +436 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner/Error.html +98 -0
- data/doc/rdoc/classes/PhusionPassenger/Railz/RequestHandler.html +155 -0
- data/doc/rdoc/classes/PhusionPassenger/SpawnManager.html +402 -0
- data/doc/rdoc/classes/PhusionPassenger/UnknownError.html +125 -0
- data/doc/rdoc/classes/PhusionPassenger/Utils.html +805 -0
- data/doc/rdoc/classes/PhusionPassenger/VersionNotFound.html +140 -0
- data/doc/rdoc/classes/PhusionPassenger/WSGI.html +89 -0
- data/doc/rdoc/classes/PhusionPassenger/WSGI/ApplicationSpawner.html +188 -0
- data/doc/rdoc/classes/PlatformInfo.html +831 -0
- data/doc/rdoc/classes/RakeExtensions.html +197 -0
- data/doc/rdoc/classes/Signal.html +131 -0
- data/doc/rdoc/created.rid +1 -0
- data/doc/rdoc/files/DEVELOPERS_TXT.html +255 -0
- data/doc/rdoc/files/README.html +157 -0
- data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +92 -0
- data/doc/rdoc/files/lib/phusion_passenger/abstract_installer_rb.html +129 -0
- data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +131 -0
- data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +126 -0
- data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +130 -0
- data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +130 -0
- data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +127 -0
- data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +126 -0
- data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +134 -0
- data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +126 -0
- data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/packaging_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +127 -0
- data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +133 -0
- data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +127 -0
- data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +143 -0
- data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +126 -0
- data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +145 -0
- data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +127 -0
- data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +122 -0
- data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +161 -0
- data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +175 -0
- data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +129 -0
- data/doc/rdoc/files/misc/rake/extensions_rb.html +130 -0
- data/doc/rdoc/fr_class_index.html +90 -0
- data/doc/rdoc/fr_file_index.html +76 -0
- data/doc/rdoc/fr_method_index.html +200 -0
- data/doc/rdoc/index.html +26 -0
- data/doc/rdoc/rdoc-style.css +187 -0
- data/doc/users_guide_snippets/rackup_specifications.txt +2 -8
- data/ext/apache2/Bucket.cpp +71 -38
- data/ext/apache2/Bucket.h +53 -16
- data/ext/apache2/Configuration.cpp +15 -0
- data/ext/apache2/Configuration.h +19 -2
- data/ext/apache2/DirectoryMapper.h +10 -10
- data/ext/apache2/Hooks.cpp +334 -74
- data/ext/boost/mpl/apply.hpp +5 -1
- data/ext/boost/mpl/apply_wrap.hpp +5 -2
- data/ext/boost/mpl/aux_/full_lambda.hpp +5 -1
- data/ext/boost/mpl/bind.hpp +5 -1
- data/ext/common/Application.h +11 -31
- data/ext/common/ApplicationPool.h +2 -1
- data/ext/common/ApplicationPoolServer.h +61 -20
- data/ext/common/ApplicationPoolServerExecutable.cpp +132 -4
- data/ext/common/ApplicationPoolStatusReporter.h +189 -65
- data/ext/common/Base64.cpp +143 -0
- data/ext/common/Base64.h +57 -0
- data/ext/common/CachedFileStat.cpp +25 -82
- data/ext/common/CachedFileStat.h +11 -125
- data/ext/common/CachedFileStat.hpp +243 -0
- data/ext/common/Exceptions.h +13 -0
- data/ext/common/FileChangeChecker.h +209 -0
- data/ext/common/Logging.h +3 -2
- data/ext/common/MessageChannel.h +10 -10
- data/ext/common/PoolOptions.h +72 -5
- data/ext/common/SpawnManager.h +11 -8
- data/ext/common/StandardApplicationPool.h +38 -39
- data/ext/common/StaticString.h +1 -0
- data/ext/common/StringListCreator.h +83 -0
- data/ext/common/SystemTime.h +3 -2
- data/ext/common/Timer.h +88 -0
- data/ext/common/Utils.cpp +161 -42
- data/ext/common/Utils.h +62 -31
- data/ext/common/Version.h +1 -1
- data/ext/nginx/Configuration.c +0 -4
- data/ext/nginx/ContentHandler.c +8 -6
- data/ext/nginx/HelperServer.cpp +45 -55
- data/ext/nginx/HttpStatusExtractor.h +4 -0
- data/ext/nginx/StaticContentHandler.c +25 -5
- data/ext/nginx/config +3 -0
- data/ext/nginx/ngx_http_passenger_module.c +72 -17
- data/ext/nginx/ngx_http_passenger_module.h +2 -2
- data/lib/phusion_passenger/abstract_request_handler.rb +15 -7
- data/lib/phusion_passenger/abstract_server.rb +16 -2
- data/lib/phusion_passenger/admin_tools/control_process.rb +36 -25
- data/lib/phusion_passenger/constants.rb +1 -1
- data/lib/phusion_passenger/dependencies.rb +10 -0
- data/lib/phusion_passenger/platform_info.rb +1 -1
- data/lib/phusion_passenger/rack/application_spawner.rb +21 -2
- data/lib/phusion_passenger/rack/request_handler.rb +10 -0
- data/lib/phusion_passenger/railz/application_spawner.rb +38 -2
- data/lib/phusion_passenger/railz/framework_spawner.rb +26 -28
- data/lib/phusion_passenger/railz/request_handler.rb +5 -1
- data/lib/phusion_passenger/spawn_manager.rb +6 -2
- data/lib/phusion_passenger/utils.rb +79 -27
- data/misc/rake/cplusplus.rb +5 -5
- data/test/ApplicationPoolServerTest.cpp +42 -0
- data/test/ApplicationPoolTest.cpp +255 -267
- data/test/Base64Test.cpp +48 -0
- data/test/CachedFileStatTest.cpp +243 -103
- data/test/FileChangeCheckerTest.cpp +331 -0
- data/test/PoolOptionsTest.cpp +80 -0
- data/test/UtilsTest.cpp +5 -17
- data/test/integration_tests/apache2_tests.rb +15 -4
- data/test/integration_tests/mycook_spec.rb +3 -4
- data/test/oxt/syscall_interruption_test.cpp +2 -14
- data/test/ruby/abstract_server_collection_spec.rb +1 -1
- data/test/ruby/abstract_server_spec.rb +35 -1
- data/test/ruby/rack/application_spawner_spec.rb +23 -6
- data/test/ruby/rails/application_spawner_spec.rb +6 -6
- data/test/ruby/rails/framework_spawner_spec.rb +6 -5
- data/test/ruby/rails/minimal_spawner_spec.rb +19 -0
- data/test/ruby/rails/spawner_error_handling_spec.rb +62 -7
- data/test/ruby/spawn_manager_spec.rb +10 -7
- data/test/ruby/spawn_server_spec.rb +1 -1
- data/test/ruby/utils_spec.rb +193 -20
- data/test/ruby/wsgi/application_spawner_spec.rb +3 -1
- data/test/stub/apache2/httpd.conf.erb +3 -0
- data/test/stub/rack/config.ru +1 -1
- data/test/stub/rails_apps/mycook/app/controllers/welcome_controller.rb +8 -0
- data/test/support/Support.cpp +84 -0
- data/test/support/Support.h +66 -8
- data/test/support/config.rb +14 -2
- data/test/support/test_helper.rb +5 -0
- data/vendor/rack-1.0.0-git/lib/rack/auth/openid.rb +123 -116
- data/vendor/rack-1.0.0-git/lib/rack/cascade.rb +17 -12
- data/vendor/rack-1.0.0-git/lib/rack/commonlogger.rb +34 -43
- data/vendor/rack-1.0.0-git/lib/rack/handler/cgi.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/handler/fastcgi.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/handler/lsws.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/handler/mongrel.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/handler/scgi.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/handler/webrick.rb +1 -1
- data/vendor/rack-1.0.0-git/lib/rack/mock.rb +4 -17
- data/vendor/rack-1.0.0-git/lib/rack/request.rb +3 -9
- data/vendor/rack-1.0.0-git/lib/rack/rewindable_input.rb +2 -0
- data/vendor/rack-1.0.0-git/lib/rack/utils.rb +38 -12
- metadata +231 -186
- data/ext/common/FileChecker.h +0 -112
- data/test/FileCheckerTest.cpp +0 -79
- data/test/stub/minimal-railsapp/README +0 -3
- data/test/stub/minimal-railsapp/config/application.rb +0 -0
- data/test/stub/minimal-railsapp/config/environment.rb +0 -3
- data/test/stub/minimal-railsapp/vendor/rails/actionmailer/lib/action_mailer.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_controller.rb +0 -10
- data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_pack.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/actionpack/lib/action_view.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/activerecord/lib/active_record.rb +0 -7
- data/test/stub/minimal-railsapp/vendor/rails/activeresource/lib/active_resource.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support.rb +0 -17
- data/test/stub/minimal-railsapp/vendor/rails/activesupport/lib/active_support/whiny_nil.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/railties/lib/dispatcher.rb +0 -0
- data/test/stub/minimal-railsapp/vendor/rails/railties/lib/initializer.rb +0 -8
- data/test/stub/minimal-railsapp/vendor/rails/railties/lib/ruby_version_check.rb +0 -1
- data/test/stub/railsapp/app/controllers/application.rb +0 -12
- data/test/stub/railsapp/app/controllers/bar_controller.rb +0 -5
- data/test/stub/railsapp/app/controllers/bar_controller_1.txt +0 -5
- data/test/stub/railsapp/app/controllers/bar_controller_2.txt +0 -5
- data/test/stub/railsapp/app/controllers/foo_controller.rb +0 -9
- data/test/stub/railsapp/app/helpers/application_helper.rb +0 -3
- data/test/stub/railsapp/config/boot.rb +0 -108
- data/test/stub/railsapp/config/database.yml +0 -19
- data/test/stub/railsapp/config/environment.rb +0 -59
- data/test/stub/railsapp/config/environments/development.rb +0 -18
- data/test/stub/railsapp/config/environments/production.rb +0 -19
- data/test/stub/railsapp/config/initializers/inflections.rb +0 -10
- data/test/stub/railsapp/config/initializers/mime_types.rb +0 -5
- data/test/stub/railsapp/config/routes.rb +0 -35
- data/test/stub/railsapp/public/useless.txt +0 -1
- data/test/stub/railsapp2/app/controllers/application.rb +0 -12
- data/test/stub/railsapp2/app/controllers/foo_controller.rb +0 -5
- data/test/stub/railsapp2/app/helpers/application_helper.rb +0 -3
- data/test/stub/railsapp2/config/boot.rb +0 -108
- data/test/stub/railsapp2/config/database.yml +0 -19
- data/test/stub/railsapp2/config/environment.rb +0 -59
- data/test/stub/railsapp2/config/environments/development.rb +0 -18
- data/test/stub/railsapp2/config/environments/production.rb +0 -19
- data/test/stub/railsapp2/config/initializers/inflections.rb +0 -10
- data/test/stub/railsapp2/config/initializers/mime_types.rb +0 -5
- data/test/stub/railsapp2/config/routes.rb +0 -35
- data/test/stub/railsapp2/public/useless.txt +0 -1
@@ -0,0 +1,243 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - http://www.modrails.com/
|
3
|
+
* Copyright (c) 2009 Phusion
|
4
|
+
*
|
5
|
+
* "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
*
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
*
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#ifndef _PASSENGER_CACHED_FILE_STAT_HPP_
|
26
|
+
#define _PASSENGER_CACHED_FILE_STAT_HPP_
|
27
|
+
|
28
|
+
#include <sys/types.h>
|
29
|
+
#include <sys/stat.h>
|
30
|
+
#include <unistd.h>
|
31
|
+
#include <time.h>
|
32
|
+
|
33
|
+
#include <cerrno>
|
34
|
+
#include <cassert>
|
35
|
+
#include <string>
|
36
|
+
#include <boost/shared_ptr.hpp>
|
37
|
+
#include <oxt/system_calls.hpp>
|
38
|
+
|
39
|
+
#include "SystemTime.h"
|
40
|
+
|
41
|
+
namespace Passenger {
|
42
|
+
|
43
|
+
using namespace std;
|
44
|
+
using namespace oxt;
|
45
|
+
using namespace boost;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* CachedFileStat allows one to stat() files at a throttled rate, in order
|
49
|
+
* to minimize stress on the filesystem. It does this by caching the old stat
|
50
|
+
* data for a specified amount of time.
|
51
|
+
*
|
52
|
+
* The cache has a maximum size, which may be altered during runtime. If a
|
53
|
+
* file that wasn't in the cache is being stat()ed, and the cache is full,
|
54
|
+
* then the oldest cache entry will be removed.
|
55
|
+
*
|
56
|
+
* This class is fully thread-safe.
|
57
|
+
*/
|
58
|
+
class CachedFileStat {
|
59
|
+
public:
|
60
|
+
/** Represents a cached file stat entry. */
|
61
|
+
class Entry {
|
62
|
+
private:
|
63
|
+
/** The last return value of stat(). */
|
64
|
+
int last_result;
|
65
|
+
|
66
|
+
/** The errno set by the last stat() call. */
|
67
|
+
int last_errno;
|
68
|
+
|
69
|
+
/** The last time a stat() was performed. */
|
70
|
+
time_t last_time;
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Checks whether <em>interval</em> seconds have elapsed since <em>begin</em>
|
74
|
+
* The current time is returned via the <tt>currentTime</tt> argument,
|
75
|
+
* so that the caller doesn't have to call time() again if it needs the current
|
76
|
+
* time.
|
77
|
+
*
|
78
|
+
* @pre begin <= time(NULL)
|
79
|
+
* @return Whether <tt>interval</tt> seconds have elapsed since <tt>begin</tt>.
|
80
|
+
* @throws TimeRetrievalException Something went wrong while retrieving the time.
|
81
|
+
* @throws boost::thread_interrupted
|
82
|
+
*/
|
83
|
+
bool expired(time_t begin, unsigned int interval, time_t ¤tTime) {
|
84
|
+
currentTime = SystemTime::get();
|
85
|
+
return (unsigned int) (currentTime - begin) >= interval;
|
86
|
+
}
|
87
|
+
|
88
|
+
public:
|
89
|
+
/** The cached stat info. */
|
90
|
+
struct stat info;
|
91
|
+
|
92
|
+
/** This entry's filename. */
|
93
|
+
string filename;
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Creates a new Entry object. The file will not be
|
97
|
+
* stat()ted until you call refresh().
|
98
|
+
*
|
99
|
+
* @param filename The file to stat.
|
100
|
+
*/
|
101
|
+
Entry(const string &filename) {
|
102
|
+
memset(&info, 0, sizeof(struct stat));
|
103
|
+
this->filename = filename;
|
104
|
+
last_result = -1;
|
105
|
+
last_errno = 0;
|
106
|
+
last_time = 0;
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Re-stat() the file, if necessary. If <tt>throttleRate</tt> seconds have
|
111
|
+
* passed since the last time stat() was called, then the file will be
|
112
|
+
* re-stat()ted.
|
113
|
+
*
|
114
|
+
* The stat information, which may either be the result of a new stat() call
|
115
|
+
* or just the old cached information, is be available in the <tt>info</tt>
|
116
|
+
* member.
|
117
|
+
*
|
118
|
+
* @return 0 if the stat() call succeeded or if no stat() was performed,
|
119
|
+
* -1 if something went wrong while statting the file. In the latter
|
120
|
+
* case, <tt>errno</tt> will be populated with an appropriate error code.
|
121
|
+
* @throws TimeRetrievalException Something went wrong while retrieving the
|
122
|
+
* system time.
|
123
|
+
* @throws boost::thread_interrupted
|
124
|
+
*/
|
125
|
+
int refresh(unsigned int throttleRate) {
|
126
|
+
time_t currentTime;
|
127
|
+
|
128
|
+
if (expired(last_time, throttleRate, currentTime)) {
|
129
|
+
last_result = syscalls::stat(filename.c_str(), &info);
|
130
|
+
last_errno = errno;
|
131
|
+
last_time = currentTime;
|
132
|
+
return last_result;
|
133
|
+
} else {
|
134
|
+
errno = last_errno;
|
135
|
+
return last_result;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
};
|
139
|
+
|
140
|
+
typedef shared_ptr<Entry> EntryPtr;
|
141
|
+
typedef list<EntryPtr> EntryList;
|
142
|
+
typedef map<string, EntryList::iterator> EntryMap;
|
143
|
+
|
144
|
+
unsigned int maxSize;
|
145
|
+
EntryList entries;
|
146
|
+
EntryMap cache;
|
147
|
+
mutable boost::mutex lock;
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Creates a new CachedFileStat object.
|
151
|
+
*
|
152
|
+
* @param maxSize The maximum cache size. A size of 0 means unlimited.
|
153
|
+
*/
|
154
|
+
CachedFileStat(unsigned int maxSize = 0) {
|
155
|
+
this->maxSize = maxSize;
|
156
|
+
}
|
157
|
+
|
158
|
+
/**
|
159
|
+
* Stats the given file. If <tt>throttleRate</tt> seconds have passed since
|
160
|
+
* the last time stat() was called on this file, then the file will be
|
161
|
+
* re-stat()ted, otherwise the cached stat information will be returned.
|
162
|
+
*
|
163
|
+
* @param filename The file to stat.
|
164
|
+
* @param stat A pointer to a stat struct; the retrieved stat information
|
165
|
+
* will be stored here.
|
166
|
+
* @param throttleRate Tells this CachedFileStat that the file may only
|
167
|
+
* be statted at most every <tt>throttleRate</tt> seconds.
|
168
|
+
* @return 0 if the stat() call succeeded or if the cached stat information was used;
|
169
|
+
* -1 if something went wrong while statting the file. In the latter
|
170
|
+
* case, <tt>errno</tt> will be populated with an appropriate error code.
|
171
|
+
* @throws SystemException Something went wrong while retrieving the
|
172
|
+
* system time. stat() errors will <em>not</em> result in
|
173
|
+
* SystemException being thrown.
|
174
|
+
* @throws boost::thread_interrupted
|
175
|
+
*/
|
176
|
+
int stat(const string &filename, struct stat *buf, unsigned int throttleRate = 0) {
|
177
|
+
boost::unique_lock<boost::mutex> l(lock);
|
178
|
+
EntryMap::iterator it(cache.find(filename));
|
179
|
+
EntryPtr entry;
|
180
|
+
int ret;
|
181
|
+
|
182
|
+
if (it == cache.end()) {
|
183
|
+
// Filename not in cache.
|
184
|
+
// If cache is full, remove the least recently used
|
185
|
+
// cache entry.
|
186
|
+
if (maxSize != 0 && cache.size() == maxSize) {
|
187
|
+
EntryList::iterator listEnd(entries.end());
|
188
|
+
listEnd--;
|
189
|
+
string filename((*listEnd)->filename);
|
190
|
+
entries.pop_back();
|
191
|
+
cache.erase(filename);
|
192
|
+
}
|
193
|
+
|
194
|
+
// Add to cache as most recently used.
|
195
|
+
entry = EntryPtr(new Entry(filename));
|
196
|
+
entries.push_front(entry);
|
197
|
+
cache[filename] = entries.begin();
|
198
|
+
} else {
|
199
|
+
// Cache hit.
|
200
|
+
entry = *it->second;
|
201
|
+
|
202
|
+
// Mark this cache item as most recently used.
|
203
|
+
entries.erase(it->second);
|
204
|
+
entries.push_front(entry);
|
205
|
+
cache[filename] = entries.begin();
|
206
|
+
}
|
207
|
+
ret = entry->refresh(throttleRate);
|
208
|
+
*buf = entry->info;
|
209
|
+
return ret;
|
210
|
+
}
|
211
|
+
|
212
|
+
/**
|
213
|
+
* Change the maximum size of the cache. If the new size is larger
|
214
|
+
* than the old size, then the oldest entries in the cache are
|
215
|
+
* removed.
|
216
|
+
*
|
217
|
+
* A size of 0 means unlimited.
|
218
|
+
*/
|
219
|
+
void setMaxSize(unsigned int maxSize) {
|
220
|
+
boost::unique_lock<boost::mutex> l(lock);
|
221
|
+
if (maxSize != 0) {
|
222
|
+
int toRemove = cache.size() - maxSize;
|
223
|
+
for (int i = 0; i < toRemove; i++) {
|
224
|
+
string filename(entries.back()->filename);
|
225
|
+
entries.pop_back();
|
226
|
+
cache.erase(filename);
|
227
|
+
}
|
228
|
+
}
|
229
|
+
this->maxSize = maxSize;
|
230
|
+
}
|
231
|
+
|
232
|
+
/**
|
233
|
+
* Returns whether <tt>filename</tt> is in the cache.
|
234
|
+
*/
|
235
|
+
bool knows(const string &filename) const {
|
236
|
+
boost::unique_lock<boost::mutex> l(lock);
|
237
|
+
return cache.find(filename) != cache.end();
|
238
|
+
}
|
239
|
+
};
|
240
|
+
|
241
|
+
} // namespace Passenger
|
242
|
+
|
243
|
+
#endif /* _PASSENGER_CACHED_FILE_STAT_HPP_ */
|
data/ext/common/Exceptions.h
CHANGED
@@ -136,6 +136,19 @@ public:
|
|
136
136
|
}
|
137
137
|
};
|
138
138
|
|
139
|
+
/**
|
140
|
+
* Unable to retrieve the system time using <tt>time()</tt>.
|
141
|
+
*
|
142
|
+
* @ingroup Exceptions
|
143
|
+
*/
|
144
|
+
class TimeRetrievalException: public SystemException {
|
145
|
+
public:
|
146
|
+
TimeRetrievalException(const string &message, int errorCode)
|
147
|
+
: SystemException(message, errorCode)
|
148
|
+
{}
|
149
|
+
virtual ~TimeRetrievalException() throw() {}
|
150
|
+
};
|
151
|
+
|
139
152
|
/**
|
140
153
|
* Represents an error that occured during an I/O operation.
|
141
154
|
*
|
@@ -0,0 +1,209 @@
|
|
1
|
+
/*
|
2
|
+
* Phusion Passenger - http://www.modrails.com/
|
3
|
+
* Copyright (c) 2009 Phusion
|
4
|
+
*
|
5
|
+
* "Phusion Passenger" is a trademark of Hongli Lai & Ninh Bui.
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
8
|
+
* of this software and associated documentation files (the "Software"), to deal
|
9
|
+
* in the Software without restriction, including without limitation the rights
|
10
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
11
|
+
* copies of the Software, and to permit persons to whom the Software is
|
12
|
+
* furnished to do so, subject to the following conditions:
|
13
|
+
*
|
14
|
+
* The above copyright notice and this permission notice shall be included in
|
15
|
+
* all copies or substantial portions of the Software.
|
16
|
+
*
|
17
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
18
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
19
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
20
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
21
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
22
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
23
|
+
* THE SOFTWARE.
|
24
|
+
*/
|
25
|
+
#ifndef _PASSENGER_CHANGE_FILE_CHECKER_H_
|
26
|
+
#define _PASSENGER_CHANGE_FILE_CHECKER_H_
|
27
|
+
|
28
|
+
#include <string>
|
29
|
+
|
30
|
+
#include <boost/thread.hpp>
|
31
|
+
#include <errno.h>
|
32
|
+
|
33
|
+
#include "CachedFileStat.hpp"
|
34
|
+
#include "SystemTime.h"
|
35
|
+
|
36
|
+
namespace Passenger {
|
37
|
+
|
38
|
+
using namespace std;
|
39
|
+
using namespace oxt;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* A utility class for checking for file changes. Example:
|
43
|
+
*
|
44
|
+
* @code
|
45
|
+
* FileChangeChecker checker;
|
46
|
+
* checker.changed("foo.txt"); // false
|
47
|
+
* writeToFile("foo.txt");
|
48
|
+
* checker.changed("foo.txt"); // true
|
49
|
+
* checker.changed("foo.txt"); // false
|
50
|
+
* @endcode
|
51
|
+
*
|
52
|
+
* FileChangeChecker uses stat() to retrieve file information. It also
|
53
|
+
* supports throttling in order to limit the number of actual stat() calls.
|
54
|
+
* This can improve performance on systems where disk I/O is a problem.
|
55
|
+
*/
|
56
|
+
class FileChangeChecker {
|
57
|
+
private:
|
58
|
+
struct Entry {
|
59
|
+
string filename;
|
60
|
+
time_t lastMtime;
|
61
|
+
time_t lastCtime;
|
62
|
+
|
63
|
+
Entry(const string &filename) {
|
64
|
+
this->filename = filename;
|
65
|
+
this->lastMtime = 0;
|
66
|
+
this->lastCtime = 0;
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
typedef shared_ptr<Entry> EntryPtr;
|
71
|
+
typedef list<EntryPtr> EntryList;
|
72
|
+
typedef map<string, EntryList::iterator> EntryMap;
|
73
|
+
|
74
|
+
CachedFileStat cstat;
|
75
|
+
mutable boost::mutex lock;
|
76
|
+
unsigned int maxSize;
|
77
|
+
EntryList entries;
|
78
|
+
EntryMap fileToEntry;
|
79
|
+
|
80
|
+
public:
|
81
|
+
/**
|
82
|
+
* Create a FileChangeChecker object.
|
83
|
+
*
|
84
|
+
* @param maxSize The maximum size of the internal file list. A size of 0 means unlimited.
|
85
|
+
*/
|
86
|
+
FileChangeChecker(unsigned int maxSize = 0)
|
87
|
+
: cstat(maxSize)
|
88
|
+
{
|
89
|
+
this->maxSize = maxSize;
|
90
|
+
}
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Checks whether, since the last call to changed() with this filename,
|
94
|
+
* the file's timestamp has changed or whether the file has been created
|
95
|
+
* or removed. If the stat() call fails for any other reason (e.g. the
|
96
|
+
* directory is not readable) then this method will return false.
|
97
|
+
*
|
98
|
+
* If this method was called with this filename for the first time, or if
|
99
|
+
* information about this file has since been removed from the internal
|
100
|
+
* file list, then this method will return whether the file is stat()-able.
|
101
|
+
* That is, if the file doesn't exist then it will return false, but if
|
102
|
+
* the directory is not readable then it will also return false.
|
103
|
+
*
|
104
|
+
* @param filename The file to check. Note that two different filename
|
105
|
+
* strings are treated as two different files, so you should
|
106
|
+
* use absolute filenames if you change working directory
|
107
|
+
* often.
|
108
|
+
* @param throttleRate When set to a non-zero value, throttling will be
|
109
|
+
* enabled. stat() will be called at most once per
|
110
|
+
* throttleRate seconds.
|
111
|
+
* @throws TimeRetrievalException Something went wrong while retrieving the
|
112
|
+
* system time.
|
113
|
+
* @throws boost::thread_interrupted
|
114
|
+
*/
|
115
|
+
bool changed(const string &filename, unsigned int throttleRate = 0) {
|
116
|
+
boost::unique_lock<boost::mutex> l(lock);
|
117
|
+
EntryMap::iterator it(fileToEntry.find(filename));
|
118
|
+
EntryPtr entry;
|
119
|
+
struct stat buf;
|
120
|
+
bool result, newEntry = false;
|
121
|
+
int ret;
|
122
|
+
|
123
|
+
if (it == fileToEntry.end()) {
|
124
|
+
// Filename not in file list.
|
125
|
+
// If file list is full, remove the least recently used
|
126
|
+
// file list entry.
|
127
|
+
if (maxSize != 0 && fileToEntry.size() == maxSize) {
|
128
|
+
EntryList::iterator listEnd(entries.end());
|
129
|
+
listEnd--;
|
130
|
+
string filename((*listEnd)->filename);
|
131
|
+
entries.pop_back();
|
132
|
+
fileToEntry.erase(filename);
|
133
|
+
}
|
134
|
+
|
135
|
+
// Add to file list as most recently used.
|
136
|
+
entry = EntryPtr(new Entry(filename));
|
137
|
+
entries.push_front(entry);
|
138
|
+
fileToEntry[filename] = entries.begin();
|
139
|
+
newEntry = true;
|
140
|
+
} else {
|
141
|
+
// Filename is in file list.
|
142
|
+
entry = *it->second;
|
143
|
+
|
144
|
+
// Mark this entry as most recently used.
|
145
|
+
entries.erase(it->second);
|
146
|
+
entries.push_front(entry);
|
147
|
+
fileToEntry[filename] = entries.begin();
|
148
|
+
}
|
149
|
+
|
150
|
+
ret = cstat.stat(filename, &buf, throttleRate);
|
151
|
+
if (newEntry) {
|
152
|
+
// The file's information isn't in the file list.
|
153
|
+
if (ret == -1) {
|
154
|
+
entry->lastMtime = 0;
|
155
|
+
entry->lastCtime = 0;
|
156
|
+
return false;
|
157
|
+
} else {
|
158
|
+
entry->lastMtime = buf.st_mtime;
|
159
|
+
entry->lastCtime = buf.st_ctime;
|
160
|
+
return true;
|
161
|
+
}
|
162
|
+
} else {
|
163
|
+
// The file's information was already in the file list.
|
164
|
+
if (ret == -1 && errno == ENOENT) {
|
165
|
+
result = entry->lastMtime != 0 || entry->lastCtime != 0;
|
166
|
+
entry->lastMtime = 0;
|
167
|
+
entry->lastCtime = 0;
|
168
|
+
} else if (ret == -1) {
|
169
|
+
result = false;
|
170
|
+
} else {
|
171
|
+
result = entry->lastMtime != buf.st_mtime || entry->lastCtime != buf.st_ctime;
|
172
|
+
entry->lastMtime = buf.st_mtime;
|
173
|
+
entry->lastCtime = buf.st_ctime;
|
174
|
+
}
|
175
|
+
return result;
|
176
|
+
}
|
177
|
+
}
|
178
|
+
|
179
|
+
/**
|
180
|
+
* Change the maximum size of the internal file list.
|
181
|
+
*
|
182
|
+
* A size of 0 means unlimited.
|
183
|
+
*/
|
184
|
+
void setMaxSize(unsigned int maxSize) {
|
185
|
+
boost::unique_lock<boost::mutex> l(lock);
|
186
|
+
if (maxSize != 0) {
|
187
|
+
int toRemove = fileToEntry.size() - maxSize;
|
188
|
+
for (int i = 0; i < toRemove; i++) {
|
189
|
+
string filename(entries.back()->filename);
|
190
|
+
entries.pop_back();
|
191
|
+
fileToEntry.erase(filename);
|
192
|
+
}
|
193
|
+
}
|
194
|
+
this->maxSize = maxSize;
|
195
|
+
cstat.setMaxSize(maxSize);
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Returns whether <tt>filename</tt> is in the internal file list.
|
200
|
+
*/
|
201
|
+
bool knows(const string &filename) const {
|
202
|
+
boost::unique_lock<boost::mutex> l(lock);
|
203
|
+
return fileToEntry.find(filename) != fileToEntry.end();
|
204
|
+
}
|
205
|
+
};
|
206
|
+
|
207
|
+
} // namespace Passenger
|
208
|
+
|
209
|
+
#endif /* _PASSENGER_CHANGE_FILE_CHECKER_H_ */
|