passenger 4.0.48 → 4.0.49
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 +8 -8
- checksums.yaml.gz.asc +7 -7
- data.tar.gz.asc +7 -7
- data/.editorconfig +36 -2
- data/.travis.yml +1 -1
- data/CHANGELOG +16 -0
- data/Rakefile +0 -1
- data/build/apache2.rb +4 -4
- data/build/common_library.rb +18 -18
- data/build/cplusplus_support.rb +2 -2
- data/build/documentation.rb +1 -1
- data/build/integration_tests.rb +12 -4
- data/build/misc.rb +12 -7
- data/build/packaging.rb +14 -14
- data/build/preprocessor.rb +10 -10
- data/build/rake_extensions.rb +11 -11
- data/build/ruby_extension.rb +2 -2
- data/dev/ci/inituidgid +24 -0
- data/dev/ci/run_jenkins.sh +57 -0
- data/dev/ci/run_rpm_tests.sh +77 -0
- data/dev/{run_travis.sh → ci/run_travis.sh} +60 -4
- data/doc/Users guide Nginx.txt +2 -2
- data/doc/users_guide_snippets/environment_variables.txt +0 -2
- data/doc/users_guide_snippets/tips.txt +20 -1
- data/ext/apache2/Bucket.cpp +18 -18
- data/ext/apache2/Bucket.h +4 -4
- data/ext/apache2/Configuration.cpp +7 -7
- data/ext/apache2/Configuration.hpp +43 -43
- data/ext/apache2/DirectoryMapper.h +5 -5
- data/ext/apache2/Hooks.cpp +142 -142
- data/ext/apache2/MergeDirConfig.cpp +40 -40
- data/ext/common/Account.h +17 -17
- data/ext/common/AccountsDatabase.h +9 -9
- data/ext/common/AgentsStarter.cpp +2 -2
- data/ext/common/AgentsStarter.h +40 -40
- data/ext/common/ApplicationPool2/Common.h +10 -6
- data/ext/common/ApplicationPool2/ComponentInfo.h +2 -2
- data/ext/common/ApplicationPool2/DirectSpawner.h +17 -17
- data/ext/common/ApplicationPool2/DummySpawner.h +5 -5
- data/ext/common/ApplicationPool2/Group.h +54 -38
- data/ext/common/ApplicationPool2/Implementation.cpp +76 -49
- data/ext/common/ApplicationPool2/Options.h +98 -91
- data/ext/common/ApplicationPool2/Pool.h +70 -69
- data/ext/common/ApplicationPool2/Process.h +21 -21
- data/ext/common/ApplicationPool2/Session.h +11 -11
- data/ext/common/ApplicationPool2/SmartSpawner.h +60 -60
- data/ext/common/ApplicationPool2/Socket.h +19 -19
- data/ext/common/ApplicationPool2/Spawner.h +64 -72
- data/ext/common/ApplicationPool2/SpawnerFactory.h +4 -4
- data/ext/common/ApplicationPool2/SuperGroup.h +41 -41
- data/ext/common/BackgroundEventLoop.cpp +1 -1
- data/ext/common/BackgroundEventLoop.h +2 -2
- data/ext/common/Constants.h +1 -1
- data/ext/common/EventedBufferedInput.h +5 -5
- data/ext/common/EventedClient.h +51 -51
- data/ext/common/EventedMessageServer.h +39 -39
- data/ext/common/EventedServer.h +32 -32
- data/ext/common/Exceptions.h +23 -23
- data/ext/common/FileDescriptor.h +18 -18
- data/ext/common/Logging.cpp +1 -1
- data/ext/common/MessageClient.h +27 -27
- data/ext/common/MessageReadersWriters.h +79 -79
- data/ext/common/MessageServer.h +59 -59
- data/ext/common/RandomGenerator.h +12 -12
- data/ext/common/ResourceLocator.h +8 -8
- data/ext/common/SafeLibev.h +54 -25
- data/ext/common/ServerInstanceDir.h +31 -31
- data/ext/common/StaticString.h +50 -48
- data/ext/common/Utils.cpp +73 -78
- data/ext/common/Utils.h +6 -6
- data/ext/common/Utils/Base64.cpp +3 -3
- data/ext/common/Utils/Base64.h +7 -7
- data/ext/common/Utils/BlockingQueue.h +9 -9
- data/ext/common/Utils/BufferedIO.h +17 -17
- data/ext/common/Utils/CachedFileStat.hpp +16 -16
- data/ext/common/Utils/Dechunker.h +25 -25
- data/ext/common/Utils/FileChangeChecker.h +10 -10
- data/ext/common/Utils/MemZeroGuard.h +5 -5
- data/ext/common/Utils/MemoryBarrier.h +1 -1
- data/ext/common/Utils/MessageIO.h +61 -61
- data/ext/common/Utils/ProcessMetricsCollector.h +40 -40
- data/ext/common/Utils/ScopeGuard.h +7 -7
- data/ext/common/Utils/SpeedMeter.h +1 -1
- data/ext/common/Utils/StrIntUtils.cpp +13 -13
- data/ext/common/Utils/StrIntUtils.h +3 -3
- data/ext/common/Utils/StringScanning.h +5 -5
- data/ext/common/Utils/SystemMetricsCollector.h +2 -2
- data/ext/common/Utils/SystemTime.h +10 -10
- data/ext/common/Utils/Template.h +2 -2
- data/ext/common/Utils/Timer.h +6 -6
- data/ext/common/Utils/VariantMap.h +29 -29
- data/ext/common/agents/Base.cpp +19 -19
- data/ext/common/agents/HelperAgent/AgentOptions.h +1 -1
- data/ext/common/agents/HelperAgent/FileBackedPipe.h +6 -6
- data/ext/common/agents/HelperAgent/Main.cpp +44 -43
- data/ext/common/agents/HelperAgent/RequestHandler.cpp +4 -4
- data/ext/common/agents/HelperAgent/RequestHandler.h +29 -28
- data/ext/common/agents/HelperAgent/ScgiRequestParser.h +56 -50
- data/ext/common/agents/LoggingAgent/AdminController.h +8 -8
- data/ext/common/agents/LoggingAgent/DataStoreId.h +17 -17
- data/ext/common/agents/LoggingAgent/FilterSupport.h +167 -167
- data/ext/common/agents/LoggingAgent/LoggingServer.h +122 -122
- data/ext/common/agents/LoggingAgent/Main.cpp +7 -7
- data/ext/common/agents/LoggingAgent/RemoteSender.h +54 -54
- data/ext/common/agents/SpawnPreparer.cpp +4 -4
- data/ext/common/agents/TempDirToucher.c +2 -2
- data/ext/common/agents/Watchdog/AgentWatcher.cpp +47 -47
- data/ext/common/agents/Watchdog/HelperAgentWatcher.cpp +7 -7
- data/ext/common/agents/Watchdog/LoggingAgentWatcher.cpp +7 -7
- data/ext/common/agents/Watchdog/Main.cpp +22 -22
- data/ext/common/agents/Watchdog/ServerInstanceDirToucher.cpp +9 -9
- data/ext/libeio/eio.c +1 -1
- data/ext/nginx/Configuration.c +30 -30
- data/ext/nginx/Configuration.h +1 -1
- data/ext/nginx/ContentHandler.c +54 -54
- data/ext/nginx/ContentHandler.h +3 -3
- data/ext/nginx/StaticContentHandler.c +2 -2
- data/ext/nginx/ngx_http_passenger_module.c +21 -21
- data/ext/oxt/detail/backtrace_enabled.hpp +1 -1
- data/ext/oxt/detail/context.hpp +1 -1
- data/ext/oxt/detail/spin_lock_darwin.hpp +4 -4
- data/ext/oxt/detail/spin_lock_gcc_x86.hpp +3 -3
- data/ext/oxt/detail/spin_lock_pthreads.hpp +4 -4
- data/ext/oxt/detail/tracable_exception_disabled.hpp +1 -1
- data/ext/oxt/dynamic_thread_group.hpp +18 -18
- data/ext/oxt/implementation.cpp +9 -8
- data/ext/oxt/macros.hpp +2 -2
- data/ext/oxt/system_calls.cpp +11 -11
- data/ext/oxt/system_calls.hpp +13 -13
- data/ext/oxt/thread.hpp +22 -14
- data/ext/ruby/passenger_native_support.c +55 -55
- data/lib/phusion_passenger.rb +24 -24
- data/lib/phusion_passenger/common_library.rb +2 -0
- data/lib/phusion_passenger/loader_shared_helpers.rb +18 -18
- data/lib/phusion_passenger/packaging.rb +9 -4
- data/lib/phusion_passenger/platform_info/apache.rb +45 -31
- data/lib/phusion_passenger/platform_info/compiler.rb +11 -11
- data/lib/phusion_passenger/rack/thread_handler_extension.rb +1 -1
- data/lib/phusion_passenger/request_handler/thread_handler.rb +8 -8
- data/lib/phusion_passenger/standalone/app_finder.rb +16 -16
- data/lib/phusion_passenger/standalone/command.rb +22 -22
- data/packaging/rpm/LICENSE.txt +19 -0
- data/packaging/rpm/Makefile +13 -0
- data/packaging/rpm/README.md +41 -0
- data/packaging/rpm/Vagrantfile +38 -0
- data/{rpm/Vagrantfile → packaging/rpm/Vagrantfile.centos} +0 -0
- data/packaging/rpm/build +170 -0
- data/packaging/rpm/create_project +41 -0
- data/packaging/rpm/git_update +88 -0
- data/packaging/rpm/image/Dockerfile +37 -0
- data/packaging/rpm/image/Gemfile +3 -0
- data/packaging/rpm/image/Gemfile.lock +12 -0
- data/packaging/rpm/image/RPM-GPG-KEY-amazon-ga +19 -0
- data/packaging/rpm/image/amazon2014-i386.cfg +96 -0
- data/packaging/rpm/image/amazon2014-x86_64.cfg +96 -0
- data/packaging/rpm/image/site-defaults.cfg +168 -0
- data/packaging/rpm/internal/build_tasks.rb +238 -0
- data/packaging/rpm/internal/dummygpg +11 -0
- data/packaging/rpm/internal/exec_build +42 -0
- data/packaging/rpm/internal/get_distro_arch +14 -0
- data/packaging/rpm/internal/get_distro_id +10 -0
- data/packaging/rpm/internal/git_update +27 -0
- data/packaging/rpm/internal/inituidgid +17 -0
- data/packaging/rpm/internal/my_init +344 -0
- data/packaging/rpm/internal/python27 +3 -0
- data/packaging/rpm/internal/repo_update +46 -0
- data/packaging/rpm/internal/setuser +26 -0
- data/packaging/rpm/internal/tracking_helper +40 -0
- data/packaging/rpm/jenkins_release +99 -0
- data/packaging/rpm/lib/build_tasks_support.rb +402 -0
- data/packaging/rpm/lib/preprocessor.rb +341 -0
- data/packaging/rpm/nginx_spec/404.html +119 -0
- data/packaging/rpm/nginx_spec/50x.html +119 -0
- data/packaging/rpm/nginx_spec/index.html +116 -0
- data/packaging/rpm/nginx_spec/nginx-auto-cc-gcc.patch +13 -0
- data/packaging/rpm/nginx_spec/nginx-logo.png +0 -0
- data/packaging/rpm/nginx_spec/nginx-upgrade +13 -0
- data/packaging/rpm/nginx_spec/nginx-upgrade.8 +151 -0
- data/packaging/rpm/nginx_spec/nginx.conf +131 -0
- data/packaging/rpm/nginx_spec/nginx.init +144 -0
- data/packaging/rpm/nginx_spec/nginx.logrotate +13 -0
- data/packaging/rpm/nginx_spec/nginx.service +15 -0
- data/packaging/rpm/nginx_spec/nginx.spec.template +559 -0
- data/packaging/rpm/nginx_spec/nginx.sysconfig +4 -0
- data/packaging/rpm/nginx_spec/passenger.conf +9 -0
- data/packaging/rpm/nginx_spec/poweredby.png +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/apache-passenger.conf.in +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/config.json +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/passenger.logrotate +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/passenger.spec.template +58 -31
- data/{rpm → packaging/rpm/passenger_spec}/passenger_dynamic_thread_group.patch +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/passenger_tests_default_config_example.patch +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/rubygem-passenger-4.0.18-GLIBC_HAVE_LONG_LONG.patch +0 -0
- data/{rpm → packaging/rpm/passenger_spec}/rubygem-passenger-4.0.18-gcc47-include-sys_types.patch +0 -0
- data/packaging/rpm/repo_update +114 -0
- data/packaging/rpm/setup-system +60 -0
- data/packaging/rpm/shell +10 -0
- data/resources/templates/standalone/config.erb +3 -1
- data/test/config.json.rpm-automation +1 -1
- data/test/cxx/ApplicationPool2/DirectSpawnerTest.cpp +11 -11
- data/test/cxx/ApplicationPool2/OptionsTest.cpp +5 -5
- data/test/cxx/ApplicationPool2/PoolTest.cpp +129 -89
- data/test/cxx/ApplicationPool2/ProcessTest.cpp +15 -15
- data/test/cxx/ApplicationPool2/SmartSpawnerTest.cpp +22 -22
- data/test/cxx/ApplicationPool2/SpawnerTestCases.cpp +11 -11
- data/test/cxx/ScgiRequestParserTest.cpp +75 -61
- data/test/cxx/UtilsTest.cpp +86 -85
- data/test/gdbinit.example +3 -0
- data/test/integration_tests/nginx_tests.rb +3 -3
- data/test/integration_tests/source_packaging_test.rb +3 -1
- data/test/stub/nginx/nginx.conf.erb +8 -1
- data/test/support/nginx_controller.rb +7 -7
- metadata +62 -17
- metadata.gz.asc +7 -7
- data/build/rpm.rb +0 -128
- data/dev/rpmtool +0 -21
- data/dev/test_rpm_packaging.sh +0 -28
- data/rpm/get_distro_id.py +0 -4
data/ext/common/MessageServer.h
CHANGED
@@ -121,16 +121,16 @@ using namespace oxt;
|
|
121
121
|
* public:
|
122
122
|
* struct MyContext: public MessageServer::ClientContext {
|
123
123
|
* int count;
|
124
|
-
*
|
124
|
+
*
|
125
125
|
* MyContext() {
|
126
126
|
* count = 0;
|
127
127
|
* }
|
128
128
|
* };
|
129
|
-
*
|
129
|
+
*
|
130
130
|
* MessageServer::ClientContextPtr newClient(MessageServer::CommonClientContext &commonContext) {
|
131
131
|
* return boost::make_shared<MyContext>();
|
132
132
|
* }
|
133
|
-
*
|
133
|
+
*
|
134
134
|
* bool processMessage(MessageServer::CommonClientContext &commonContext,
|
135
135
|
* MessageServer::ClientContextPtr &specificContext,
|
136
136
|
* const vector<string> &args)
|
@@ -145,9 +145,9 @@ using namespace oxt;
|
|
145
145
|
* }
|
146
146
|
* }
|
147
147
|
* };
|
148
|
-
*
|
148
|
+
*
|
149
149
|
* ...
|
150
|
-
*
|
150
|
+
*
|
151
151
|
* MessageServer server("server.sock");
|
152
152
|
* server.addHandler(MessageServer::HandlerPtr(new PingHandler()));
|
153
153
|
* server.addHandler(MessageServer::HandlerPtr(new PingHandler()));
|
@@ -159,15 +159,15 @@ using namespace oxt;
|
|
159
159
|
class MessageServer {
|
160
160
|
public:
|
161
161
|
static const unsigned int CLIENT_THREAD_STACK_SIZE = 1024 * 128;
|
162
|
-
|
162
|
+
|
163
163
|
/** Interface for client context objects. */
|
164
164
|
class ClientContext {
|
165
165
|
public:
|
166
166
|
virtual ~ClientContext() { }
|
167
167
|
};
|
168
|
-
|
168
|
+
|
169
169
|
typedef boost::shared_ptr<ClientContext> ClientContextPtr;
|
170
|
-
|
170
|
+
|
171
171
|
/**
|
172
172
|
* A common client context, containing client-specific information
|
173
173
|
* used by MessageServer itself.
|
@@ -176,21 +176,21 @@ public:
|
|
176
176
|
public:
|
177
177
|
/** The client's socket file descriptor. */
|
178
178
|
FileDescriptor fd;
|
179
|
-
|
179
|
+
|
180
180
|
/** The account with which the client authenticated. */
|
181
181
|
AccountPtr account;
|
182
|
-
|
183
|
-
|
182
|
+
|
183
|
+
|
184
184
|
CommonClientContext(FileDescriptor &_fd, AccountPtr &_account)
|
185
185
|
: fd(_fd),
|
186
186
|
account(_account)
|
187
187
|
{ }
|
188
|
-
|
188
|
+
|
189
189
|
/** Returns a string representation for this client context. */
|
190
190
|
string name() {
|
191
191
|
return toString(fd);
|
192
192
|
}
|
193
|
-
|
193
|
+
|
194
194
|
/**
|
195
195
|
* Checks whether this client has all of the rights in `rights`. The
|
196
196
|
* client will be notified about the result of this check, by sending it a
|
@@ -219,7 +219,7 @@ public:
|
|
219
219
|
writeArrayMessage(fd, "Passed security", NULL);
|
220
220
|
}
|
221
221
|
};
|
222
|
-
|
222
|
+
|
223
223
|
/**
|
224
224
|
* An abstract message handler class.
|
225
225
|
*
|
@@ -271,7 +271,7 @@ public:
|
|
271
271
|
|
272
272
|
public:
|
273
273
|
virtual ~Handler() { }
|
274
|
-
|
274
|
+
|
275
275
|
/**
|
276
276
|
* Called when a new client has connected to the MessageServer.
|
277
277
|
*
|
@@ -284,7 +284,7 @@ public:
|
|
284
284
|
virtual ClientContextPtr newClient(CommonClientContext &context) {
|
285
285
|
return ClientContextPtr();
|
286
286
|
}
|
287
|
-
|
287
|
+
|
288
288
|
/**
|
289
289
|
* Called when a client has disconnected from the MessageServer. The
|
290
290
|
* default implementation does nothing.
|
@@ -299,7 +299,7 @@ public:
|
|
299
299
|
virtual void clientDisconnected(MessageServer::CommonClientContext &context,
|
300
300
|
MessageServer::ClientContextPtr &handlerSpecificContext)
|
301
301
|
{ }
|
302
|
-
|
302
|
+
|
303
303
|
/**
|
304
304
|
* Called then a client has sent a request message.
|
305
305
|
*
|
@@ -316,41 +316,41 @@ public:
|
|
316
316
|
ClientContextPtr &handlerSpecificContext,
|
317
317
|
const vector<string> &args) = 0;
|
318
318
|
};
|
319
|
-
|
319
|
+
|
320
320
|
typedef boost::shared_ptr<Handler> HandlerPtr;
|
321
|
-
|
321
|
+
|
322
322
|
protected:
|
323
323
|
/** The filename of the server socket on which this MessageServer is listening. */
|
324
324
|
string socketFilename;
|
325
|
-
|
325
|
+
|
326
326
|
/** An accounts database, used for authenticating clients. */
|
327
327
|
AccountsDatabasePtr accountsDatabase;
|
328
|
-
|
328
|
+
|
329
329
|
/** The registered message handlers. */
|
330
330
|
vector<HandlerPtr> handlers;
|
331
|
-
|
331
|
+
|
332
332
|
/** The maximum number of milliseconds that client may spend on logging in.
|
333
333
|
* Clients that take longer are disconnected.
|
334
334
|
*
|
335
335
|
* @invariant loginTimeout != 0
|
336
336
|
*/
|
337
337
|
unsigned long long loginTimeout;
|
338
|
-
|
338
|
+
|
339
339
|
/** The client threads. */
|
340
340
|
dynamic_thread_group threadGroup;
|
341
|
-
|
341
|
+
|
342
342
|
/** The server socket's file descriptor.
|
343
343
|
* @invariant serverFd >= 0
|
344
344
|
*/
|
345
345
|
int serverFd;
|
346
|
-
|
347
|
-
|
346
|
+
|
347
|
+
|
348
348
|
/** Calls clientDisconnected() on all handlers when destroyed. */
|
349
349
|
struct DisconnectEventBroadcastGuard {
|
350
350
|
vector<HandlerPtr> &handlers;
|
351
351
|
CommonClientContext &commonContext;
|
352
352
|
vector<ClientContextPtr> &handlerSpecificContexts;
|
353
|
-
|
353
|
+
|
354
354
|
DisconnectEventBroadcastGuard(vector<HandlerPtr> &_handlers,
|
355
355
|
CommonClientContext &_commonContext,
|
356
356
|
vector<ClientContextPtr> &_handlerSpecificContexts)
|
@@ -358,7 +358,7 @@ protected:
|
|
358
358
|
commonContext(_commonContext),
|
359
359
|
handlerSpecificContexts(_handlerSpecificContexts)
|
360
360
|
{ }
|
361
|
-
|
361
|
+
|
362
362
|
~DisconnectEventBroadcastGuard() {
|
363
363
|
vector<HandlerPtr>::iterator handler_iter;
|
364
364
|
vector<ClientContextPtr>::iterator context_iter;
|
@@ -370,8 +370,8 @@ protected:
|
|
370
370
|
}
|
371
371
|
}
|
372
372
|
};
|
373
|
-
|
374
|
-
|
373
|
+
|
374
|
+
|
375
375
|
/**
|
376
376
|
* Create a server socket and set it up for listening. This socket will
|
377
377
|
* be world-writable.
|
@@ -383,7 +383,7 @@ protected:
|
|
383
383
|
void startListening() {
|
384
384
|
TRACE_POINT();
|
385
385
|
int ret;
|
386
|
-
|
386
|
+
|
387
387
|
serverFd = createUnixServer(socketFilename.c_str());
|
388
388
|
do {
|
389
389
|
ret = chmod(socketFilename.c_str(),
|
@@ -393,7 +393,7 @@ protected:
|
|
393
393
|
S_IROTH | S_IWOTH | S_IXOTH);
|
394
394
|
} while (ret == -1 && errno == EINTR);
|
395
395
|
}
|
396
|
-
|
396
|
+
|
397
397
|
/**
|
398
398
|
* Authenticate the given client and returns its account information.
|
399
399
|
*
|
@@ -403,10 +403,10 @@ protected:
|
|
403
403
|
string username, password;
|
404
404
|
MemZeroGuard passwordGuard(password);
|
405
405
|
unsigned long long timeout = loginTimeout;
|
406
|
-
|
406
|
+
|
407
407
|
try {
|
408
408
|
writeArrayMessage(client, &timeout, "version", "1", NULL);
|
409
|
-
|
409
|
+
|
410
410
|
try {
|
411
411
|
if (!readScalarMessage(client, username, MESSAGE_SERVER_MAX_USERNAME_SIZE, &timeout)) {
|
412
412
|
return AccountPtr();
|
@@ -415,7 +415,7 @@ protected:
|
|
415
415
|
writeArrayMessage(client, &timeout, "The supplied username is too long.", NULL);
|
416
416
|
return AccountPtr();
|
417
417
|
}
|
418
|
-
|
418
|
+
|
419
419
|
try {
|
420
420
|
if (!readScalarMessage(client, password, MESSAGE_SERVER_MAX_PASSWORD_SIZE, &timeout)) {
|
421
421
|
return AccountPtr();
|
@@ -424,7 +424,7 @@ protected:
|
|
424
424
|
writeArrayMessage(client, &timeout, "The supplied password is too long.", NULL);
|
425
425
|
return AccountPtr();
|
426
426
|
}
|
427
|
-
|
427
|
+
|
428
428
|
AccountPtr account = accountsDatabase->authenticate(username, password);
|
429
429
|
passwordGuard.zeroNow();
|
430
430
|
if (account == NULL) {
|
@@ -441,22 +441,22 @@ protected:
|
|
441
441
|
return AccountPtr();
|
442
442
|
}
|
443
443
|
}
|
444
|
-
|
444
|
+
|
445
445
|
void broadcastNewClientEvent(CommonClientContext &context,
|
446
446
|
vector<ClientContextPtr> &handlerSpecificContexts) {
|
447
447
|
vector<HandlerPtr>::iterator it;
|
448
|
-
|
448
|
+
|
449
449
|
for (it = handlers.begin(); it != handlers.end(); it++) {
|
450
450
|
handlerSpecificContexts.push_back((*it)->newClient(context));
|
451
451
|
}
|
452
452
|
}
|
453
|
-
|
453
|
+
|
454
454
|
bool processMessage(CommonClientContext &commonContext,
|
455
455
|
vector<ClientContextPtr> &handlerSpecificContexts,
|
456
456
|
const vector<string> &args) {
|
457
457
|
vector<HandlerPtr>::iterator handler_iter;
|
458
458
|
vector<ClientContextPtr>::iterator context_iter;
|
459
|
-
|
459
|
+
|
460
460
|
for (handler_iter = handlers.begin(), context_iter = handlerSpecificContexts.begin();
|
461
461
|
handler_iter != handlers.end();
|
462
462
|
handler_iter++, context_iter++) {
|
@@ -466,7 +466,7 @@ protected:
|
|
466
466
|
}
|
467
467
|
return false;
|
468
468
|
}
|
469
|
-
|
469
|
+
|
470
470
|
void processUnknownMessage(CommonClientContext &commonContext, const vector<string> &args) {
|
471
471
|
TRACE_POINT();
|
472
472
|
string name;
|
@@ -478,38 +478,38 @@ protected:
|
|
478
478
|
P_TRACE(2, "A MessageServer client sent an invalid command: "
|
479
479
|
<< name << " (" << args.size() << " elements)");
|
480
480
|
}
|
481
|
-
|
481
|
+
|
482
482
|
/**
|
483
483
|
* The main function for a thread which handles a client.
|
484
484
|
*/
|
485
485
|
void clientHandlingMainLoop(FileDescriptor client) {
|
486
486
|
TRACE_POINT();
|
487
487
|
vector<string> args;
|
488
|
-
|
488
|
+
|
489
489
|
P_TRACE(4, "MessageServer client thread " << (int) client << " started.");
|
490
|
-
|
490
|
+
|
491
491
|
try {
|
492
492
|
AccountPtr account(authenticate(client));
|
493
493
|
if (account == NULL) {
|
494
494
|
P_TRACE(4, "MessageServer client thread " << (int) client << " exited.");
|
495
495
|
return;
|
496
496
|
}
|
497
|
-
|
497
|
+
|
498
498
|
CommonClientContext commonContext(client, account);
|
499
499
|
vector<ClientContextPtr> handlerSpecificContexts;
|
500
500
|
broadcastNewClientEvent(commonContext, handlerSpecificContexts);
|
501
501
|
DisconnectEventBroadcastGuard dguard(handlers, commonContext, handlerSpecificContexts);
|
502
|
-
|
502
|
+
|
503
503
|
while (!this_thread::interruption_requested()) {
|
504
504
|
UPDATE_TRACE_POINT();
|
505
505
|
if (!readArrayMessage(commonContext.fd, args)) {
|
506
506
|
// Client closed connection.
|
507
507
|
break;
|
508
508
|
}
|
509
|
-
|
509
|
+
|
510
510
|
P_TRACE(4, "MessageServer client " << commonContext.name() <<
|
511
511
|
": received message: " << toString(args));
|
512
|
-
|
512
|
+
|
513
513
|
UPDATE_TRACE_POINT();
|
514
514
|
if (!processMessage(commonContext, handlerSpecificContexts, args)) {
|
515
515
|
processUnknownMessage(commonContext, args);
|
@@ -517,7 +517,7 @@ protected:
|
|
517
517
|
}
|
518
518
|
args.clear();
|
519
519
|
}
|
520
|
-
|
520
|
+
|
521
521
|
P_TRACE(4, "MessageServer client thread " << (int) client << " exited.");
|
522
522
|
client.close();
|
523
523
|
} catch (const boost::thread_interrupted &) {
|
@@ -529,7 +529,7 @@ protected:
|
|
529
529
|
<< " backtrace:\n" << e.backtrace());
|
530
530
|
}
|
531
531
|
}
|
532
|
-
|
532
|
+
|
533
533
|
public:
|
534
534
|
/**
|
535
535
|
* Creates a new MessageServer object.
|
@@ -549,17 +549,17 @@ public:
|
|
549
549
|
loginTimeout = 2000000;
|
550
550
|
startListening();
|
551
551
|
}
|
552
|
-
|
552
|
+
|
553
553
|
~MessageServer() {
|
554
554
|
this_thread::disable_syscall_interruption dsi;
|
555
555
|
syscalls::close(serverFd);
|
556
556
|
syscalls::unlink(socketFilename.c_str());
|
557
557
|
}
|
558
|
-
|
558
|
+
|
559
559
|
string getSocketFilename() const {
|
560
560
|
return socketFilename;
|
561
561
|
}
|
562
|
-
|
562
|
+
|
563
563
|
/**
|
564
564
|
* Starts the server main loop. This method will loop forever until some
|
565
565
|
* other thread interrupts the calling thread, or until an exception is raised.
|
@@ -576,17 +576,17 @@ public:
|
|
576
576
|
sockaddr_un addr;
|
577
577
|
socklen_t len = sizeof(addr);
|
578
578
|
FileDescriptor fd;
|
579
|
-
|
579
|
+
|
580
580
|
UPDATE_TRACE_POINT();
|
581
581
|
fd = syscalls::accept(serverFd, (struct sockaddr *) &addr, &len);
|
582
582
|
if (fd == -1) {
|
583
583
|
throw SystemException("Unable to accept a new client", errno);
|
584
584
|
}
|
585
|
-
|
585
|
+
|
586
586
|
UPDATE_TRACE_POINT();
|
587
587
|
this_thread::disable_interruption di;
|
588
588
|
this_thread::disable_syscall_interruption dsi;
|
589
|
-
|
589
|
+
|
590
590
|
boost::function<void ()> func(boost::bind(&MessageServer::clientHandlingMainLoop,
|
591
591
|
this, fd));
|
592
592
|
string name = "MessageServer client thread ";
|
@@ -594,16 +594,16 @@ public:
|
|
594
594
|
threadGroup.create_thread(func, name, CLIENT_THREAD_STACK_SIZE);
|
595
595
|
}
|
596
596
|
}
|
597
|
-
|
597
|
+
|
598
598
|
/**
|
599
599
|
* Registers a new handler.
|
600
|
-
*
|
600
|
+
*
|
601
601
|
* @pre The main loop isn't running.
|
602
602
|
*/
|
603
603
|
void addHandler(HandlerPtr handler) {
|
604
604
|
handlers.push_back(handler);
|
605
605
|
}
|
606
|
-
|
606
|
+
|
607
607
|
/**
|
608
608
|
* Sets the maximum number of microseconds that clients may spend on logging in.
|
609
609
|
* Clients that take longer are disconnected.
|
@@ -37,7 +37,7 @@
|
|
37
37
|
|
38
38
|
|
39
39
|
/**
|
40
|
-
* A random
|
40
|
+
* A random
|
41
41
|
*/
|
42
42
|
namespace Passenger {
|
43
43
|
|
@@ -60,7 +60,7 @@ using namespace oxt;
|
|
60
60
|
class RandomGenerator: public boost::noncopyable {
|
61
61
|
private:
|
62
62
|
FILE *handle;
|
63
|
-
|
63
|
+
|
64
64
|
public:
|
65
65
|
RandomGenerator(bool open = true) {
|
66
66
|
handle = NULL;
|
@@ -68,12 +68,12 @@ public:
|
|
68
68
|
reopen();
|
69
69
|
}
|
70
70
|
}
|
71
|
-
|
71
|
+
|
72
72
|
~RandomGenerator() {
|
73
73
|
this_thread::disable_syscall_interruption dsi;
|
74
74
|
close();
|
75
75
|
}
|
76
|
-
|
76
|
+
|
77
77
|
void reopen() {
|
78
78
|
close();
|
79
79
|
handle = syscalls::fopen("/dev/urandom", "r");
|
@@ -82,14 +82,14 @@ public:
|
|
82
82
|
errno, "/dev/urandom");
|
83
83
|
}
|
84
84
|
}
|
85
|
-
|
85
|
+
|
86
86
|
void close() {
|
87
87
|
if (handle != NULL) {
|
88
88
|
syscalls::fclose(handle);
|
89
89
|
handle = NULL;
|
90
90
|
}
|
91
91
|
}
|
92
|
-
|
92
|
+
|
93
93
|
StaticString generateBytes(void *buf, unsigned int size) {
|
94
94
|
size_t ret = syscalls::fread(buf, 1, size, handle);
|
95
95
|
if (ret != size) {
|
@@ -97,19 +97,19 @@ public:
|
|
97
97
|
}
|
98
98
|
return StaticString((const char *) buf, size);
|
99
99
|
}
|
100
|
-
|
100
|
+
|
101
101
|
string generateByteString(unsigned int size) {
|
102
102
|
string result(size, '\0');
|
103
103
|
generateBytes(&result[0], size);
|
104
104
|
return result;
|
105
105
|
}
|
106
|
-
|
106
|
+
|
107
107
|
string generateHexString(unsigned int size) {
|
108
108
|
string buf(size, '\0');
|
109
109
|
generateBytes(&buf[0], size);
|
110
110
|
return toHex(buf);
|
111
111
|
}
|
112
|
-
|
112
|
+
|
113
113
|
/**
|
114
114
|
* Generates a random string of <em>size</em> bytes which is also
|
115
115
|
* valid ASCII. The result consists only of the characters A-Z,
|
@@ -126,7 +126,7 @@ public:
|
|
126
126
|
generateAsciiString(&result[0], size);
|
127
127
|
return result;
|
128
128
|
}
|
129
|
-
|
129
|
+
|
130
130
|
void generateAsciiString(char *_buf, unsigned int size) {
|
131
131
|
static const char chars[] = {
|
132
132
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
@@ -141,13 +141,13 @@ public:
|
|
141
141
|
buf[i] = chars[buf[i] % sizeof(chars)];
|
142
142
|
}
|
143
143
|
}
|
144
|
-
|
144
|
+
|
145
145
|
int generateInt() {
|
146
146
|
int ret;
|
147
147
|
generateBytes(&ret, sizeof(ret));
|
148
148
|
return ret;
|
149
149
|
}
|
150
|
-
|
150
|
+
|
151
151
|
unsigned int generateUint() {
|
152
152
|
return (unsigned int) generateInt();
|
153
153
|
}
|