1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Late night hackery. Moving code for checking users and groups to common place, letting people who set allow_concurrency shoot themselves in the foot.

git-svn-id: svn+ssh://rubyforge.org/var/svn/mongrel/trunk@225 19e92222-5c0b-0410-8929-a290d50e31e9
This commit is contained in:
zedshaw 2006-06-05 08:54:06 +00:00
parent 05a11e01ba
commit fbf042877d
4 changed files with 55 additions and 49 deletions

View file

@ -57,30 +57,13 @@ class Start < GemPlugin::Plugin "/commands"
valid_user? @user if @user
valid_group? @group if @group
if ActionController::Base.allow_concurrency
STDERR.puts "[RAILS] allow_concurrency is true. Wow, you're very brave."
end
return @valid
end
def valid_user?(user)
valid?(Process.uid == 0, "You must be root to change the user.")
valid?(@group, "You must also specify a group.")
begin
Etc.getpwnam(user)
rescue
failure "User does not exist: #{user}"
@valid = false
end
end
def valid_group?(group)
valid?(Process.uid == 0, "You must be root to change the group.")
valid?(@user, "You must also specify a user.")
begin
Etc.getgrnam(group)
rescue
failure "Group does not exist: #{group}"
@valid = false
end
end
def run

View file

@ -6,4 +6,4 @@ directoryName: Apache
h1. Apache Best Practice Deployment
Coming soon...

View file

@ -126,6 +126,28 @@ module Mongrel
valid?(file != nil && File.directory?(file), message)
end
def valid_user?(user)
valid?(Process.uid == 0, "You must be root to change the user.")
valid?(@group, "You must also specify a group.")
begin
Etc.getpwnam(user)
rescue
failure "User does not exist: #{user}"
@valid = false
end
end
def valid_group?(group)
valid?(Process.uid == 0, "You must be root to change the group.")
valid?(@user, "You must also specify a user.")
begin
Etc.getgrnam(group)
rescue
failure "Group does not exist: #{group}"
@valid = false
end
end
# Just a simple method to display failure until something better is developed.
def failure(message)
STDERR.puts "!!! #{message}"

View file

@ -77,10 +77,9 @@ module Mongrel
cgi = Mongrel::CGIWrapper.new(request, response)
cgi.handler = self
@guard.synchronize do
# Rails is not thread safe so must be run entirely within synchronize
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
end
@guard.lock unless ActionController::Base.allow_concurrency
# Rails is not thread safe so must be run entirely within synchronize
Dispatcher.dispatch(cgi, ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS, response.body)
# This finalizes the output using the proper HttpResponse way
cgi.out {""}
@ -89,6 +88,8 @@ module Mongrel
rescue Object => rails_error
STDERR.puts "Error calling Dispatcher.dispatch #{rails_error.inspect}"
STDERR.puts rails_error.backtrace.join("\n")
ensure
@guard.unlock
end
end
end