Compare commits

...
36 Commits
Author SHA1 Message Date
roberto@sirius e260873338 uWSGI 0.9.5.1 2010-05-19 16:08:29 +02:00
roberto@voldemort a7822742c0 lighttpd PATH_INFO fix 2010-05-18 08:01:32 +02:00
roberto@voldemort f1316ef4bb fix env configuration 2010-05-18 07:34:36 +02:00
roberto@sirius 4106931175 fix getrlimit() 2010-05-18 07:06:07 +02:00
roberto@sirius fb5ba40f0c support for unladen swallow 2010-05-16 12:34:19 +02:00
roberto@sirius 854e51f0ad fix for eval modifier 2010-05-13 13:47:15 +02:00
roberto@sirium 676b43f17d UWSGI_MODIFIER_EVAL and nginx module update 2010-05-13 13:04:37 +02:00
roberto@sirius 48b68e6a92 updated help and version 2010-05-12 16:40:47 +02:00
roberto@sirius 61f33721e1 add --limit-post 2010-05-12 13:13:01 +02:00
roberto@sirius 5c3c46598f --post-buffering, this will help harakiri mode with big uploads 2010-05-12 12:54:49 +02:00
roberto@sirius 4358036f9e add --prio option 2010-05-12 09:10:04 +02:00
roberto@sirius 54d75d92ef fix paste support 2010-05-10 18:04:01 +02:00
roberto@sirius b1ae57c932 applied gentoo fixes 2010-05-10 10:58:52 +02:00
roberto@sirius 2636baa33f added --logto 2010-05-02 12:38:39 +02:00
roberto@sirius 926c739517 0.9.5 2010-05-01 08:24:21 +02:00
roberto@sirius 79fa25c4e0 latest (i hope) pip hack 2010-05-01 08:10:36 +02:00
roberto@sirius 02050675a8 pip hack [5] 2010-05-01 08:06:44 +02:00
roberto@sirius 0d5857a1bc pip hack [4] 2010-05-01 08:04:05 +02:00
roberto@sirius e3a51be1f9 pip hack [3] 2010-05-01 07:58:53 +02:00
roberto@sirius 57cb098a6e move to setuptools 2010-05-01 07:39:56 +02:00
roberto@sirius 5f285eef56 pip hack [2] 2010-05-01 07:29:07 +02:00
roberto@sirius 7d5cf6f318 pip hack 2010-05-01 07:14:14 +02:00
roberto@silente 99d305c7a1 snmp big endian fixes 2010-04-30 16:41:57 +02:00
roberto@sirius b9cc3b6a7d snmp fix 2010-04-30 15:51:32 +02:00
roberto@sirius e1f8c69d3d minor fixes 2010-04-30 15:16:18 +02:00
roberto@sirius 67b6fbd15b admin modifier fix 2010-04-30 14:46:27 +02:00
roberto@sirius 50f407eb9e no_server fix 2010-04-30 14:41:30 +02:00
roberto@freebsd b127699c0a FreeBSD/Dragonfly little fix 2010-04-30 14:12:51 +02:00
roberto@netbsd 4d74fa6759 small netbsd include fix 2010-04-30 16:04:02 +02:00
roberto@sirius 2b9d6cb7c2 uwsgi_log everywhere 2010-04-30 12:28:01 +02:00
roberto@solaris e0b67bba58 uwsgi_log instead of fprintf [1] 2010-04-30 12:22:07 +02:00
roberto@silente 3cdf17df75 strlcopy insted of strcpy 2010-04-30 09:54:25 +02:00
roberto@silente 43c086494b be more verbose on extreme cases 2010-04-30 09:18:53 +02:00
roberto@silente ae26e90b3a OpenBSD ha no RLIMIT_AS and swapcontext(), added an harakiri message to avoid user confusion 2010-04-30 09:01:26 +02:00
roberto@sirius d35a7d8725 updated urack.rb for unbit 2010-04-27 12:47:29 +02:00
roberto@sirius 043e7ddde4 uWSGI 0.9.5-rc2 2010-04-20 10:51:54 +02:00
30 changed files with 1066 additions and 661 deletions
+2
View File
@@ -1,3 +1,5 @@
d3850b52334a91d005b0fe45e1e38ba0997a1fb8 no_server mode
2d8a617299153ed2efa6ecee7920e9d36c29e0f5 0.9.5beta1
04722a2d0121080d14a64df097c278860db5ce8a 0.9.5rc1
820cc64ab296dc4589ef72a33a6b804c22a0430c 0.9.5rc2
b0db39cfad5ac6d4f00bbb3f9c57cf73206e2afb 0.9.5
+49
View File
@@ -1,3 +1,52 @@
*** may 2010 ***
* 0.9.5.1 [20100519] *
- fixed paste support
- added a new modifier (22)
- full support for configuration via environment variables
- nginx_string option in nginx module
- fix for harakiri without master
- backported unladen swallow support for 0.9.6-dev
- fixed address space limit detection via getrlimit()
- http body buffering implementation
- added --prio option (to set priority)
- added --post-limit to limit the size of uploads
- added --logto option to allow udp logging without daemonizing
- applied Gentoo's packagers fixes for build system
* 0.9.5 [20100501] *
- hook based request/modifier management
- plugin support via dlopen
- on-the-fly management flag
- integrated proxy
- logging via udp
- improved spooler for cron-like apps
- async support
- green thread platform (uGreen) on top of teh async mode
- transparent Erlang integration
- embedded snmp agent
- nagios mode
- improved python 3.x support
- improved xml configuration
- new build system
- address space usage limiting
- lot of portability fixes
- lot of optimizations and code refactoring
*** april 2010 ***
* Fourth Maintenance release [20100427] *
- backported non-yielding app optimization from 0.9.5
- backported udp logging from 0.9.5
- backported uwsgi_error() from 0.9.5 (no more dumb perror())
- fix a rare (but possible) segmentation fault
- added --version
- updated apache2 module
*** march 2010 ***
* Third Maintenance release [20100310] *
+2 -2
View File
@@ -42,7 +42,7 @@ int async_wait(int queuefd, void *events, int nevents, int block, int timeout) {
timeout = timeout*1000;
}
//fprintf(stderr,"waiting with timeout %d nevents %d\n", timeout, nevents);
//uwsgi_log("waiting with timeout %d nevents %d\n", timeout, nevents);
ret = epoll_wait(queuefd, (struct epoll_event *) events, nevents, timeout);
if (ret < 0) {
uwsgi_error("epoll_wait()");
@@ -139,7 +139,7 @@ int async_wait(int queuefd, void *events, int nevents, int block, int timeout) {
dv.dp_nfds = nevents;
dv.dp_timeout = timeout;
//fprintf(stderr,"waiting with timeout %d nevents %d\n", timeout, nevents);
//uwsgi_log("waiting with timeout %d nevents %d\n", timeout, nevents);
ret = ioctl(queuefd, DP_POLL, &dv);
if (ret < 0) {
uwsgi_error("ioctl()");
+278 -274
View File
@@ -1,303 +1,307 @@
# Copyright 2009 Unbit S.a.s. <info@unbit.it>
# see the COPYRIGHT file
require 'rubygems'
require 'socket'
require 'rack'
require 'rack/content_length'
require 'rack/rewindable_input'
require 'stringio'
$stdout.sync = true
options = {}
require 'optparse'
options = {
:processes => 1,
:master => false,
:logging => true,
:static => true,
:config => nil,
:cachehack => false
}
opts = OptionParser.new do |opts|
opts.on("-p", "--processes=nproc", Integer, '') { |p| options[:processes] = p }
opts.on("-M", "--master", '') { options[:master] = true }
opts.on("-L", "--no-logging", '') { options[:logging] = false }
opts.on("-S", "--no-static", '') { options[:static] = false }
opts.on("-C", "--cache-hack", '') { options[:cachehack] = true }
opts.parse! ARGV
end
if ARGV[0]
options[:config] = ARGV[0]
end
def human_round(float)
(float * (10 ** 2)).round / (10 ** 2).to_f
end
$domain = ARGV.last.gsub('[','').gsub(']','')
$unbit_log_base = "[uRack/Unbit on #{$domain}]"
$limit_as = human_round(Process.getrlimit(Process::RLIMIT_AS)[1].to_f/1024/1024)
puts "#{$unbit_log_base} process address space limit is #{$limit_as} MB"
$uidsec_size = syscall(357,0,0)
puts "#{$unbit_log_base} need #{$uidsec_size} bytes to store uidsec_struct..."
$uidsec = '1' * $uidsec_size
puts "#{$unbit_log_base} uidsec_struct allocated."
options[:processes] = 1
options[:serve_file] = nil
options[:max_input_size] = 8
options[:unbit_debug] = false
options[:master] = true
options[:gc_freq] = nil
puts "[#{Time.new}] uRack: loading app [#{RAILS_ROOT}]..."
starttime = Time.now
require "config/environment"
require 'socket'
require 'rubygems'
require 'rack'
require 'rack/utils'
require 'rack/content_length'
$requests = 0
$workers = Array.new
module Rack
module Handler
class Unbit
class Tempfile < ::Tempfile
def _close
@tmpfile.close if @tmpfile
@data[1] = nil if @data
@tmpfile = nil
end
end
def self.run(app, options={})
master_pid = Process.pid
options[:processes] ||= 1
class RailsCachingHack
def initialize app
@app = app
end
server = UNIXServer.for_fd(0)
def stripuri(uri)
uri = uri.split('/')
uri.slice!(1)
val = uri.join('/')
end
def call env
env['PATH_INFO'] = stripuri(env['PATH_INFO']) if env['PATH_INFO']
env['REQUEST_URI'] = stripuri(env['REQUEST_URI']) if env['REQUEST_URI']
env['REQUEST_URI'] = '/' if env['REQUEST_URI'] == ''
@app.call env
end
end
$workers = Array.new
module Handler
class Unbit
if options[:master]
$0 = "uRack #{ARGV.last}"
pid = Process.fork
if pid.to_i > 0
puts "[#{Time.new}] uRack: spawned rack worker 1 (pid: #{pid})"
$workers[1] = pid ;
end
end
def self.run(app, options={})
server = UNIXServer.for_fd(0)
# the check on master pid is necessary
# without it the first worker will execute this part
if options[:processes] > 1 and Process.pid == master_pid
for p in 2..options[:processes]
pid = Process.fork
break if pid.to_i == 0
puts "[#{Time.new}] uRack: spawned rack worker #{p} (pid: #{pid})"
$workers[p] = pid ;
end
end
can_spawn = true
if options[:master]
$0 = 'uRack master'
$workers[0] = Process.pid
ulog("master process enabled (pid: #{$workers[0]})")
$workers[1] = Process.fork
if $workers[1].to_i > 0
ulog("spawned worker 1 (pid: #{$workers[1]})")
elsif $workers[1].to_i == 0
$0 = "uRack worker 1"
can_spawn = false
end
else
$0 = 'uRack worker 1'
$workers[0] = nil
$workers[1] = Process.pid
ulog("spawned worker 1 (pid: #{$workers[1]})")
end
# am i the master ?
if options[:master] and Process.pid == master_pid
Signal.trap('TERM') do
puts "[#{Time.new}] uRack: gracefully killing uRack"
for wid in 1..options[:processes]
Process.kill('TERM', $workers[wid]);
end
exit 0;
end
Signal.trap('QUIT') do
puts "[#{Time.new}] uRack: brutally killing uRack"
for wid in 1..options[:processes]
Process.kill('INT', $workers[wid]);
end
exit 0;
end
puts "[#{Time.new}] uRack: the master process manager is alive."
while 1
pid = Process.waitpid
puts "[#{Time.new}] uRack: worker died ! (pid: #{pid})"
newpid = Process.fork
break if newpid.to_i == 0
puts "[#{Time.new}] uRack: respawned rack worker (pid: #{newpid})"
for wid in 1..options[:processes]
if $workers[wid] == pid
$workers[wid] = newpid
break
end
end
end
end
if Process.pid != master_pid
$0 = $0.gsub(/^uRack/,'urack')
Signal.trap("TERM") do
puts "[#{Time.new}] uRack: grecefully killing process #{Process.pid}..."
if $in_request == 0
puts "[#{Time.new}] uRack: goodbye to process #{Process.pid}"
exit 0
end
$manage_next_request = nil
end
Signal.trap('INT') do
puts "[#{Time.new}] uRack: brutally killing process #{Process.pid}..."
exit 0
end
Signal.trap('PIPE') do
puts "[#{Time.new}] uRack: the webserver (or the client) has closed the connection with process #{Process.pid} !!!"
end
end
max_input_size = options[:max_input_size].to_i * 1024
requests = 0
null_post = StringIO.new('')
options[:app_name] ||= Dir.getwd
app = Rack::ContentLength.new(app)
$manage_next_request = true
if options[:gc_freq].to_i > 1
GC.disable
end
while $manage_next_request
$in_request = 0
client = server.accept
$in_request = 1
timed_out = false
ver, size, arg1 = client.recvfrom(4)[0].unpack('CvC')
vars = client.recvfrom(size)[0]
env = Hash.new
i = 0
while i < size
kl = vars[i, 2].unpack('v')[0]
i = i + 2
key = vars[i, kl]
i = i + kl
vl = vars[i, 2].unpack('v')[0]
i = i + 2
value = vars[i, vl]
i = i + vl
env[key] = value
end
rack_input = null_post
env.delete 'CONTENT_LENGTH' if env['CONTENT_LENGTH'] == ''
if env['CONTENT_LENGTH'].to_i > 0
cl = env['CONTENT_LENGTH'].to_i
if cl <= max_input_size
poststr = ''
while poststr.size < cl
poststr = poststr + client.recvfrom(cl-poststr.size)[0] ;
end
rack_input = StringIO.new(poststr)
else
rack_input = Tempfile.new('UnbitRack')
rack_input.chmod(0000)
bytes_read = 0
while bytes_read < cl
buf = client.recvfrom(4096)[0]
rack_input.write(buf)
bytes_read += buf.size
end
rack_input.rewind
end
end
env["SCRIPT_NAME"] = ""
env.update({"rack.version" => [0,1],
"rack.input" => rack_input,
"rack.errors" => $stderr,
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => false,
"rack.url_scheme" => "http"
})
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
begin
#puts env.inspect
$start_of_request = Time.new
status, headers, body = app.call(env)
$speed = Time.new - $start_of_request
client.print "#{env["HTTP_VERSION"]} #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}\r\n"
headers.each {|k,vs|
vs.split("\n").each { |v|
client.print "#{k}: #{v}\r\n"
}
}
client.print "\r\n"
client.flush
body.each {|part|
client.print part
client.flush
}
rescue Errno::EPIPE
puts "[#{Time.new}] uRack: the webserver (or the client) has closed the connection with process #{Process.pid} !!!"
timed_out = true
ensure
if rack_input.respond_to? :unlink
rack_input.unlink
end
unless rack_input.closed?
rack_input.close
end
client.close
requests = requests+1
# logging
$stderr.puts "[#{Time.new}] uRack: [#{options[:app_name]}] req: #{requests} ip: #{env['REMOTE_ADDR']} pid: #{Process.pid} as: #{human_round(syscall(356).to_f/1024/1024)} MB => #{env['REQUEST_METHOD']} #{env['REQUEST_URI']} in #{$speed} secs [#{status}]#{' TIMED OUT !!!' if timed_out}"
if syscall(357, $uidsec, 0) == $uidsec_size
if $uidsec[120..123].unpack('i')[0] > 0
$stderr.puts "[#{Time.new}] uRack: found a memory allocation error for request #{requests} (pid: #{Process.pid}). Better to kill myself..."
$manage_next_request = nil
end
end
$uidsec = '1' * $uidsec_size
if options[:unbit_debug]
current_as = human_round( (syscall(356).to_f/1024/1024) - $last_as )
$stderr.puts "#{$unbit_log_base} resource status after request #{requests}: AS for this request: #{current_as} MB | OBJ for this request: #{ObjectSpace.each_object {} - $last_obj} | OBJ total: #{ObjectSpace.each_object {}}"
$last_as = human_round(syscall(356).to_f/1024/1024) ;
$last_obj = ObjectSpace.each_object {}
end
if options[:gc_freq].to_i > 1
if requests % options[:gc_freq].to_i == 0
$stderr.puts "[#{Time.new}] uRack: [#{options[:app_name]}] calling GC for pid #{Process.pid} after #{requests} requests."
GC.enable ; GC.start ; GC.disable
end
end
end
end
puts "[#{Time.new}] uRack: goodbye to process #{Process.pid}"
if options[:processes] > 1 and can_spawn
for p in 2..options[:processes]
$workers[p] = Process.fork
if $workers[p].to_i == 0
$0 = "uRack worker #{p}"
break
elsif $workers[p].to_i > 0
ulog("spawned worker #{p} (pid: #{$workers[p]})")
end
end
end
# am i the master ?
if options[:master] and Process.pid == $workers[0]
while 1
i_am_a_child = false
pid = Process.waitpid
for wid in 1..options[:processes]
if $workers[wid] == pid
ulog("worker #{wid} died ! (pid: #{pid})")
$workers[wid] = Process.fork
if $workers[wid].to_i == 0
$0 = "uRack worker #{wid}"
i_am_a_child = true
break
elsif $workers[wid].to_i > 0
ulog("respawned worker #{wid} (pid: #{$workers[wid]})")
end
end
end
break if i_am_a_child
end
end
while client = server.accept
serve client, app, options
end
end
def self.serve(client, app, options)
speed = Time.now
head, sender = client.recvfrom(4)
unless head
client.close
return
end
mod1, size, mod2 = head.unpack('CvC')
if size == 0 or size.nil?
client.close
return
end
vars, sender = client.recvfrom(size)
if vars.length != size
client.close
return
end
env = Hash.new
i = 0
while i < size
kl = vars[i, 2].unpack('v')[0]
i = i + 2
key = vars[i, kl]
i = i + kl
vl = vars[i, 2].unpack('v')[0]
i = i + 2
value = vars[i, vl]
i = i + vl
env[key] = value
end
env.delete "HTTP_CONTENT_LENGTH"
env.delete "HTTP_CONTENT_TYPE"
env["SCRIPT_NAME"] = "" if env["SCRIPT_NAME"] == "/"
env["QUERY_STRING"] ||= ""
env["HTTP_VERSION"] ||= env["SERVER_PROTOCOL"]
env["REQUEST_PATH"] ||= "/"
env.delete "PATH_INFO" if env["PATH_INFO"] == ""
env.delete "CONTENT_TYPE" if env["CONTENT_TYPE"] == ""
env.delete "CONTENT_LENGTH" if env["CONTENT_LENGTH"] == ""
if env["CONTENT_LENGTH"].to_i > 4096
rack_input = Rack::RewindableInput::Tempfile.new('Rack_unbit_Input')
rack_input.chmod(0000)
rack_input.set_encoding(Encoding::BINARY) if rack_input.respond_to?(:set_encoding)
rack_input.binmode
rack_input.unlink
remains = env["CONTENT_LENGTH"].to_i
while remains > 0
if remains >= 4096
buf, sender = client.recvfrom(4096)
else
buf, sender = client.recvfrom(remains)
end
rack_input.write( buf )
remains -= buf.length
end
elsif env["CONTENT_LENGTH"].to_i > 0
rack_input = StringIO.new(client.recvfrom(env["CONTENT_LENGTH"].to_i)[0])
else
rack_input = StringIO.new('')
end
rack_input.rewind
env.update({"rack.version" => [1,1],
"rack.input" => rack_input,
"rack.errors" => $stderr,
"rack.multithread" => false,
"rack.multiprocess" => true,
"rack.run_once" => false,
"rack.url_scheme" => ["yes", "on", "1"].include?(env["HTTPS"]) ? "https" : "http"
})
app = Rack::ContentLength.new(app)
disconnected = false
begin
status, headers, body = app.call(env)
begin
send_headers client, env["HTTP_VERSION"] ,status, headers
send_body client, body
ensure
body.close if body.respond_to? :close
end
rescue Errno::EPIPE, Errno::ECONNRESET
disconnected = true
ensure
rack_input.close
client.close
end
$requests = $requests+1
ulog("req: #{$requests} ip: #{env['REMOTE_ADDR']} pid: #{Process.pid} as: #{human_round(syscall(356).to_f/1024/1024)} MB => #{env['REQUEST_METHOD']} #{env['REQUEST_URI']} in #{Time.now-speed} secs [#{status}]#{' DISCONNECTED !!!' if disconnected}") if options[:logging]
end
def self.send_headers(client, protocol, status, headers)
client.print "#{protocol} #{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}\r\n"
headers.each { |k, vs|
vs.split("\n").each { |v|
client.print "#{k}: #{v}\r\n"
}
}
client.print "\r\n"
client.flush
end
def self.send_body(client, body)
body.each { |part|
client.print part
client.flush
}
end
end
end
end
def ulog(message)
$stderr.puts "[#{Time.new}] uRack: #{message}"
end
ulog("starting at #{Dir.getwd}")
limit_as = human_round(Process.getrlimit(Process::RLIMIT_AS)[1].to_f/1024/1024)
ulog("your process address space limit is #{limit_as} MB")
server = Rack::Handler.get('Unbit')
app = Rack::Builder.new {
if options[:serve_file]
puts "[#{Time.new}] uRack: file serving enabled."
use Rails::Rack::Static
starttime = Time.now
app = nil
if options[:config]
cfgfile = File.read(options[:config])
if cfgfile[/^#\\(.*)/]
opts.parse! $1.split(/\s+/)
end
if ActionController.const_defined?(:Dispatcher) && (ActionController::Dispatcher.instance_methods.include?(:call) || ActionController::Dispatcher.instance_methods.include?("call"))
run ActionController::Dispatcher.new
app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app", nil, options[:config]
else
# falling back to rails
if Dir.getwd =~ /\/public\/?$/
require '../config/environment'
else
require 'thin'
run Rack::Adapter::Rails.new(:environment => ENV['RAILS_ENV'])
require 'config/environment'
end
}.to_app
app = Rack::Builder.new {
if options[:cachehack]
use Rack::RailsCachingHack
end
if options[:static]
use Rails::Rack::Static
end
if ActionController.const_defined?(:Dispatcher) && (ActionController::Dispatcher.instance_methods.include?(:call) || ActionController::Dispatcher.instance_methods.include?("call"))
run ActionController::Dispatcher.new
else
require 'thin'
run Rack::Adapter::Rails.new(:environment => ENV['RAILS_ENV'])
end
}
end
$after_spawn_used_as = human_round(syscall(356).to_f/1024/1024)
$stderr.puts "#{$unbit_log_base} now you have #{$limit_as-$after_spawn_used_as} MB of address space available (used #{$after_spawn_used_as}MB after app startup)"
secs = Time.now-starttime
puts "[#{Time.new}] uRack: ready to serve requests after #{secs.to_i} secs (pid: #{Process.pid})"
ulog("your app is ready (in #{Time.now-starttime} seconds).")
$last_as = $after_spawn_used_as ;
$last_obj = ObjectSpace.each_object {}
server.run(app, options)
+3 -3
View File
@@ -1,6 +1,6 @@
Package: uwsgi
Version: 0.9.2
Version: 0.9.5
Maintainer: Unbit
Description: Fast, developer-friendly wsgi server
Architecture: i386
Depends: python2.5, libxml2
Architecture: all
Depends: python, libxml2
+13 -13
View File
@@ -318,7 +318,7 @@ int init_erlang(char *nodename, char *cookie) {
ip = strchr(nodename, '@');
if (ip == NULL) {
fprintf(stderr, "*** invalid erlang node name ***\n");
uwsgi_log( "*** invalid erlang node name ***\n");
return -1;
}
@@ -326,7 +326,7 @@ int init_erlang(char *nodename, char *cookie) {
// get the cookie from the home
cookiehome = getenv("HOME");
if (!cookiehome) {
fprintf(stderr, "unable to get erlang cookie from your home.\n");
uwsgi_log( "unable to get erlang cookie from your home.\n");
return -1;
}
cookiefile = malloc(strlen(cookiehome) + 1 + strlen(".erlang.cookie") + 1);
@@ -346,7 +346,7 @@ int init_erlang(char *nodename, char *cookie) {
memset(cookievalue, 0, 128);
if (read(cookiefd, cookievalue, 127) < 1) {
fprintf(stderr, "invalid cookie found in %s\n", cookiefile);
uwsgi_log( "invalid cookie found in %s\n", cookiefile);
close(cookiefd);
free(cookiefile);
return -1;
@@ -367,7 +367,7 @@ int init_erlang(char *nodename, char *cookie) {
erl_init(NULL, 0);
if (erl_connect_xinit(ip + 1, node, nodename, NULL, cookie, 0) == -1) {
fprintf(stderr, "*** unable to initialize erlang c-node ***\n");
uwsgi_log( "*** unable to initialize erlang c-node ***\n");
return -1;
}
@@ -409,12 +409,12 @@ int init_erlang(char *nodename, char *cookie) {
}
if (erl_publish(ntohs(e_addr.sin_port)) < 0) {
fprintf(stderr, "*** unable to subscribe with EPMD ***\n");
uwsgi_log( "*** unable to subscribe with EPMD ***\n");
close(efd);
return -1;
}
fprintf(stderr, "Erlang C-Node initialized on port %d you can access it with name %s\n", ntohs(e_addr.sin_port), nodename);
uwsgi_log( "Erlang C-Node initialized on port %d you can access it with name %s\n", ntohs(e_addr.sin_port), nodename);
for (uwsgi_function = uwsgi_erlang_methods; uwsgi_function->ml_name != NULL; uwsgi_function++) {
PyObject *func = PyCFunction_New(uwsgi_function, NULL);
@@ -512,7 +512,7 @@ ETERM *py_to_eterm(PyObject * pobj) {
free(eobj3);
}
else {
fprintf(stderr, "UNMANAGED PYTHON TYPE: %s\n", pobj->ob_type->tp_name);
uwsgi_log( "UNMANAGED PYTHON TYPE: %s\n", pobj->ob_type->tp_name);
}
clear:
@@ -560,7 +560,7 @@ PyObject *eterm_to_py(ETERM * obj) {
eobj = PyInt_FromLong(ERL_INT_VALUE(obj));
break;
case ERL_BINARY:
fprintf(stderr, "FOUND A BINARY %.*s\n", ERL_BIN_SIZE(obj), ERL_BIN_PTR(obj));
uwsgi_log( "FOUND A BINARY %.*s\n", ERL_BIN_SIZE(obj), ERL_BIN_PTR(obj));
break;
case ERL_PID:
eobj = PyDict_New();
@@ -581,7 +581,7 @@ PyObject *eterm_to_py(ETERM * obj) {
break;
}
default:
fprintf(stderr, "UNMANAGED ETERM TYPE: %d\n", ERL_TYPE(obj));
uwsgi_log( "UNMANAGED ETERM TYPE: %d\n", ERL_TYPE(obj));
break;
}
@@ -603,13 +603,13 @@ void erlang_loop(struct wsgi_request *wsgi_req) {
PyObject *callable = PyDict_GetItemString(uwsgi.embedded_dict, "erlang_func");
if (!callable) {
PyErr_Print();
fprintf(stderr, "- you have not defined a uwsgi.erlang_func callable, Erlang message manager will be disabled until you define it -\n");
uwsgi_log( "- you have not defined a uwsgi.erlang_func callable, Erlang message manager will be disabled until you define it -\n");
}
PyObject *pargs = PyTuple_New(1);
if (!pargs) {
PyErr_Print();
fprintf(stderr, "- error preparing arg tuple for uwsgi.erlang_func callable, Erlang message manager will be disabled -\n");
uwsgi_log( "- error preparing arg tuple for uwsgi.erlang_func callable, Erlang message manager will be disabled -\n");
}
while (uwsgi.workers[uwsgi.mywid].manage_next_request) {
@@ -632,7 +632,7 @@ void erlang_loop(struct wsgi_request *wsgi_req) {
}
if (!callable) {
fprintf(stderr, "- you still have not defined a uwsgi.erlang_func callable, Erlang message rejected -\n");
uwsgi_log( "- you still have not defined a uwsgi.erlang_func callable, Erlang message rejected -\n");
}
PyObject *zero = eterm_to_py(em.msg);
@@ -694,7 +694,7 @@ static void erlang_log() {
uwsgi.workers[uwsgi.mywid].rss_size = 0;
uwsgi.workers[uwsgi.mywid].vsz_size = 0;
}
fprintf(stderr, "[Erlang worker %d pid %d] request %llu done {rss: %llu vsz: %llu}\n", uwsgi.mywid, uwsgi.mypid, uwsgi.workers[uwsgi.mywid].requests, uwsgi.workers[uwsgi.mywid].rss_size, uwsgi.workers[uwsgi.mywid].vsz_size);
uwsgi_log( "[Erlang worker %d pid %d] request %llu done {rss: %llu vsz: %llu}\n", uwsgi.mywid, uwsgi.mypid, uwsgi.workers[uwsgi.mywid].requests, uwsgi.workers[uwsgi.mywid].rss_size, uwsgi.workers[uwsgi.mywid].vsz_size);
}
#else
+2 -2
View File
@@ -490,7 +490,7 @@ static int uwsgi_create_env(server *srv, handler_ctx *hctx) {
if (hctx->path_info_offset > 1) {
uwsgi_add_var(b, "SCRIPT_NAME", 11, con->uri.path->ptr, hctx->path_info_offset);
if (strlen(con->uri.path->ptr + hctx->path_info_offset) > 0) {
uwsgi_add_var(b, "PATH_INFO", 9, con->request.orig_uri->ptr + hctx->path_info_offset, strlen(con->request.orig_uri->ptr + hctx->path_info_offset));
uwsgi_add_var(b, "PATH_INFO", 9, con->uri.path->ptr + hctx->path_info_offset, strlen(con->uri.path->ptr + hctx->path_info_offset));
}
else {
uwsgi_add_var(b, "PATH_INFO", 9, "/", 1);
@@ -498,7 +498,7 @@ static int uwsgi_create_env(server *srv, handler_ctx *hctx) {
}
else {
uwsgi_add_var(b, "SCRIPT_NAME", 11, "", 0) ;
uwsgi_add_var(b, "PATH_INFO", 9, con->request.orig_uri->ptr, con->request.orig_uri->used-1) ;
uwsgi_add_var(b, "PATH_INFO", 9, con->uri.path->ptr, strlen(con->uri.path->ptr)) ;
}
+37 -15
View File
@@ -12,18 +12,28 @@
#define _FILE_OFFSET_BITS 64
#endif
#if defined(__NetBSD__) || defined(__FreeBSD__) || defined(__DragonFly__)
#include <sys/sysctl.h>
#endif
extern struct uwsgi_server uwsgi;
void log_request(struct wsgi_request *wsgi_req) {
// optimize this (please)
char *time_request;
time_t microseconds, microseconds2;
static char *empty = "";
char *first_part = empty;
int rlen;
int app_req = -1;
char *msg2 = " ";
char *via = msg2;
char mempkt[4096];
char logpkt[4096];
struct iovec logvec[2] ;
int logvecpos = 0 ;
#ifdef UWSGI_SENDFILE
char *msg1 = " via sendfile() ";
@@ -49,20 +59,23 @@ void log_request(struct wsgi_request *wsgi_req) {
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1) {
#ifndef UNBIT
if (uwsgi.synclog) {
snprintf(uwsgi.sync_page, uwsgi.page_size, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", uwsgi.workers[uwsgi.mywid].vsz_size, uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024, uwsgi.workers[uwsgi.mywid].rss_size, uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024);
first_part = uwsgi.sync_page;
}
else {
fprintf(stderr, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ", uwsgi.workers[uwsgi.mywid].vsz_size, uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024, uwsgi.workers[uwsgi.mywid].rss_size, uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024);
}
rlen = snprintf(mempkt, 4096, "{address space usage: %lld bytes/%lluMB} {rss usage: %llu bytes/%lluMB} ",
uwsgi.workers[uwsgi.mywid].vsz_size, uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024,
uwsgi.workers[uwsgi.mywid].rss_size, uwsgi.workers[uwsgi.mywid].rss_size / 1024 / 1024);
#else
fprintf(stderr, "{address space usage: %lld bytes/%lluMB} ", uwsgi.workers[uwsgi.mywid].vsz_size, uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024);
rlen = snprintf(mempkt, 4096, "{address space usage: %lld bytes/%lluMB} ",
uwsgi.workers[uwsgi.mywid].vsz_size, uwsgi.workers[uwsgi.mywid].vsz_size / 1024 / 1024);
#endif
logvec[logvecpos].iov_base = mempkt ;
logvec[logvecpos].iov_len = rlen ;
logvecpos++;
}
fprintf(stderr, "%s[pid: %d|app: %d|req: %d/%llu] %.*s (%.*s) {%d vars in %d bytes} [%.*s] %.*s %.*s => generated %llu bytes in %ld msecs%s(%.*s %d) %d headers in %d bytes (%d async switches on async core %d)\n",
first_part,
rlen = snprintf(logpkt, 4096, "[pid: %d|app: %d|req: %d/%llu] %.*s (%.*s) {%d vars in %d bytes} [%.*s] %.*s %.*s => generated %llu bytes in %ld msecs%s(%.*s %d) %d headers in %d bytes (%d async switches on async core %d)\n",
uwsgi.mypid,
wsgi_req->app_id,
app_req,
@@ -83,6 +96,11 @@ void log_request(struct wsgi_request *wsgi_req) {
wsgi_req->headers_size,
wsgi_req->async_switches, wsgi_req->async_id);
logvec[logvecpos].iov_base = logpkt ;
logvec[logvecpos].iov_len = rlen ;
// do not check for errors
rlen = writev(2, logvec, logvecpos+1);
}
@@ -97,7 +115,7 @@ void get_memusage() {
if (procfile) {
i = fscanf(procfile, "%*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %*s %llu %lld", &uwsgi.workers[uwsgi.mywid].vsz_size, &uwsgi.workers[uwsgi.mywid].rss_size);
if (i != 2) {
fprintf(stderr, "warning: invalid record in /proc/self/stat\n");
uwsgi_log( "warning: invalid record in /proc/self/stat\n");
}
fclose(procfile);
}
@@ -138,12 +156,16 @@ void get_memusage() {
uwsgi.workers[uwsgi.mywid].vsz_size = kproc->ki_size;
uwsgi.workers[uwsgi.mywid].rss_size = kproc->ki_rssize * uwsgi.page_size;
}
#elif defined(__NetBSD__)
#elif defined(__NetBSD__) || defined(__OpenBSD__)
struct kinfo_proc2 *kproc2;
kproc2 = kvm_getproc2(kv, KERN_PROC_PID, uwsgi.mypid, sizeof(struct kinfo_proc2), &cnt);
if (kproc2 && cnt > 0) {
#ifdef __OpenBSD__
uwsgi.workers[uwsgi.mywid].vsz_size = (kproc2->p_vm_dsize + kproc2->p_vm_ssize + kproc2->p_vm_tsize) * uwsgi.page_size;
#else
uwsgi.workers[uwsgi.mywid].vsz_size = kproc2->p_vm_msize * uwsgi.page_size;
#endif
uwsgi.workers[uwsgi.mywid].rss_size = kproc2->p_vm_rssize * uwsgi.page_size;
}
#endif
+23 -1
View File
@@ -48,6 +48,8 @@ typedef struct {
ngx_array_t *uwsgi_lengths;
ngx_array_t *uwsgi_values;
ngx_str_t uwsgi_string ;
u_char modifier1;
u_char modifier2;
@@ -271,6 +273,14 @@ static ngx_command_t ngx_http_uwsgi_commands[] = {
offsetof (ngx_http_uwsgi_loc_conf_t, params_source),
NULL},
{ ngx_string("uwsgi_string"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF |
NGX_CONF_TAKE1,
ngx_conf_set_str_slot,
NGX_HTTP_LOC_CONF_OFFSET,
offsetof(ngx_http_uwsgi_loc_conf_t, uwsgi_string),
NULL },
{ngx_string ("uwsgi_pass_header"),
NGX_HTTP_MAIN_CONF | NGX_HTTP_SRV_CONF | NGX_HTTP_LOC_CONF |
NGX_CONF_FLAG,
@@ -538,13 +548,18 @@ ngx_http_uwsgi_create_request (ngx_http_request_t * r)
}
}
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
uwsgi_pkt_size += uwcf->uwsgi_string.len ;
}
// check here
/* allow custom uwsgi packet
if (uwsgi_pkt_size > 0 && uwsgi_pkt_size < 2) {
ngx_log_error (NGX_LOG_ALERT, r->connection->log, 0,
"uwsgi request is too little: %uz", uwsgi_pkt_size);
return NGX_ERROR;
}
*/
b = ngx_create_temp_buf (r->pool, uwsgi_pkt_size + 4);
if (b == NULL) {
@@ -676,6 +691,11 @@ ngx_http_uwsgi_create_request (ngx_http_request_t * r)
}
if (uwcf->uwsgi_string.data && uwcf->uwsgi_string.len) {
b->last = ngx_copy(b->last, uwcf->uwsgi_string.data, uwcf->uwsgi_string.len);
}
if (uwcf->upstream.pass_request_body) {
body = r->upstream->request_bufs;
r->upstream->request_bufs = cl;
@@ -1381,6 +1401,8 @@ ngx_http_uwsgi_merge_loc_conf (ngx_conf_t * cf, void *parent, void *child)
ngx_conf_merge_value (conf->upstream.intercept_errors,
prev->upstream.intercept_errors, 0);
ngx_conf_merge_str_value(conf->uwsgi_string, prev->uwsgi_string, "");
hash.max_size = 512;
hash.bucket_size = ngx_align (64, ngx_cacheline_size);
hash.name = "uwsgi_hide_headers_hash";
+31 -14
View File
@@ -2,6 +2,20 @@
extern struct uwsgi_server uwsgi;
static size_t get_content_length(char *buf, uint16_t size) {
int i;
size_t val = 0 ;
for(i=0;i<size;i++) {
if (buf[i] >= '0' && buf[i] <= '9') {
val = (val*10) + (buf[i] - '0') ;
continue;
}
break;
}
return val;
}
#ifdef UWSGI_UDP
ssize_t send_udp_message(uint8_t modifier1, char *host, char *message, uint16_t message_size) {
@@ -69,7 +83,7 @@ int uwsgi_enqueue_message(char *host, int port, uint8_t modifier1, uint8_t modif
timeout = 1;
if (size > 0xFFFF) {
fprintf(stderr, "invalid object (marshalled) size\n");
uwsgi_log( "invalid object (marshalled) size\n");
return -1;
}
@@ -127,7 +141,7 @@ PyObject *uwsgi_send_message(const char *host, int port, uint8_t modifier1, uint
timeout = 1;
if (size > 0xFFFF) {
fprintf(stderr, "invalid object (marshalled) size\n");
uwsgi_log( "invalid object (marshalled) size\n");
Py_INCREF(Py_None);
return Py_None;
}
@@ -212,7 +226,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
exit(1);
}
else if (rlen == 0) {
fprintf(stderr, "timeout. skip request\n");
uwsgi_log( "timeout. skip request\n");
close(upoll->fd);
return 0;
}
@@ -226,13 +240,13 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
exit(1);
}
else if (rlen == 0) {
fprintf(stderr, "timeout waiting for header. skip request.\n");
uwsgi_log( "timeout waiting for header. skip request.\n");
close(upoll->fd);
break;
}
rlen = read(upoll->fd, (char *) (uh) + i, 4 - i);
if (rlen <= 0) {
fprintf(stderr, "broken header. skip request.\n");
uwsgi_log( "broken header. skip request.\n");
close(upoll->fd);
break;
}
@@ -243,7 +257,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
}
}
else if (rlen <= 0) {
fprintf(stderr, "invalid request header size: %d...skip\n", rlen);
uwsgi_log( "invalid request header size: %d...skip\n", rlen);
close(upoll->fd);
return 0;
}
@@ -254,12 +268,12 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
/* check for max buffer size */
if (uh->pktsize > uwsgi.buffer_size) {
fprintf(stderr, "invalid request block size: %d...skip\n", uh->pktsize);
uwsgi_log( "invalid request block size: %d...skip\n", uh->pktsize);
close(upoll->fd);
return 0;
}
//fprintf(stderr,"ready for reading %d bytes\n", wsgi_req.size);
//uwsgi_log("ready for reading %d bytes\n", wsgi_req.size);
i = 0;
while (i < uh->pktsize) {
@@ -269,13 +283,13 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header
exit(1);
}
else if (rlen == 0) {
fprintf(stderr, "timeout. skip request. (expecting %d bytes, got %d)\n", uh->pktsize, i);
uwsgi_log( "timeout. skip request. (expecting %d bytes, got %d)\n", uh->pktsize, i);
close(upoll->fd);
break;
}
rlen = read(upoll->fd, buffer + i, uh->pktsize - i);
if (rlen <= 0) {
fprintf(stderr, "broken vars. skip request.\n");
uwsgi_log( "broken vars. skip request.\n");
close(upoll->fd);
break;
}
@@ -312,7 +326,7 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
#endif
/* key cannot be null */
if (!strsize) {
fprintf(stderr, "uwsgi key cannot be null. skip this request.\n");
uwsgi_log( "uwsgi key cannot be null. skip this request.\n");
return -1;
}
@@ -382,22 +396,25 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
wsgi_req->unbit_flags = *(unsigned long long *) ptrbuf;
}
#endif
else if (!strncmp("CONTENT_LENGTH", wsgi_req->hvec[wsgi_req->var_cnt].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len)) {
wsgi_req->post_cl = get_content_length(ptrbuf, strsize);
}
if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) {
wsgi_req->var_cnt++;
}
else {
fprintf(stderr, "max vec size reached. skip this header.\n");
uwsgi_log( "max vec size reached. skip this header.\n");
return -1;
}
// var value
wsgi_req->hvec[wsgi_req->var_cnt].iov_base = ptrbuf;
wsgi_req->hvec[wsgi_req->var_cnt].iov_len = strsize;
//fprintf(stderr,"%.*s = %.*s\n", wsgi_req->hvec[wsgi_req->var_cnt-1].iov_len, wsgi_req->hvec[wsgi_req->var_cnt-1].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len, wsgi_req->hvec[wsgi_req->var_cnt].iov_base);
//uwsgi_log("%.*s = %.*s\n", wsgi_req->hvec[wsgi_req->var_cnt-1].iov_len, wsgi_req->hvec[wsgi_req->var_cnt-1].iov_base, wsgi_req->hvec[wsgi_req->var_cnt].iov_len, wsgi_req->hvec[wsgi_req->var_cnt].iov_base);
if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) {
wsgi_req->var_cnt++;
}
else {
fprintf(stderr, "max vec size reached. skip this header.\n");
uwsgi_log( "max vec size reached. skip this header.\n");
return -1;
}
ptrbuf += strsize;
+12 -12
View File
@@ -139,9 +139,9 @@ void uwsgi_proxy(int proxyfd) {
int next_node = -1;
fprintf(stderr, "spawned uWSGI proxy (pid: %d)\n", getpid());
uwsgi_log( "spawned uWSGI proxy (pid: %d)\n", getpid());
fprintf(stderr, "allocating space for %d concurrent proxy connections\n", max_connections);
uwsgi_log( "allocating space for %d concurrent proxy connections\n", max_connections);
// allocate memory for connections
upcs = malloc(sizeof(struct uwsgi_proxy_connection) * max_connections);
@@ -221,7 +221,7 @@ void uwsgi_proxy(int proxyfd) {
upcs[ev.ASYNC_FD].retry = 0;
next_node = uwsgi_proxy_find_next_node(next_node);
if (next_node == -1) {
fprintf(stderr, "unable to find an available worker in the cluster !\n");
uwsgi_log( "unable to find an available worker in the cluster !\n");
uwsgi_proxy_close(upcs, ev.ASYNC_FD);
continue;
}
@@ -280,7 +280,7 @@ void uwsgi_proxy(int proxyfd) {
}
else {
fprintf(stderr, "!!! something horrible happened to the uWSGI proxy, reloading it !!!\n");
uwsgi_log( "!!! something horrible happened to the uWSGI proxy, reloading it !!!\n");
exit(1);
}
}
@@ -289,7 +289,7 @@ void uwsgi_proxy(int proxyfd) {
if (eevents[i].ASYNC_IS_IN) {
// is this a connected client/worker ?
//fprintf(stderr,"ready %d\n", upcs[eevents[i].data.fd].status);
//uwsgi_log("ready %d\n", upcs[eevents[i].data.fd].status);
if (!upcs[eevents[i].ASYNC_FD].status) {
if (upcs[eevents[i].ASYNC_FD].dest_fd >= 0) {
@@ -323,7 +323,7 @@ void uwsgi_proxy(int proxyfd) {
continue;
}
else {
fprintf(stderr, "UNKNOWN STATUS %d\n", upcs[eevents[i].ASYNC_FD].status);
uwsgi_log( "UNKNOWN STATUS %d\n", upcs[eevents[i].ASYNC_FD].status);
continue;
}
}
@@ -339,9 +339,9 @@ void uwsgi_proxy(int proxyfd) {
}
/* is something bad ? */
if (soopt) {
fprintf(stderr, "connect() %s\n", strerror(soopt));
uwsgi_log( "connect() %s\n", strerror(soopt));
// increase errors on node
fprintf(stderr, "*** marking cluster node %d/%s as failed ***\n", upcs[eevents[i].ASYNC_FD].node, uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].name);
uwsgi_log( "*** marking cluster node %d/%s as failed ***\n", upcs[eevents[i].ASYNC_FD].node, uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].name);
uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].errors++;
uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].status = UWSGI_NODE_FAILED;
uwsgi_proxy_close(upcs, ev.ASYNC_FD);
@@ -372,7 +372,7 @@ void uwsgi_proxy(int proxyfd) {
}
}
else {
fprintf(stderr, "strange event for %d\n", (int) eevents[i].ASYNC_FD);
uwsgi_log( "strange event for %d\n", (int) eevents[i].ASYNC_FD);
}
}
else {
@@ -382,16 +382,16 @@ void uwsgi_proxy(int proxyfd) {
}
/* is something bad ? */
if (soopt) {
fprintf(stderr, "connect() %s\n", strerror(soopt));
uwsgi_log( "connect() %s\n", strerror(soopt));
}
// increase errors on node
fprintf(stderr, "*** marking cluster node %d/%s as failed ***\n", upcs[eevents[i].ASYNC_FD].node, uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].name);
uwsgi_log( "*** marking cluster node %d/%s as failed ***\n", upcs[eevents[i].ASYNC_FD].node, uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].name);
uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].errors++;
uwsgi.shared->nodes[upcs[eevents[i].ASYNC_FD].node].status = UWSGI_NODE_FAILED;
}
else {
fprintf(stderr, "STRANGE EVENT !!! %d %d %d\n", (int) eevents[i].ASYNC_FD, (int) eevents[i].ASYNC_EV, upcs[eevents[i].ASYNC_FD].status);
uwsgi_log( "STRANGE EVENT !!! %d %d %d\n", (int) eevents[i].ASYNC_FD, (int) eevents[i].ASYNC_EV, upcs[eevents[i].ASYNC_FD].status);
}
uwsgi_proxy_close(upcs, eevents[i].ASYNC_FD);
continue;
+3 -1
View File
@@ -103,7 +103,9 @@ clear:
}
if (wsgi_req->async_post && !wsgi_req->fd_closed) {
fclose(wsgi_req->async_post);
wsgi_req->fd_closed = 1 ;
if (!uwsgi->post_buffering || wsgi_req->post_cl <= uwsgi->post_buffering) {
wsgi_req->fd_closed = 1 ;
}
}
Py_XDECREF((PyObject *)wsgi_req->async_placeholder);
clear2:
+8 -4
View File
@@ -3,9 +3,10 @@ import sys
import uwsgiconfig as uc
import shutil
from distutils.core import setup, Distribution
from distutils.command.install import install
from distutils.command.build_ext import build_ext
from setuptools import setup
from setuptools.dist import Distribution
from setuptools.command.install import install
from setuptools.command.build_ext import build_ext
class uWSGIBuilder(build_ext):
@@ -17,6 +18,9 @@ class uWSGIBuilder(build_ext):
class uWSGIInstall(install):
def run(self):
# hack, hack and still hack. We need to find a solution for 0.9.6
if self.record:
record_file = open(self.record,'w')
uc.parse_vars()
uc.build_uwsgi(sys.prefix + '/bin/' + uc.UWSGI_BIN_NAME)
@@ -30,7 +34,7 @@ class uWSGIDistribution(Distribution):
setup(name='uWSGI',
version='0.9.5',
version='0.9.5.1',
description='The uWSGI server',
author='Unbit',
author_email='info@unbit.it',
+1 -1
View File
@@ -1,5 +1,5 @@
def application(env, start_response):
#print env
print env
start_response('200 Ok', [('Content-type', 'text/plain')])
yield "hello world"
yield "hello world2"
+12 -7
View File
@@ -43,17 +43,21 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
uint64_t request_id;
uint64_t version;
// KISS for memory management
if (size > SNMP_WATERMARK)
return;
ptr++;
// check total sequence size
if (*ptr > SNMP_WATERMARK || *ptr < 13)
return;
ptr++;
// check snmp version
if (*ptr != SNMP_INTEGER)
return;
@@ -66,6 +70,7 @@ void manage_snmp(int fd, uint8_t * buffer, int size, struct sockaddr_in *client_
// check for community string (this must be set from the python vm using uwsgi.snmp_community or with --snmp-community arg)
if (*ptr != SNMP_STRING)
return;
@@ -266,7 +271,7 @@ static uint8_t snmp_int_to_snmp(uint64_t snmp_val, uint8_t oid_type, uint8_t * b
uint8_t tlen;
int i, j;
uint8_t *ptr = (uint8_t *) & snmp_val;
uint8_t *ptr = (uint8_t *) &snmp_val;
// check for counter, counter64 or gauge
@@ -334,7 +339,7 @@ PyObject *py_snmp_counter32(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bi:snmp_set_counter32", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bI:snmp_set_counter32", &oid_num, &oid_val)) {
return NULL;
}
@@ -358,7 +363,7 @@ PyObject *py_snmp_counter64(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint64_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bl:snmp_set_counter64", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bK:snmp_set_counter64", &oid_num, &oid_val)) {
return NULL;
}
@@ -382,7 +387,7 @@ PyObject *py_snmp_gauge(PyObject * self, PyObject * args) {
uint8_t oid_num;
uint32_t oid_val = 0;
if (!PyArg_ParseTuple(args, "bi:snmp_set_gauge", &oid_num, &oid_val)) {
if (!PyArg_ParseTuple(args, "bI:snmp_set_gauge", &oid_num, &oid_val)) {
return NULL;
}
@@ -410,11 +415,11 @@ PyObject *py_snmp_community(PyObject * self, PyObject * args) {
}
if (strlen(snmp_community) > 72) {
fprintf(stderr, "*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
uwsgi_log( "*** warning the supplied SNMP community string will be truncated to 72 chars ***\n");
memcpy(uwsgi.shared->snmp_community, snmp_community, 72);
}
else {
strcpy(uwsgi.shared->snmp_community, snmp_community);
strlcpy(uwsgi.shared->snmp_community, snmp_community, 73);
}
Py_INCREF(Py_True);
@@ -440,7 +445,7 @@ void snmp_init() {
Py_DECREF(func);
}
fprintf(stderr, "SNMP python functions initialized.\n");
uwsgi_log( "SNMP python functions initialized.\n");
}
+9 -9
View File
@@ -7,11 +7,11 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
int serverfd;
struct sockaddr_un *uws_addr;
fprintf(stderr, "binding on UNIX socket: %s\n", socket_name);
uwsgi_log( "binding on UNIX socket: %s\n", socket_name);
// leave 1 byte for abstract namespace (108 linux -> 104 bsd/mac)
if (strlen(socket_name) > 102) {
fprintf(stderr, "invalid socket name\n");
uwsgi_log( "invalid socket name\n");
exit(1);
}
@@ -34,11 +34,11 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
}
if (abstract_socket == 1) {
fprintf(stderr, "setting abstract socket mode (warning: only Linux supports this)\n");
uwsgi_log( "setting abstract socket mode (warning: only Linux supports this)\n");
}
uws_addr->sun_family = AF_UNIX;
strcpy(uws_addr->sun_path + abstract_socket, socket_name);
strlcpy(uws_addr->sun_path + abstract_socket, socket_name, 102+1);
if (bind(serverfd, (struct sockaddr *) uws_addr, strlen(socket_name) + abstract_socket + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) {
uwsgi_error("bind()");
@@ -52,7 +52,7 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst
// chmod unix socket for lazy users
if (chmod_socket == 1 && abstract_socket == 0) {
fprintf(stderr, "chmod() socket to 666 for lazy and brave users\n");
uwsgi_log( "chmod() socket to 666 for lazy and brave users\n");
if (chmod(socket_name, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) != 0) {
uwsgi_error("chmod()");
}
@@ -95,7 +95,7 @@ int bind_to_sctp(char *socket_name, int listen_queue, char *sctp_port) {
exit(1);
}
fprintf(stderr, "binding on %d SCTP interfaces on port: %d\n", num_ip, ntohs(uws_addr[0].sin_port));
uwsgi_log( "binding on %d SCTP interfaces on port: %d\n", num_ip, ntohs(uws_addr[0].sin_port));
if (sctp_bindx(serverfd, (struct sockaddr *) uws_addr, num_ip, SCTP_BINDX_ADD_ADDR) != 0) {
@@ -168,7 +168,7 @@ int bind_to_udp(char *socket_name) {
}
#endif
fprintf(stderr, "binding on UDP port: %d\n", ntohs(uws_addr.sin_port));
uwsgi_log( "binding on UDP port: %d\n", ntohs(uws_addr.sin_port));
if (bind(serverfd, (struct sockaddr *) &uws_addr, sizeof(uws_addr)) != 0) {
uwsgi_error("bind()");
@@ -178,7 +178,7 @@ int bind_to_udp(char *socket_name) {
#ifdef UWSGI_MULTICAST
if (uwsgi.multicast_group) {
fprintf(stderr, "joining uWSGI multicast group: %s:%d\n", uwsgi.multicast_group, ntohs(uws_addr.sin_port));
uwsgi_log( "joining uWSGI multicast group: %s:%d\n", uwsgi.multicast_group, ntohs(uws_addr.sin_port));
if (setsockopt(serverfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mc, sizeof(mc))) {
uwsgi_error("setsockopt()");
}
@@ -274,7 +274,7 @@ int bind_to_tcp(char *socket_name, int listen_queue, char *tcp_port) {
}
fprintf(stderr, "binding on TCP port: %d\n", ntohs(uws_addr.sin_port));
uwsgi_log( "binding on TCP port: %d\n", ntohs(uws_addr.sin_port));
if (bind(serverfd, (struct sockaddr *) &uws_addr, sizeof(uws_addr)) != 0) {
uwsgi_error("bind()");
+14 -14
View File
@@ -59,7 +59,7 @@ int spool_request(struct uwsgi_server *uwsgi, char *filename, int rn, char *buff
close(fd);
fprintf(stderr, "written %d bytes to spool file %s.\n", size + 4, filename);
uwsgi_log( "written %d bytes to spool file %s.\n", size + 4, filename);
return 1;
@@ -92,14 +92,14 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
spool_tuple = PyTuple_New(1);
if (!spool_tuple) {
fprintf(stderr, "could not create spooler tuple.\n");
uwsgi_log( "could not create spooler tuple.\n");
exit(1);
}
spool_env = PyDict_New();
if (!spool_env) {
fprintf(stderr, "could not create spooler env.\n");
uwsgi_log( "could not create spooler env.\n");
exit(1);
}
@@ -114,7 +114,7 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
}
// asked by Marco Beri
fprintf(stderr, "lowering spooler priority to %d\n", PRIO_MAX);
uwsgi_log( "lowering spooler priority to %d\n", PRIO_MAX);
setpriority(PRIO_PROCESS, getpid(), PRIO_MAX);
for (;;) {
@@ -133,11 +133,11 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
continue;
}
if (!access(dp->d_name, R_OK | W_OK)) {
fprintf(stderr, "managing spool request %s...\n", dp->d_name);
uwsgi_log( "managing spool request %s...\n", dp->d_name);
spooler_callable = PyDict_GetItemString(uwsgi_module_dict, "spooler");
if (!spooler_callable) {
fprintf(stderr, "you have to define uwsgi.spooler to use the spooler !!!\n");
uwsgi_log( "you have to define uwsgi.spooler to use the spooler !!!\n");
continue;
}
@@ -241,25 +241,25 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) {
spool_result = python_call(spooler_callable, spool_tuple);
if (!spool_result) {
PyErr_Print();
fprintf(stderr, "error detected. spool request canceled.\n");
uwsgi_log( "error detected. spool request canceled.\n");
goto next_spool;
}
if (PyInt_Check(spool_result)) {
if (PyInt_AsLong(spool_result) == 17) {
Py_DECREF(spool_result);
fprintf(stderr, "retry this task later...\n");
uwsgi_log( "retry this task later...\n");
goto retry_later;
}
}
Py_DECREF(spool_result);
fprintf(stderr, "done with task/spool %s\n", dp->d_name);
uwsgi_log( "done with task/spool %s\n", dp->d_name);
next_spool:
if (unlink(dp->d_name)) {
uwsgi_error("unlink");
fprintf(stderr, "something horrible happened to the spooler. Better to kill it.\n");
uwsgi_log( "something horrible happened to the spooler. Better to kill it.\n");
exit(1);
}
retry_later:
@@ -283,7 +283,7 @@ int uwsgi_request_spooler(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_
char spool_filename[1024];
if (uwsgi->spool_dir == NULL) {
fprintf(stderr, "the spooler is inactive !!!...skip\n");
uwsgi_log( "the spooler is inactive !!!...skip\n");
wsgi_req->uh.modifier1 = 255;
wsgi_req->uh.pktsize = 0;
wsgi_req->uh.modifier2 = 0;
@@ -294,18 +294,18 @@ int uwsgi_request_spooler(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_
return -1;
}
fprintf(stderr, "managing spool request...\n");
uwsgi_log( "managing spool request...\n");
i = spool_request(uwsgi, spool_filename, uwsgi->workers[0].requests + 1, wsgi_req->buffer, wsgi_req->uh.pktsize);
wsgi_req->uh.modifier1 = 255;
wsgi_req->uh.pktsize = 0;
if (i > 0) {
wsgi_req->uh.modifier2 = 1;
if (write(wsgi_req->poll.fd, wsgi_req, 4) != 4) {
fprintf(stderr, "disconnected client, remove spool file.\n");
uwsgi_log( "disconnected client, remove spool file.\n");
/* client disconnect, remove spool file */
if (unlink(spool_filename)) {
uwsgi_error("unlink()");
fprintf(stderr, "something horrible happened !!! check your spooler ASAP !!!\n");
uwsgi_log( "something horrible happened !!! check your spooler ASAP !!!\n");
goodbye_cruel_world();
}
}
+7 -7
View File
@@ -25,7 +25,7 @@ PyObject *py_uwsgi_stackless_worker(PyObject * self, PyObject * args) {
int async_id = wsgi_req->async_id;
//fprintf(stderr,"i am the tasklet worker\n");
//uwsgi_log("i am the tasklet worker\n");
for(;;) {
@@ -74,7 +74,7 @@ void stackless_init(struct uwsgi_server *uwsgi) {
memset(uwsgi->stackless_table[i], 0, sizeof(struct stackless_req));
}
fprintf(stderr,"initializing %d tasklet...", uwsgi->async);
uwsgi_log("initializing %d tasklet...", uwsgi->async);
// creating uwsgi->async tasklets
for(i=0;i<uwsgi->async;i++) {
@@ -90,7 +90,7 @@ void stackless_init(struct uwsgi_server *uwsgi) {
wsgi_req = next_wsgi_req(uwsgi, wsgi_req) ;
}
fprintf(stderr,"done\n");
uwsgi_log("done\n");
}
void stackless_loop(struct uwsgi_server *uwsgi) {
@@ -114,7 +114,7 @@ void stackless_loop(struct uwsgi_server *uwsgi) {
if (uwsgi->async_events[i].ASYNC_FD == uwsgi->serverfd) {
//pass the connection to the first available tasklet
fprintf(stderr,"sending new connection...\n");
uwsgi_log("sending new connection...\n");
PyChannel_Send(uwsgi->workers_channel, Py_True);
}
@@ -130,11 +130,11 @@ void stackless_loop(struct uwsgi_server *uwsgi) {
//int_tasklet = (PyTaskletObject *) PyStackless_RunWatchdog( 1000 );
/*
fprintf(stderr,"done watchdog %p\n", int_tasklet);
uwsgi_log("done watchdog %p\n", int_tasklet);
if (!PyTasklet_IsCurrent(int_tasklet)) {
fprintf(stderr,"re-insert: %d\n", 1);// PyTasklet_Insert(int_tasklet));
uwsgi_log("re-insert: %d\n", 1);// PyTasklet_Insert(int_tasklet));
}
fprintf(stderr,"recycle\n");
uwsgi_log("recycle\n");
*/
}
+1 -1
View File
@@ -2,5 +2,5 @@ import time
def application(env, start_response):
start_response( '200 OK', [ ('Content-Type','text/html') ])
for i in range(1,100000):
for i in range(1,1000):
yield "<h1>%s at %s</h1>" % (i, str(time.time()))
+1 -1
View File
@@ -296,7 +296,7 @@ void u_green_init(struct uwsgi_server *uwsgi) {
u_stack_size = uwsgi->ugreen_stackpages * uwsgi->page_size ;
}
fprintf(stderr,"initializing %d uGreen threads with stack size of %lu (%lu KB)\n", uwsgi->async, (unsigned long) u_stack_size, (unsigned long) u_stack_size/1024);
uwsgi_log("initializing %d uGreen threads with stack size of %lu (%lu KB)\n", uwsgi->async, (unsigned long) u_stack_size, (unsigned long) u_stack_size/1024);
uwsgi->ugreen_contexts = malloc( sizeof(ucontext_t*) * uwsgi->async);
+33
View File
@@ -0,0 +1,33 @@
import uwsgi
def ciao():
uwsgi.start_response('200 OK', [ ('Content-type', 'text/plain') ])
uwsgi.send(str(22+30))
def application(env, start_response):
start_response('200 Ok', [('Content-type', 'text/html')])
if env['REQUEST_METHOD'] == 'POST':
print "getting file..."
remains = int(env['CONTENT_LENGTH'])
print remains
buf = ''
while remains > 0:
if remains < 8192:
buf = env['wsgi.input'].read(remains)
else:
buf = env['wsgi.input'].read(8192)
#print len(buf)
remains = remains - len(buf)
#print "remains",remains
print "upload ready"
yield env['CONTENT_LENGTH']
else:
yield """
<form method="POST" enctype="multipart/form-data">
<input type="file" name="file" />
<input type="submit" value="invia" />
</form>
"""
+98 -33
View File
@@ -7,10 +7,37 @@ extern struct uwsgi_server uwsgi;
uint16_t uwsgi_swap16(uint16_t x) {
return (uint16_t) ((x & 0xff) << 8 | (x & 0xff00) >> 8);
}
uint32_t uwsgi_swap32(uint32_t x) {
x = ( (x<<8) & 0xFF00FF00 ) | ( (x>>8) & 0x00FF00FF );
return (x>>16) | (x<<16);
}
// thanks to ffmpeg project for this idea :P
uint64_t uwsgi_swap64(uint64_t x) {
union {
uint64_t ll;
uint32_t l[2];
} w, r;
w.ll = x;
r.l[0] = uwsgi_swap32(w.l[1]);
r.l[1] = uwsgi_swap32(w.l[0]);
return r.ll;
}
#endif
void inc_harakiri(int sec) {
if (uwsgi.master_process) {
uwsgi.workers[uwsgi.mywid].harakiri += sec;
}
else {
alarm(uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] + sec);
}
}
void set_harakiri(int sec) {
if (uwsgi.workers) {
if (uwsgi.master_process) {
if (sec == 0) {
uwsgi.workers[uwsgi.mywid].harakiri = 0;
}
@@ -27,12 +54,8 @@ void set_harakiri(int sec) {
void daemonize(char *logfile) {
pid_t pid;
int fd, fdin;
int fdin;
#ifdef UWSGI_UDP
char *udp_port;
struct sockaddr_in udp_addr;
#endif
@@ -76,13 +99,30 @@ void daemonize(char *logfile) {
exit(1);
}
/* stdin */
if (dup2(fdin, 0) < 0) {
uwsgi_error("dup2()");
exit(1);
}
logto(logfile);
}
void logto(char *logfile) {
int fd ;
#ifdef UWSGI_UDP
char *udp_port;
struct sockaddr_in udp_addr;
udp_port = strchr(logfile, ':');
if (udp_port) {
udp_port[0] = 0 ;
if ( !udp_port[1] || !logfile[0] ) {
fprintf(stderr,"invalid udp address\n");
uwsgi_log("invalid udp address\n");
exit(1);
}
@@ -114,12 +154,6 @@ void daemonize(char *logfile) {
}
#endif
/* stdin */
if (dup2(fdin, 0) < 0) {
uwsgi_error("dup2()");
exit(1);
}
/* stdout */
if (dup2(fd, 1) < 0) {
@@ -134,8 +168,6 @@ void daemonize(char *logfile) {
}
close(fd);
}
@@ -154,7 +186,7 @@ char *uwsgi_get_cwd() {
if (getcwd(cwd, newsize) == NULL) {
newsize = errno;
fprintf(stderr, "need a bigger buffer (%d bytes) for getcwd(). doing reallocation.\n", newsize);
uwsgi_log("need a bigger buffer (%d bytes) for getcwd(). doing reallocation.\n", newsize);
free(cwd);
cwd = malloc(newsize);
if (cwd == NULL) {
@@ -190,28 +222,28 @@ void internal_server_error(int fd, char *message) {
void uwsgi_as_root() {
if (!getuid()) {
fprintf(stderr, "uWSGI running as root, you can use --uid/--gid/--chroot options\n");
uwsgi_log("uWSGI running as root, you can use --uid/--gid/--chroot options\n");
if (uwsgi.chroot) {
fprintf(stderr, "chroot() to %s\n", uwsgi.chroot);
uwsgi_log("chroot() to %s\n", uwsgi.chroot);
if (chroot(uwsgi.chroot)) {
uwsgi_error("chroot()");
exit(1);
}
#ifdef __linux__
if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) {
fprintf(stderr, "*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
uwsgi_log("*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n");
}
#endif
}
if (uwsgi.gid) {
fprintf(stderr, "setgid() to %d\n", uwsgi.gid);
uwsgi_log("setgid() to %d\n", uwsgi.gid);
if (setgid(uwsgi.gid)) {
uwsgi_error("setgid()");
exit(1);
}
}
if (uwsgi.uid) {
fprintf(stderr, "setuid() to %d\n", uwsgi.uid);
uwsgi_log("setuid() to %d\n", uwsgi.uid);
if (setuid(uwsgi.uid)) {
uwsgi_error("setuid()");
exit(1);
@@ -219,20 +251,20 @@ void uwsgi_as_root() {
}
if (!getuid()) {
fprintf(stderr, " *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** \n");
uwsgi_log(" *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** \n");
}
}
else {
if (uwsgi.chroot) {
fprintf(stderr, "cannot chroot() as non-root user\n");
uwsgi_log("cannot chroot() as non-root user\n");
exit(1);
}
if (uwsgi.gid) {
fprintf(stderr, "cannot setgid() as non-root user\n");
uwsgi_log("cannot setgid() as non-root user\n");
exit(1);
}
if (uwsgi.uid) {
fprintf(stderr, "cannot setuid() as non-root user\n");
uwsgi_log("cannot setuid() as non-root user\n");
exit(1);
}
}
@@ -250,6 +282,7 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
if (uwsgi->shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1)
get_memusage();
// close the connection with the webserver
if (!wsgi_req->fd_closed) {
close(wsgi_req->poll.fd);
@@ -257,12 +290,12 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
uwsgi->workers[0].requests++;
uwsgi->workers[uwsgi->mywid].requests++;
// after_request hook
(*uwsgi->shared->after_hooks[wsgi_req->uh.modifier1]) (uwsgi, wsgi_req);
// leave harakiri mode
if (uwsgi->workers[uwsgi->mywid].harakiri > 0) {
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
set_harakiri(0);
}
@@ -277,6 +310,7 @@ void uwsgi_close_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_r
goodbye_cruel_world();
}
}
void wsgi_req_setup(struct wsgi_request *wsgi_req, int async_id) {
@@ -294,6 +328,10 @@ void wsgi_req_setup(struct wsgi_request *wsgi_req, int async_id) {
wsgi_req->hvec = &uwsgi.async_hvec[wsgi_req->async_id];
wsgi_req->buffer = uwsgi.async_buf[wsgi_req->async_id];
if (uwsgi.post_buffering > 0) {
wsgi_req->post_buffering_buf = uwsgi.async_post_buf[wsgi_req->async_id];
}
}
int wsgi_req_recv(struct wsgi_request *wsgi_req) {
@@ -347,7 +385,7 @@ void sanitize_args(struct uwsgi_server *uwsgi) {
#ifdef UWSGI_PROFILER
if (uwsgi->enable_profiler) {
fprintf(stderr,"*** Profiler enabled, do not use it in production environment !!! ***\n");
uwsgi_log("*** Profiler enabled, do not use it in production environment !!! ***\n");
uwsgi->async = 1;
}
#endif
@@ -356,21 +394,34 @@ void sanitize_args(struct uwsgi_server *uwsgi) {
#ifdef UWSGI_THREADING
if (uwsgi->ugreen) {
if (uwsgi->has_threads) {
fprintf(stderr,"--- python threads will be disabled in uGreen mode ---\n");
uwsgi_log("--- python threads will be disabled in uGreen mode ---\n");
uwsgi->has_threads = 0;
}
}
#endif
#endif
if (uwsgi->wsgi_config) {
uwsgi->single_interpreter = 1 ;
}
}
void env_to_arg(char *src, char *dst) {
int i;
int val = 0 ;
for(i=0;i<strlen(src);i++) {
dst[i] = tolower(src[i]);
if (dst[i] == '_') {
dst[i] = '-';
if (src[i] == '=') {
val = 1 ;
}
if (val) {
dst[i] = src[i];
}
else {
dst[i] = tolower(src[i]);
if (dst[i] == '_') {
dst[i] = '-';
}
}
}
@@ -424,3 +475,17 @@ void parse_sys_envs(char **envs, struct option *long_options) {
}
}
//use this instead of fprintf to avoid buffering mess with udp logging
void uwsgi_log(const char *fmt, ...) {
va_list ap;
char logpkt[4096];
int rlen;
va_start (ap, fmt);
rlen = vsnprintf(logpkt, 4096, fmt, ap );
va_end(ap);
// do not check for errors
rlen = write(2, logpkt, rlen);
}
+205 -178
View File
File diff suppressed because it is too large Load Diff
+42 -5
View File
@@ -2,17 +2,24 @@
/* indent -i8 -br -brs -brf -l0 -npsl -nip -npcs */
#define UWSGI_VERSION "0.9.5-dev"
#define UWSGI_VERSION "0.9.5.1"
#define uwsgi_error(x) fprintf(stderr, "%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#define uwsgi_error(x) uwsgi_log("%s: %s [%s line %d]\n", x, strerror(errno), __FILE__, __LINE__);
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <stdarg.h>
// linux has not strlcpy
#ifdef __linux
#define strlcpy(x, y, z) strcpy(x, y)
#endif
#ifdef UWSGI_SCTP
#include <netinet/sctp.h>
@@ -132,6 +139,11 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define LONG_ARGS_UGREEN_PAGES 17022
#define LONG_ARGS_FILE_CONFIG 17023
#define LONG_ARGS_MULTICAST 17024
#define LONG_ARGS_LOGTO 17025
#define LONG_ARGS_PRIO 17026
#define LONG_ARGS_POST_BUFFERING 17027
#define LONG_ARGS_POST_BUFFERING_SIZE 17028
#define LONG_ARGS_LIMIT_POST 17029
#define UWSGI_OK 0
#define UWSGI_AGAIN 1
@@ -191,6 +203,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t);
#define UWSGI_MODIFIER_ADMIN_REQUEST 10
#define UWSGI_MODIFIER_SPOOL_REQUEST 17
#define UWSGI_MODIFIER_EVAL 22
#define UWSGI_MODIFIER_FASTFUNC 26
#define UWSGI_MODIFIER_MANAGE_PATH_INFO 30
#define UWSGI_MODIFIER_MESSAGE 31
@@ -340,6 +353,10 @@ struct wsgi_request {
int async_plagued;
size_t post_cl;
char *post_buffering_buf;
uint64_t post_buffering_read;
#ifdef UWSGI_STACKLESS
PyTaskletObject* tasklet;
#endif
@@ -376,8 +393,11 @@ struct uwsgi_server {
struct iovec *async_hvec;
char **async_buf;
char **async_post_buf;
struct rlimit rl;
size_t limit_post;
int prio;
char *binary_path;
@@ -417,15 +437,16 @@ struct uwsgi_server {
int buffer_size;
int post_buffering;
int post_buffering_harakiri;
int post_buffering_bufsize;
int master_process;
int no_defer_accept;
int page_size;
char *sync_page;
int synclog;
char *test_module;
char *pidfile;
@@ -622,6 +643,7 @@ int bind_to_sctp(char *, int, char *);
#endif
#ifndef UNBIT
void daemonize(char *);
void logto(char *);
#endif
void log_request(struct wsgi_request *);
void get_memusage(void);
@@ -660,9 +682,12 @@ pid_t spooler_start(int, PyObject *);
#endif
void set_harakiri(int);
void inc_harakiri(int);
#ifdef __BIG_ENDIAN__
uint16_t uwsgi_swap16(uint16_t);
uint32_t uwsgi_swap32(uint32_t);
uint64_t uwsgi_swap64(uint64_t);
#endif
int init_uwsgi_app(PyObject *, PyObject *);
@@ -686,6 +711,7 @@ int uwsgi_request_admin(struct uwsgi_server *, struct wsgi_request *);
#ifdef UWSGI_SPOOLER
int uwsgi_request_spooler(struct uwsgi_server *, struct wsgi_request *);
#endif
int uwsgi_request_eval(struct uwsgi_server *, struct wsgi_request *);
int uwsgi_request_fastfunc(struct uwsgi_server *, struct wsgi_request *);
int uwsgi_request_marshal(struct uwsgi_server *, struct wsgi_request *);
int uwsgi_request_ping(struct uwsgi_server *, struct wsgi_request *);
@@ -724,7 +750,12 @@ struct wsgi_request *find_first_available_wsgi_req(struct uwsgi_server *);
struct wsgi_request *find_wsgi_req_by_fd(struct uwsgi_server *, int, int);
struct wsgi_request *find_wsgi_req_by_id(struct uwsgi_server *, int);
#ifdef __clang__
struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
#else
inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *);
#endif
int async_add(int, int , int) ;
int async_mod(int, int , int) ;
@@ -813,9 +844,15 @@ void u_green_init(struct uwsgi_server *);
void u_green_loop(struct uwsgi_server *);
#endif
#ifdef __clang__
struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
#else
inline struct wsgi_request *current_wsgi_req(struct uwsgi_server *);
#endif
void sanitize_args(struct uwsgi_server *);
void env_to_arg(char *, char *);
void parse_sys_envs(char **, struct option *);
void uwsgi_log(const char *, ...);
+42 -8
View File
@@ -4,13 +4,13 @@
int uwsgi_request_ping(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
char len;
fprintf(stderr, "PING\n");
uwsgi_log( "PING\n");
wsgi_req->uh.modifier2 = 1;
wsgi_req->uh.pktsize = 0;
len = strlen(uwsgi->shared->warning_message);
if (len > 0) {
// endianess check is not needed as the warning message can be max 80 chars
// TODO: check endianess ?
wsgi_req->uh.pktsize = len;
}
if (write(wsgi_req->poll.fd, wsgi_req, 4) != 4) {
@@ -24,7 +24,7 @@ int uwsgi_request_ping(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
}
}
return 0;
return UWSGI_OK;
}
/* uwsgi ADMIN|10 */
@@ -33,19 +33,53 @@ int uwsgi_request_admin(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_re
int i;
if (wsgi_req->uh.pktsize >= 4) {
memcpy(&opt_value, &wsgi_req->buffer, 4);
// TODO: check endianess
memcpy(&opt_value, wsgi_req->buffer, 4);
// TODO: check endianess ?
}
fprintf(stderr, "setting internal option %d to %d\n", wsgi_req->uh.modifier2, opt_value);
uwsgi_log( "setting internal option %d to %d\n", wsgi_req->uh.modifier2, opt_value);
uwsgi->shared->options[wsgi_req->uh.modifier2] = opt_value;
// ACK
wsgi_req->uh.modifier1 = 255;
wsgi_req->uh.pktsize = 0;
wsgi_req->uh.modifier2 = 1;
i = write(wsgi_req->poll.fd, wsgi_req, 4);
if (i != 4) {
uwsgi_error("write()");
}
return UWSGI_OK;
}
int uwsgi_request_eval(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
PyObject *code, *py_dict;
PyObject *m = PyImport_AddModule("__main__");
if (m == NULL) {
PyErr_Print();
return -1;
}
py_dict = PyModule_GetDict(m);
// make it a valid c string
wsgi_req->buffer[wsgi_req->uh.pktsize] = 0 ;
// need to find a way to cache compilations...
code = Py_CompileString(wsgi_req->buffer, "uWSGI", Py_file_input);
if (code == NULL) {
PyErr_Print();
return -1;
}
PyEval_EvalCode((PyCodeObject *)code, py_dict, py_dict );
Py_DECREF(code);
if (PyErr_Occurred()) {
PyErr_Print();
return -1;
}
return UWSGI_OK;
}
@@ -62,7 +96,7 @@ int uwsgi_request_fastfunc(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi
ffunc = PyList_GetItem(uwsgi->fastfuncslist, wsgi_req->uh.modifier2);
if (ffunc) {
fprintf(stderr, "managing fastfunc %d\n", wsgi_req->uh.modifier2);
uwsgi_log( "managing fastfunc %d\n", wsgi_req->uh.modifier2);
return uwsgi_python_call(uwsgi, wsgi_req, ffunc, NULL);
}
@@ -104,7 +138,7 @@ int uwsgi_request_marshal(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_
}
}
else {
fprintf(stderr, "marshalled object is too big. skip\n");
uwsgi_log( "marshalled object is too big. skip\n");
}
Py_DECREF(marshalled);
}
+32 -12
View File
@@ -19,6 +19,25 @@ extern struct uwsgi_server uwsgi;
#define UWSGI_LOGBASE "[- uWSGI -"
PyObject *py_uwsgi_send(PyObject * self, PyObject * args) {
char *data;
if (!PyArg_ParseTuple(args, "s:send", &data)) {
return NULL;
}
if (write(uwsgi.wsgi_req->poll.fd, data, strlen(data)) < 0) {
uwsgi_error("write()");
Py_INCREF(Py_None);
return Py_None;
}
Py_INCREF(Py_True);
return Py_True;
}
#ifdef UWSGI_ASYNC
@@ -51,7 +70,7 @@ PyObject *py_uwsgi_warning(PyObject * self, PyObject * args) {
len = strlen(message);
if (len > 80) {
fprintf(stderr, "- warning message must be max 80 chars, it will be truncated -");
uwsgi_log( "- warning message must be max 80 chars, it will be truncated -");
memcpy(uwsgi.shared->warning_message, message, 80);
uwsgi.shared->warning_message[80] = 0;
}
@@ -74,10 +93,10 @@ PyObject *py_uwsgi_log(PyObject * self, PyObject * args) {
tt = time(NULL);
if (logline[strlen(logline)] != '\n') {
fprintf(stderr, UWSGI_LOGBASE " %.*s] %s\n", 24, ctime(&tt), logline);
uwsgi_log( UWSGI_LOGBASE " %.*s] %s\n", 24, ctime(&tt), logline);
}
else {
fprintf(stderr, UWSGI_LOGBASE " %.*s] %s", 24, ctime(&tt), logline);
uwsgi_log( UWSGI_LOGBASE " %.*s] %s", 24, ctime(&tt), logline);
}
Py_INCREF(Py_True);
@@ -497,7 +516,7 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) {
goto megamulticlear;
}
else if (pret == 0) {
fprintf(stderr, "timeout on multiple send !\n");
uwsgi_log( "timeout on multiple send !\n");
goto megamulticlear;
}
else {
@@ -579,15 +598,15 @@ PyObject *py_uwsgi_load_plugin(PyObject * self, PyObject * args) {
plugin_handle = dlopen(plugin_name, RTLD_NOW | RTLD_GLOBAL);
if (!plugin_handle) {
fprintf(stderr, "%s\n", dlerror());
uwsgi_log( "%s\n", dlerror());
}
else {
plugin_init = dlsym(plugin_handle, "uwsgi_init");
if (plugin_init) {
if ((*plugin_init) (&uwsgi, pargs)) {
fprintf(stderr, "plugin initialization returned error\n");
uwsgi_log( "plugin initialization returned error\n");
if (dlclose(plugin_handle)) {
fprintf(stderr, "unable to unload plugin\n");
uwsgi_log( "unable to unload plugin\n");
}
Py_INCREF(Py_None);
@@ -607,7 +626,7 @@ PyObject *py_uwsgi_load_plugin(PyObject * self, PyObject * args) {
}
else {
fprintf(stderr, "%s\n", dlerror());
uwsgi_log( "%s\n", dlerror());
}
}
@@ -830,7 +849,7 @@ PyObject *py_uwsgi_worker_id(PyObject * self, PyObject * args) {
}
PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) {
fprintf(stderr, "detaching uWSGI from current connection...\n");
uwsgi_log( "detaching uWSGI from current connection...\n");
struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi);
@@ -868,6 +887,7 @@ static PyMethodDef uwsgi_advanced_methods[] = {
{"load_plugin", py_uwsgi_load_plugin, METH_VARARGS, ""},
{"lock", py_uwsgi_lock, METH_VARARGS, ""},
{"unlock", py_uwsgi_unlock, METH_VARARGS, ""},
{"send", py_uwsgi_send, METH_VARARGS, ""},
{"set_warning_message", py_uwsgi_warning, METH_VARARGS, ""},
#ifdef UWSGI_MULTICAST
{"send_multicast_message", py_uwsgi_multicast, METH_VARARGS, ""},
@@ -900,7 +920,7 @@ void init_uwsgi_module_spooler(PyObject * current_uwsgi_module) {
uwsgi_module_dict = PyModule_GetDict(current_uwsgi_module);
if (!uwsgi_module_dict) {
fprintf(stderr, "could not get uwsgi module __dict__\n");
uwsgi_log( "could not get uwsgi module __dict__\n");
exit(1);
}
@@ -925,7 +945,7 @@ void init_uwsgi_module_advanced(PyObject * current_uwsgi_module) {
uwsgi_module_dict = PyModule_GetDict(current_uwsgi_module);
if (!uwsgi_module_dict) {
fprintf(stderr, "could not get uwsgi module __dict__\n");
uwsgi_log( "could not get uwsgi module __dict__\n");
exit(1);
}
@@ -942,7 +962,7 @@ void init_uwsgi_module_sharedarea(PyObject * current_uwsgi_module) {
uwsgi_module_dict = PyModule_GetDict(current_uwsgi_module);
if (!uwsgi_module_dict) {
fprintf(stderr, "could not get uwsgi module __dict__\n");
uwsgi_log( "could not get uwsgi module __dict__\n");
exit(1);
}
+41 -20
View File
@@ -13,14 +13,15 @@ SENDFILE=True
PROFILER=True
NAGIOS=True
PROXY=True
PASTE=True
MINTERPRETERS=True
ASYNC=True
UGREEN=True
STACKLESS=False
PLUGINS = []
USWALLOW=False
UNBIT=False
UWSGI_BIN_NAME = 'uwsgi'
GCC='gcc'
# specific compilation flags
# libxml2 or expat
@@ -46,17 +47,27 @@ import subprocess
from distutils import sysconfig
GCC = os.environ.get('CC', sysconfig.get_config_var('CC'))
if not GCC:
GCC = 'gcc'
gcc_list = ['utils', 'pyutils', 'protocol', 'socket', 'logging', 'wsgi_handlers', 'wsgi_headers', 'uwsgi_handlers', 'uwsgi']
# large file support
try:
cflags = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + sysconfig.get_config_var('CFLAGS').split()
cflags = ['-D_LARGEFILE_SOURCE', '-D_FILE_OFFSET_BITS=64'] + os.environ.get("CFLAGS", "").split()
except:
print("You need python headers to build uWSGI.")
sys.exit(1)
cflags = cflags + ['-I' + sysconfig.get_python_inc(), '-I' + sysconfig.get_python_inc(plat_specific=True) ]
ldflags = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
ldflags = os.environ.get("LDFLAGS", "").split()
libs = ['-lpthread', '-rdynamic'] + sysconfig.get_config_var('LIBS').split() + sysconfig.get_config_var('SYSLIBS').split()
if USWALLOW:
cflags = cflags + sysconfig.get_config_var('LLVM_CXXFLAGS').split()
ldflags = ldflags + sysconfig.get_config_var('LLVM_LDFLAGS').split() + sysconfig.get_config_var('LINKFORSHARED').split()
GCC = 'clang'
def depends_on(what, dep):
for d in dep:
@@ -68,9 +79,9 @@ def spcall(cmd):
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
if p.wait() == 0:
return p.stdout.read().rstrip().decode()
return p.stdout.read().rstrip().decode()
else:
return None
return None
def add_o(x):
if x == 'uwsgi':
@@ -97,7 +108,7 @@ def build_uwsgi(bin_name):
print(plugin)
print("*** uWSGI linking ***")
ldline = "%s -o %s %s %s" % (GCC, bin_name, ' '.join(map(add_o, gcc_list)), ' '.join(ldflags))
ldline = "%s -o %s %s %s %s" % (GCC, bin_name, ' '.join(ldflags), ' '.join(map(add_o, gcc_list)), ' '.join(libs))
print(ldline)
ret = os.system(ldline)
if ret != 0:
@@ -136,22 +147,27 @@ def unbit_setup():
def parse_vars():
global UGREEN
version = sys.version_info
uver = "%d.%d" % (version[0], version[1])
ldflags.append('-lpython' + uver)
libs.append('-lpython' + uver)
if str(PYLIB_PATH) != '':
ldflags.insert(0,'-L' + PYLIB_PATH)
libs.insert(0,'-L' + PYLIB_PATH)
kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly']
if uwsgi_os == 'SunOS':
ldflags.append('-lsendfile')
ldflags.remove('-rdynamic')
libs.append('-lsendfile')
libs.remove('-rdynamic')
if uwsgi_os in kvm_list:
ldflags.append('-lkvm')
libs.append('-lkvm')
if uwsgi_os == 'OpenBSD':
UGREEN = False
if EMBEDDED:
cflags.append('-DUWSGI_EMBEDDED')
@@ -205,6 +221,9 @@ def parse_vars():
if PROFILER:
cflags.append("-DUWSGI_PROFILER")
if PASTE:
cflags.append('-DUWSGI_PASTE')
if SENDFILE:
cflags.append("-DUWSGI_SENDFILE")
gcc_list.append('sendfile')
@@ -216,7 +235,7 @@ def parse_vars():
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
sys.exit(1)
else:
ldflags.append(xmlconf)
libs.append(xmlconf)
xmlconf = spcall("xml2-config --cflags")
if xmlconf is None:
print("*** libxml2 headers unavailable. uWSGI build is interrupted. You have to install libxml2 development package or use libexpat or disable XML")
@@ -227,21 +246,21 @@ def parse_vars():
gcc_list.append('xmlconf')
elif XML_IMPLEMENTATION == 'expat':
cflags.append("-DUWSGI_XML -DUWSGI_XML_EXPAT")
ldflags.append('-lexpat')
libs.append('-lexpat')
gcc_list.append('xmlconf')
if ERLANG:
depends_on("ERLANG", ['EMBEDDED'])
cflags.append("-DUWSGI_ERLANG")
ldflags.append(ERLANG_LDFLAGS)
libs.append(ERLANG_LDFLAGS)
if str(ERLANG_CFLAGS) != '':
cflags.append(ERLANG_CFLAGS)
gcc_list.append('erlang')
if SCTP:
ldflags.append("-lsctp")
cflags.append("-DUWSGI_SCTP")
libs.append("-lsctp")
cflags.append("-DUWSGI_SCTP")
if SPOOLER:
depends_on("SPOOLER", ['EMBEDDED'])
@@ -258,13 +277,13 @@ def build_plugin(path):
import uwsgiplugin as up
cflags.append(up.CFLAGS)
ldflags.append(up.LDFLAGS)
libs.append(up.LDFLAGS)
cflags.insert(0, '-I.')
plugin_base = path + '/' + up.NAME + '_plugin'
gccline = "%s -fPIC -shared -o %s.so %s %s.c %s" % (GCC, plugin_base, ' '.join(cflags), plugin_base, ' '.join(ldflags))
gccline = "%s -fPIC -shared -o %s.so %s %s %s.c %s" % (GCC, plugin_base, ' '.join(cflags), ' '.join(ldflags), plugin_base, ' '.join(libs))
print(gccline)
ret = os.system(gccline)
@@ -289,9 +308,11 @@ if __name__ == "__main__":
sys.exit(1)
if cmd == '--cflags':
print(' '.join(cflags))
print(' '.join(cflags))
if cmd == '--ldflags':
print(' '.join(ldflags))
print(' '.join(ldflags))
if cmd == '--libs':
print(' '.join(libs))
elif cmd == '--build':
parse_vars()
build_uwsgi(UWSGI_BIN_NAME)
+47 -6
View File
@@ -98,15 +98,22 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
/* Standard WSGI request */
if (!wsgi_req->uh.pktsize) {
fprintf(stderr, "Invalid WSGI request. skip.\n");
uwsgi_log( "Invalid WSGI request. skip.\n");
return -1;
}
if (uwsgi_parse_vars(uwsgi, wsgi_req)) {
fprintf(stderr,"Invalid WSGI request. skip.\n");
uwsgi_log("Invalid WSGI request. skip.\n");
return -1;
}
if (uwsgi->limit_post) {
if (wsgi_req->post_cl > uwsgi->limit_post) {
uwsgi_log("Invalid (too big) CONTENT_LENGTH. skip.\n");
return -1;
}
}
#ifdef UWSGI_THREADING
if (uwsgi->has_threads && !uwsgi->workers[uwsgi->mywid].i_have_gil) {
@@ -158,13 +165,13 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
if (wsgi_req->protocol_len < 5) {
fprintf(stderr, "INVALID PROTOCOL: %.*s", wsgi_req->protocol_len, wsgi_req->protocol);
uwsgi_log( "INVALID PROTOCOL: %.*s", wsgi_req->protocol_len, wsgi_req->protocol);
internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!");
goto clear;
}
if (strncmp(wsgi_req->protocol, "HTTP/", 5)) {
fprintf(stderr, "INVALID PROTOCOL: %.*s", wsgi_req->protocol_len, wsgi_req->protocol);
uwsgi_log( "INVALID PROTOCOL: %.*s", wsgi_req->protocol_len, wsgi_req->protocol);
internal_server_error(wsgi_req->poll.fd, "invalid HTTP protocol !!!");
goto clear;
}
@@ -183,7 +190,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
for (i = 0; i < wsgi_req->var_cnt; i += 2) {
//fprintf(stderr,"%.*s: %.*s\n", wsgi_req->hvec[i].iov_len, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i+1].iov_len, wsgi_req->hvec[i+1].iov_base);
//uwsgi_log("%.*s: %.*s\n", wsgi_req->hvec[i].iov_len, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i+1].iov_len, wsgi_req->hvec[i+1].iov_base);
pydictkey = PyString_FromStringAndSize(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len);
pydictvalue = PyString_FromStringAndSize(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len);
PyDict_SetItem(wsgi_req->async_environ, pydictkey, pydictvalue);
@@ -212,7 +219,41 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req
// set wsgi vars
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
if (uwsgi->post_buffering > 0 && wsgi_req->post_cl > uwsgi->post_buffering) {
wsgi_req->async_post = tmpfile();
if (!wsgi_req->async_post) {
uwsgi_error("tmpfile()");
goto clear;
}
size_t post_remains = wsgi_req->post_cl;
ssize_t post_chunk;
while(post_remains > 0) {
if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) {
inc_harakiri(uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]);
}
if (post_remains > uwsgi->post_buffering_bufsize) {
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, uwsgi->post_buffering_bufsize);
}
else {
post_chunk = read(wsgi_req->poll.fd, wsgi_req->post_buffering_buf, post_remains);
}
if (post_chunk < 0) {
uwsgi_error("read()");
goto clear;
}
if (fwrite(wsgi_req->post_buffering_buf, post_chunk, 1, wsgi_req->async_post) <0) {
uwsgi_error("fwrite()");
goto clear;
}
post_remains -= post_chunk;
}
rewind(wsgi_req->async_post);
}
else {
wsgi_req->async_post = fdopen(wsgi_req->poll.fd, "r");
}
wsgi_socket = PyFile_FromFile(wsgi_req->async_post, "wsgi_input", "r", NULL);
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.input", wsgi_socket);
+4 -4
View File
@@ -27,7 +27,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
}
if (!PyString_Check(head)) {
fprintf(stderr, "http status must be a string !\n");
uwsgi_log( "http status must be a string !\n");
goto clear;
}
@@ -94,7 +94,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
goto clear;
}
if (!PyList_Check(headers)) {
fprintf(stderr, "http headers must be in a python list\n");
uwsgi_log( "http headers must be in a python list\n");
goto clear;
}
wsgi_req->header_cnt = PyList_Size(headers);
@@ -111,7 +111,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
goto clear;
}
if (!PyTuple_Check(head)) {
fprintf(stderr, "http header must be defined in a tuple !\n");
uwsgi_log( "http header must be defined in a tuple !\n");
goto clear;
}
h_key = PyTuple_GetItem(head, 0);
@@ -140,7 +140,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) {
#endif
wsgi_req->hvec[j + 3].iov_base = nl;
wsgi_req->hvec[j + 3].iov_len = NL_SIZE;
//fprintf(stderr, "%.*s: %.*s\n", wsgi_req->hvec[j].iov_len, (char *)wsgi_req->hvec[j].iov_base, wsgi_req->hvec[j+2].iov_len, (char *) wsgi_req->hvec[j+2].iov_base);
//uwsgi_log( "%.*s: %.*s\n", wsgi_req->hvec[j].iov_len, (char *)wsgi_req->hvec[j].iov_base, wsgi_req->hvec[j+2].iov_len, (char *) wsgi_req->hvec[j+2].iov_base);
}
+14 -14
View File
@@ -23,21 +23,21 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
doc = xmlReadFile(uwsgi.xml_config, NULL, 0);
if (doc == NULL) {
fprintf(stderr, "[uWSGI] could not parse file %s.\n", uwsgi.xml_config);
uwsgi_log( "[uWSGI] could not parse file %s.\n", uwsgi.xml_config);
exit(1);
}
if (long_options) {
fprintf(stderr, "[uWSGI] parsing config file %s\n", uwsgi.xml_config);
uwsgi_log( "[uWSGI] parsing config file %s\n", uwsgi.xml_config);
}
element = xmlDocGetRootElement(doc);
if (element == NULL) {
fprintf(stderr, "[uWSGI] invalid xml config file.\n");
uwsgi_log( "[uWSGI] invalid xml config file.\n");
exit(1);
}
if (strcmp((char *) element->name, "uwsgi")) {
fprintf(stderr, "[uWSGI] invalid xml root element, <uwsgi> expected.\n");
uwsgi_log( "[uWSGI] invalid xml root element, <uwsgi> expected.\n");
exit(1);
}
@@ -52,13 +52,13 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
break;
if (!strcmp((char *) node->name, aopt->name)) {
if (!node->children && aopt->has_arg) {
fprintf(stderr, "[uWSGI] %s option need a value. skip.\n", aopt->name);
uwsgi_log( "[uWSGI] %s option need a value. skip.\n", aopt->name);
exit(1);
}
if (node->children) {
if (!node->children->content && aopt->has_arg) {
fprintf(stderr, "[uWSGI] %s option need a value. skip.\n", aopt->name);
uwsgi_log( "[uWSGI] %s option need a value. skip.\n", aopt->name);
exit(1);
}
}
@@ -89,7 +89,7 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
if (!strcmp((char *) node->name, "app")) {
xml_uwsgi_mountpoint = xmlGetProp(node, (const xmlChar *) "mountpoint");
if (xml_uwsgi_mountpoint == NULL) {
fprintf(stderr, "no mountpoint defined for app. skip.\n");
uwsgi_log( "no mountpoint defined for app. skip.\n");
continue;
}
wsgi_req->script_name = (char *) xml_uwsgi_mountpoint;
@@ -99,12 +99,12 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
if (node2->type == XML_ELEMENT_NODE) {
if (!strcmp((char *) node2->name, "script")) {
if (!node2->children) {
fprintf(stderr, "no wsgi script defined. skip.\n");
uwsgi_log( "no wsgi script defined. skip.\n");
continue;
}
xml_uwsgi_script = node2->children->content;
if (xml_uwsgi_script == NULL) {
fprintf(stderr, "no wsgi script defined. skip.\n");
uwsgi_log( "no wsgi script defined. skip.\n");
continue;
}
wsgi_req->wsgi_script = (char *) xml_uwsgi_script;
@@ -145,7 +145,7 @@ void uwsgi_endElement(void *userData, const char *name) {
}
else if (current_xmlnode_has_arg) {
if (!current_xmlnode_text_len) {
fprintf(stderr,"option %s requires an argument\n", name);
uwsgi_log("option %s requires an argument\n", name);
exit(1);
}
// HACK: use the first char of closing tag for nulling string
@@ -188,9 +188,9 @@ void uwsgi_startApp(void *userData, const char *name, const char **attrs) {
if (!strcmp(name, "app")) {
current_xmlnode = 0 ;
fprintf(stderr,"%s = %s\n", attrs[0], attrs[1]);
uwsgi_log("%s = %s\n", attrs[0], attrs[1]);
if (strcmp(attrs[0], "mountpoint")) {
fprintf(stderr,"invalid attribute for app tag. must be 'mountpoint'\n");
uwsgi_log("invalid attribute for app tag. must be 'mountpoint'\n");
exit(1);
}
if (attrs[1]) {
@@ -204,7 +204,7 @@ void uwsgi_startApp(void *userData, const char *name, const char **attrs) {
}
else if (!strcmp(name, "script")) {
if (!wsgi_req->script_name_len) {
fprintf(stderr,"you have not specified an app mountpoint.\n");
uwsgi_log("you have not specified an app mountpoint.\n");
exit(1);
}
current_xmlnode = 1 ;
@@ -283,7 +283,7 @@ void uwsgi_xml_config(struct wsgi_request *wsgi_req, struct option *long_options
}
if (!XML_Parse(parser, xmlbuf, stat_buf.st_size, 1)) {
fprintf(stderr, "%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), (int) XML_GetCurrentLineNumber(parser));
uwsgi_log( "%s at line %d\n", XML_ErrorString(XML_GetErrorCode(parser)), (int) XML_GetCurrentLineNumber(parser));
exit(1);
}