Compare commits

...
21 Commits
Author SHA1 Message Date
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
25 changed files with 703 additions and 575 deletions
+1
View File
@@ -1,3 +1,4 @@
d3850b52334a91d005b0fe45e1e38ba0997a1fb8 no_server mode
2d8a617299153ed2efa6ecee7920e9d36c29e0f5 0.9.5beta1
04722a2d0121080d14a64df097c278860db5ce8a 0.9.5rc1
820cc64ab296dc4589ef72a33a6b804c22a0430c 0.9.5rc2
+34
View File
@@ -1,3 +1,37 @@
*** may 2010 ***
* 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
+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
+14 -14
View File
@@ -69,7 +69,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 +127,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 +212,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 +226,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 +243,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 +254,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 +269,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 +312,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;
}
@@ -386,18 +386,18 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req)
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;
+7 -3
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)
+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);
+49 -15
View File
@@ -7,10 +7,28 @@ 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 set_harakiri(int sec) {
if (uwsgi.workers) {
if (uwsgi.master_process) {
if (sec == 0) {
uwsgi.workers[uwsgi.mywid].harakiri = 0;
}
@@ -82,7 +100,7 @@ void daemonize(char *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);
}
@@ -154,7 +172,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 +208,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 +237,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 +268,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,10 +276,10 @@ 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) {
set_harakiri(0);
@@ -277,6 +296,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) {
@@ -347,7 +367,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,7 +376,7 @@ 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;
}
}
@@ -424,3 +444,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);
}
+143 -138
View File
@@ -44,7 +44,7 @@ PyMethodDef uwsgi_sendfile_method[] = {{"uwsgi_sendfile", py_uwsgi_sendfile, MET
int find_worker_id(pid_t pid) {
int i;
for (i = 1; i <= uwsgi.numproc; i++) {
/* fprintf(stderr,"%d of %d\n", pid, uwsgi.workers[i].pid); */
/* uwsgi_log("%d of %d\n", pid, uwsgi.workers[i].pid); */
if (uwsgi.workers[i].pid == pid)
return i;
}
@@ -69,11 +69,11 @@ int check_for_memory_errors = 0;
struct uwsgi_app *wi;
void warn_pipe() {
fprintf(stderr, "writing to a closed pipe/socket/fd !!!\n");
uwsgi_log("SIGPIPE: writing to a closed pipe/socket/fd !!!\n");
}
void gracefully_kill() {
fprintf(stderr, "Gracefully killing worker %d...\n", uwsgi.mypid);
uwsgi_log("Gracefully killing worker %d...\n", uwsgi.mypid);
if (UWSGI_IS_IN_REQUEST) {
uwsgi.workers[uwsgi.mywid].manage_next_request = 0;
}
@@ -91,14 +91,14 @@ void end_me() {
}
void goodbye_cruel_world() {
fprintf(stderr, "...The work of process %d is done. Seeya!\n", getpid());
uwsgi_log("...The work of process %d is done. Seeya!\n", getpid());
exit(0);
}
void kill_them_all() {
int i;
uwsgi.to_hell = 1;
fprintf(stderr, "SIGINT/SIGQUIT received...killing workers...\n");
uwsgi_log("SIGINT/SIGQUIT received...killing workers...\n");
for (i = 1; i <= uwsgi.numproc; i++) {
kill(uwsgi.workers[i].pid, SIGINT);
}
@@ -107,7 +107,7 @@ void kill_them_all() {
void grace_them_all() {
int i;
uwsgi.to_heaven = 1;
fprintf(stderr, "...gracefully killing workers...\n");
uwsgi_log("...gracefully killing workers...\n");
for (i = 1; i <= uwsgi.numproc; i++) {
kill(uwsgi.workers[i].pid, SIGHUP);
}
@@ -115,7 +115,7 @@ void grace_them_all() {
void reap_them_all() {
int i;
fprintf(stderr, "...brutally killing workers...\n");
uwsgi_log("...brutally killing workers...\n");
for (i = 1; i <= uwsgi.numproc; i++) {
kill(uwsgi.workers[i].pid, SIGTERM);
}
@@ -128,7 +128,7 @@ void harakiri() {
PyGILState_Ensure();
_myself = PyThreadState_Get();
if (wi) {
fprintf(stderr, "\nF*CK !!! i must kill myself (pid: %d app_id: %d) wi: %p wi->wsgi_harakiri: %p thread_state: %p frame: %p...\n", uwsgi.mypid, uwsgi.wsgi_req->app_id, wi, wi->wsgi_harakiri, _myself, _myself->frame);
uwsgi_log("\nF*CK !!! i must kill myself (pid: %d app_id: %d) wi: %p wi->wsgi_harakiri: %p thread_state: %p frame: %p...\n", uwsgi.mypid, uwsgi.wsgi_req->app_id, wi, wi->wsgi_harakiri, _myself, _myself->frame);
/*
// NEED TO FIND A SAFER WAY !!!
@@ -140,23 +140,30 @@ void harakiri() {
}
*/
}
else {
uwsgi_log("\nF*CK !!! i must kill myself (pid: %d app_id: %d) thread_state: %p frame: %p...\n", uwsgi.mypid, uwsgi.wsgi_req->app_id, _myself, _myself->frame);
}
uwsgi_log("*** if you want your workers to be automatically respawned consider enabling the uWSGI master process ***\n");
Py_FatalError("HARAKIRI !\n");
}
#ifndef UNBIT
void stats() {
// fix this for better logging (this cause races)
struct uwsgi_app *ua = NULL;
int i;
fprintf(stderr, "*** pid %d stats ***\n", getpid());
fprintf(stderr, "\ttotal requests: %llu\n", uwsgi.workers[0].requests);
uwsgi_log("*** pid %d stats ***\n", getpid());
uwsgi_log("\ttotal requests: %llu\n", uwsgi.workers[0].requests);
for (i = 0; i < uwsgi.wsgi_cnt; i++) {
ua = &uwsgi.wsgi_apps[i];
if (ua) {
fprintf(stderr, "\tapp %d requests: %d\n", i, ua->requests);
uwsgi_log("\tapp %d requests: %d\n", i, ua->requests);
}
}
fprintf(stderr, "\n");
uwsgi_log("\n");
}
#endif
@@ -183,7 +190,7 @@ int single_app_mode = 0;
static int unconfigured_hook(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) {
fprintf(stderr, "-- unavailable modifier requested: %d --\n", wsgi_req->uh.modifier1);
uwsgi_log("-- unavailable modifier requested: %d --\n", wsgi_req->uh.modifier1);
return -1;
}
@@ -259,7 +266,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
memset(uwsgi.shared, 0, sizeof(struct uwsgi_shared));
for (i = 0; i < 0xFF; i++) {
for (i = 0; i <= 0xFF; i++) {
uwsgi.shared->hooks[i] = unconfigured_hook;
uwsgi.shared->after_hooks[i] = unconfigured_after_hook;
}
@@ -325,7 +332,6 @@ int main(int argc, char *argv[], char *envp[]) {
{"pythonpath", required_argument, 0, LONG_ARGS_PYTHONPATH},
{"pyargv", required_argument, 0, LONG_ARGS_PYARGV},
{"paste", required_argument, 0, LONG_ARGS_PASTE},
{"sync-log", no_argument, &uwsgi.synclog, 1},
{"no-server", no_argument, &no_server, 1},
{"no-defer-accept", no_argument, &uwsgi.no_defer_accept, 1},
{"limit-as", required_argument, 0, LONG_ARGS_LIMIT_AS},
@@ -403,7 +409,7 @@ int main(int argc, char *argv[], char *envp[]) {
socket_type_len = sizeof(int);
if (!getsockopt(3, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) {
if (socket_type == SOCK_STREAM && reloads > 0) {
fprintf(stderr, "...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n");
uwsgi_log("...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n");
uwsgi.is_a_reload = 1;
#ifdef UNBIT
/* discard the 3'th fd as we will use the fd 0 */
@@ -487,39 +493,44 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_error("malloc()");
exit(1);
}
strcpy(uwsgi.binary_path, argv[0]);
strlcpy(uwsgi.binary_path, argv[0], strlen(argv[0]) + 1);
}
#ifndef UNBIT
if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) {
#endif
if (uwsgi.test_module == NULL) {
fprintf(stderr, "*** Starting uWSGI %s (%dbit) on [%.*s] ***\n", UWSGI_VERSION, (int) (sizeof(void *)) * 8, 24, ctime((const time_t *) &uwsgi.start_tv.tv_sec));
uwsgi_log("*** Starting uWSGI %s (%dbit) on [%.*s] ***\n", UWSGI_VERSION, (int) (sizeof(void *)) * 8, 24, ctime((const time_t *) &uwsgi.start_tv.tv_sec));
}
#ifndef UNBIT
}
else {
fprintf(stderr, "*** Starting uWSGI %s (CGI mode) (%dbit) on [%.*s] ***\n", UWSGI_VERSION, (int) (sizeof(void *)) * 8, 24, ctime((const time_t *) &uwsgi.start_tv.tv_sec));
uwsgi_log("*** Starting uWSGI %s (CGI mode) (%dbit) on [%.*s] ***\n", UWSGI_VERSION, (int) (sizeof(void *)) * 8, 24, ctime((const time_t *) &uwsgi.start_tv.tv_sec));
}
#endif
#ifdef __BIG_ENDIAN__
fprintf(stderr, "*** big endian arch detected ***\n");
uwsgi_log("*** big endian arch detected ***\n");
#endif
#ifdef PYTHREE
fprintf(stderr, "*** Warning Python3.x support is experimental, do not use it in production environment ***\n");
uwsgi_log("*** Warning Python3.x support is experimental, do not use it in production environment ***\n");
#endif
fprintf(stderr, "Python version: %s\n", Py_GetVersion());
uwsgi_log("Python version: %s\n", Py_GetVersion());
#ifndef UNBIT
uwsgi_as_root();
#endif
if (!uwsgi.master_process) {
uwsgi_log(" *** WARNING: you are running uWSGI without its master process manager ***\n");
}
#ifndef __OpenBSD__
#ifndef UNBIT
if (uwsgi.rl.rlim_max > 0) {
fprintf(stderr, "limiting address space of processes...\n");
uwsgi_log("limiting address space of processes...\n");
if (setrlimit(RLIMIT_AS, &uwsgi.rl)) {
uwsgi_error("setrlimit()");
}
@@ -531,17 +542,18 @@ int main(int argc, char *argv[], char *envp[]) {
// check for overflow
if ((sizeof(void *) == 4 && (uint32_t) uwsgi.rl.rlim_max < UINT32_MAX) || (sizeof(void *) == 8 && (uint64_t) uwsgi.rl.rlim_max < UINT64_MAX)) {
#endif
fprintf(stderr, "your process address space limit is %lld bytes (%lld MB)\n", (long long) uwsgi.rl.rlim_max, (long long) uwsgi.rl.rlim_max / 1024 / 1024);
uwsgi_log("your process address space limit is %lld bytes (%lld MB)\n", (long long) uwsgi.rl.rlim_max, (long long) uwsgi.rl.rlim_max / 1024 / 1024);
#ifndef UNBIT
}
#endif
}
#endif
uwsgi.page_size = getpagesize();
fprintf(stderr, "your memory page size is %d bytes\n", uwsgi.page_size);
uwsgi_log("your memory page size is %d bytes\n", uwsgi.page_size);
if (uwsgi.buffer_size > 65536) {
fprintf(stderr, "invalid buffer size.\n");
uwsgi_log("invalid buffer size.\n");
exit(1);
}
@@ -550,12 +562,12 @@ int main(int argc, char *argv[], char *envp[]) {
if (uwsgi.async > 1) {
if (!getrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
if (uwsgi.rl.rlim_cur < uwsgi.async) {
fprintf(stderr,"- your current max open files limit is %lu, this is lower than requested async cores !!! -\n", (unsigned long) uwsgi.rl.rlim_cur);
uwsgi_log("- your current max open files limit is %lu, this is lower than requested async cores !!! -\n", (unsigned long) uwsgi.rl.rlim_cur);
if (uwsgi.rl.rlim_cur < uwsgi.rl.rlim_max && uwsgi.rl.rlim_max > uwsgi.async) {
unsigned long tmp_nofile = (unsigned long) uwsgi.rl.rlim_cur ;
uwsgi.rl.rlim_cur = uwsgi.async;
if (!setrlimit(RLIMIT_NOFILE, &uwsgi.rl)) {
fprintf(stderr,"max open files limit reset to %lu\n", (unsigned long) uwsgi.rl.rlim_cur);
uwsgi_log("max open files limit reset to %lu\n", (unsigned long) uwsgi.rl.rlim_cur);
uwsgi.async = uwsgi.rl.rlim_cur;
}
else {
@@ -566,7 +578,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.async = uwsgi.rl.rlim_cur;
}
fprintf(stderr,"- async cores set to %d -\n", uwsgi.async);
uwsgi_log("- async cores set to %d -\n", uwsgi.async);
}
}
}
@@ -574,7 +586,7 @@ int main(int argc, char *argv[], char *envp[]) {
// allocate more wsgi_req for async mode
uwsgi.wsgi_requests = malloc(sizeof(struct wsgi_request) * uwsgi.async);
if (uwsgi.wsgi_requests == NULL) {
fprintf(stderr, "unable to allocate memory for requests.\n");
uwsgi_log("unable to allocate memory for requests.\n");
exit(1);
}
memset(uwsgi.wsgi_requests, 0, sizeof(struct wsgi_request) * uwsgi.async);
@@ -597,22 +609,12 @@ int main(int argc, char *argv[], char *envp[]) {
// by default set wsgi_req to the first slot
uwsgi.wsgi_req = uwsgi.wsgi_requests ;
fprintf(stderr, "allocated %llu bytes (%llu KB) for %d request's buffer.\n", (uint64_t) (sizeof(struct wsgi_request) * uwsgi.async),
uwsgi_log("allocated %llu bytes (%llu KB) for %d request's buffer.\n", (uint64_t) (sizeof(struct wsgi_request) * uwsgi.async),
(uint64_t)( (sizeof(struct wsgi_request) * uwsgi.async ) / 1024),
uwsgi.async);
if (uwsgi.synclog) {
fprintf(stderr, "allocating a memory page for synced logging.\n");
uwsgi.sync_page = malloc(uwsgi.page_size);
if (!uwsgi.sync_page) {
uwsgi_error("malloc()");
exit(1);
}
}
if (uwsgi.pyhome != NULL) {
fprintf(stderr, "Setting PythonHome to %s...\n", uwsgi.pyhome);
uwsgi_log("Setting PythonHome to %s...\n", uwsgi.pyhome);
#ifdef PYTHREE
wchar_t *wpyhome;
wpyhome = malloc((sizeof(wchar_t) * strlen(uwsgi.pyhome)) + 2);
@@ -705,26 +707,26 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
#else
fprintf(stderr, "***WARNING*** the sharedarea on OpenBSD is not SMP-safe. Beware of race conditions !!!\n");
uwsgi_log("***WARNING*** the sharedarea on OpenBSD is not SMP-safe. Beware of race conditions !!!\n");
#endif
uwsgi.sharedarea = mmap(NULL, uwsgi.page_size * uwsgi.sharedareasize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0);
if (uwsgi.sharedarea) {
fprintf(stderr, "shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea);
uwsgi_log("shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea);
#ifdef __APPLE__
memset(uwsgi.sharedareamutex, 0, sizeof(OSSpinLock));
#else
#if !defined(__OpenBSD__) && !defined(__NetBSD__)
if (pthread_mutexattr_init((pthread_mutexattr_t *) uwsgi.sharedareamutex)) {
fprintf(stderr, "unable to allocate mutexattr structure\n");
uwsgi_log("unable to allocate mutexattr structure\n");
exit(1);
}
if (pthread_mutexattr_setpshared((pthread_mutexattr_t *) uwsgi.sharedareamutex, PTHREAD_PROCESS_SHARED)) {
fprintf(stderr, "unable to share mutex\n");
uwsgi_log("unable to share mutex\n");
exit(1);
}
if (pthread_mutex_init((pthread_mutex_t *) uwsgi.sharedareamutex + sizeof(pthread_mutexattr_t), (pthread_mutexattr_t *) uwsgi.sharedareamutex)) {
fprintf(stderr, "unable to initialize mutex\n");
uwsgi_log("unable to initialize mutex\n");
exit(1);
}
#endif
@@ -764,7 +766,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_THREADING
if (uwsgi.has_threads) {
PyEval_InitThreads();
fprintf(stderr, "threads support enabled\n");
uwsgi_log("threads support enabled\n");
}
#endif
@@ -782,7 +784,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (uwsgi.serverfd < 0) {
fprintf(stderr, "unable to create the server socket.\n");
uwsgi_log("unable to create the server socket.\n");
exit(1);
}
}
@@ -813,8 +815,8 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (!uwsgi_will_starts) {
fprintf(stderr, "The -s/--socket option is missing and stdin is not a socket.\n");
if (!uwsgi_will_starts && !no_server) {
uwsgi_log( "The -s/--socket option is missing and stdin is not a socket.\n");
exit(1);
}
@@ -838,7 +840,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifndef UNBIT
fprintf(stderr, "your server socket listen backlog is limited to %d connections\n", uwsgi.listen_queue);
uwsgi_log( "your server socket listen backlog is limited to %d connections\n", uwsgi.listen_queue);
#endif
@@ -865,14 +867,14 @@ int main(int argc, char *argv[], char *envp[]) {
#ifndef UNBIT
if (uwsgi.pidfile) {
fprintf(stderr, "writing pidfile to %s\n", uwsgi.pidfile);
uwsgi_log( "writing pidfile to %s\n", uwsgi.pidfile);
pidfile = fopen(uwsgi.pidfile, "w");
if (!pidfile) {
uwsgi_error("fopen");
exit(1);
}
if (fprintf(pidfile, "%d\n", masterpid) < 0) {
fprintf(stderr, "could not write pidfile.\n");
uwsgi_log( "could not write pidfile.\n");
}
fclose(pidfile);
}
@@ -882,7 +884,7 @@ int main(int argc, char *argv[], char *envp[]) {
/* save the masterpid */
uwsgi.workers[0].pid = masterpid;
fprintf(stderr, "initializing hooks...");
uwsgi_log( "initializing hooks...");
uwsgi.shared->hooks[0] = uwsgi_request_wsgi;
uwsgi.shared->after_hooks[0] = uwsgi_after_request_wsgi;
@@ -899,7 +901,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.shared->hooks[UWSGI_MODIFIER_MESSAGE_MARSHAL] = uwsgi_request_marshal; //33
uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping; //100
fprintf(stderr, "done.\n");
uwsgi_log( "done.\n");
#ifdef UWSGI_ERLANG
if (uwsgi.erlang_node) {
@@ -946,7 +948,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifndef UNBIT
if (no_server) {
fprintf(stderr, "no-server mode requested. Goodbye.\n");
uwsgi_log( "no-server mode requested. Goodbye.\n");
exit(0);
}
#endif
@@ -958,16 +960,16 @@ int main(int argc, char *argv[], char *envp[]) {
}
if (!uwsgi.single_interpreter) {
fprintf(stderr, "*** uWSGI is running in multiple interpreter mode !!! ***\n");
uwsgi_log( "*** uWSGI is running in multiple interpreter mode !!! ***\n");
}
/* preforking() */
if (uwsgi.master_process) {
if (uwsgi.is_a_reload) {
fprintf(stderr, "gracefully (RE)spawned uWSGI master process (pid: %d)\n", uwsgi.mypid);
uwsgi_log( "gracefully (RE)spawned uWSGI master process (pid: %d)\n", uwsgi.mypid);
}
else {
fprintf(stderr, "spawned uWSGI master process (pid: %d)\n", uwsgi.mypid);
uwsgi_log( "spawned uWSGI master process (pid: %d)\n", uwsgi.mypid);
}
}
@@ -978,7 +980,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.wsgi_req->wsgi_script_len = strlen(uwsgi.wsgi_req->wsgi_script);
}
else {
fprintf(stderr, "UWSGI_SCRIPT env var not set !\n");
uwsgi_log( "UWSGI_SCRIPT env var not set !\n");
exit(1);
}
@@ -1001,10 +1003,10 @@ int main(int argc, char *argv[], char *envp[]) {
if (!uwsgi.master_process) {
if (uwsgi.numproc == 1) {
fprintf(stderr, "spawned uWSGI worker 1 (and the only) (pid: %d)\n", masterpid);
uwsgi_log( "spawned uWSGI worker 1 (and the only) (pid: %d)\n", masterpid);
}
else {
fprintf(stderr, "spawned uWSGI worker 1 (pid: %d)\n", masterpid);
uwsgi_log( "spawned uWSGI worker 1 (pid: %d)\n", masterpid);
}
uwsgi.workers[1].pid = masterpid;
uwsgi.workers[1].id = 1;
@@ -1043,7 +1045,7 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
else {
fprintf(stderr, "spawned uWSGI worker %d (pid: %d)\n", i, pid);
uwsgi_log( "spawned uWSGI worker %d (pid: %d)\n", i, pid);
gettimeofday(&last_respawn, NULL);
respawn_delta = last_respawn.tv_sec;
}
@@ -1061,14 +1063,15 @@ int main(int argc, char *argv[], char *envp[]) {
signal(SIGUSR1, (void *) &stats);
#endif
#ifdef UWSGI_SNMP
uwsgi.wsgi_req->buffer = uwsgi.async_buf[0];
#ifdef UWSGI_UDP
if (uwsgi.udp_socket) {
uwsgi_poll.fd = bind_to_udp(uwsgi.udp_socket);
if (uwsgi_poll.fd < 0) {
fprintf(stderr, "unable to bind to udp socket. SNMP and cluster management services will be disabled.\n");
uwsgi_log( "unable to bind to udp socket. SNMP and cluster management services will be disabled.\n");
}
else {
fprintf(stderr, "UDP server enabled.\n");
uwsgi_log( "UDP server enabled.\n");
uwsgi_poll.events = POLLIN;
}
}
@@ -1078,19 +1081,19 @@ int main(int argc, char *argv[], char *envp[]) {
if (uwsgi.snmp) {
if (uwsgi.snmp_community) {
if (strlen(uwsgi.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, uwsgi.snmp_community, 72);
}
else {
strcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community);
strlcpy(uwsgi.shared->snmp_community, uwsgi.snmp_community, 73);
}
}
fprintf(stderr, "filling SNMP table...");
uwsgi_log( "filling SNMP table...");
uwsgi.shared->snmp_gvalue[0].type = SNMP_COUNTER64;
uwsgi.shared->snmp_gvalue[0].val = &uwsgi.workers[0].requests;
fprintf(stderr, "done\n");
uwsgi_log( "done\n");
}
#endif
@@ -1107,7 +1110,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_SPOOLER
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
fprintf(stderr, "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
uwsgi_log( "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid);
}
#endif
@@ -1115,31 +1118,31 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_PROXY
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
kill(uwsgi.shared->proxy_pid, SIGKILL);
fprintf(stderr, "killed proxy with pid %d\n", uwsgi.shared->proxy_pid);
uwsgi_log( "killed proxy with pid %d\n", uwsgi.shared->proxy_pid);
}
#endif
fprintf(stderr, "goodbye to uWSGI.\n");
uwsgi_log( "goodbye to uWSGI.\n");
exit(0);
}
if (ready_to_reload >= uwsgi.numproc && uwsgi.to_heaven) {
#ifdef UWSGI_SPOOLER
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
kill(uwsgi.shared->spooler_pid, SIGKILL);
fprintf(stderr, "wait4() the spooler with pid %d...", uwsgi.shared->spooler_pid);
uwsgi_log( "wait4() the spooler with pid %d...", uwsgi.shared->spooler_pid);
diedpid = waitpid(uwsgi.shared->spooler_pid, &waitpid_status, 0);
fprintf(stderr, "done.");
uwsgi_log( "done.");
}
#endif
#ifdef UWSGI_PROXY
if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) {
kill(uwsgi.shared->proxy_pid, SIGKILL);
fprintf(stderr, "wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid);
uwsgi_log( "wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid);
diedpid = waitpid(uwsgi.shared->proxy_pid, &waitpid_status, 0);
fprintf(stderr, "done.");
uwsgi_log( "done.");
}
#endif
fprintf(stderr, "binary reloading uWSGI...\n");
uwsgi_log( "binary reloading uWSGI...\n");
if (cwd) {
if (chdir(cwd)) {
uwsgi_error("chdir()");
@@ -1147,7 +1150,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
/* check fd table (a module can obviosly open some fd on initialization...) */
fprintf(stderr, "closing all fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf(_SC_OPEN_MAX));
uwsgi_log( "closing all fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf(_SC_OPEN_MAX));
for (i = 3; i < sysconf(_SC_OPEN_MAX); i++) {
if (i == uwsgi.serverfd) {
continue;
@@ -1160,7 +1163,7 @@ int main(int argc, char *argv[], char *envp[]) {
exit(1);
}
}
fprintf(stderr, "running %s\n", uwsgi.binary_path);
uwsgi_log( "running %s\n", uwsgi.binary_path);
argv[0] = uwsgi.binary_path;
//strcpy (argv[0], uwsgi.binary_path);
execve(uwsgi.binary_path, argv, environ);
@@ -1193,7 +1196,7 @@ int main(int argc, char *argv[], char *envp[]) {
if (diedpid == -1) {
uwsgi_error("waitpid()");
/* here is better to reload all the uWSGI stack */
fprintf(stderr, "something horrible happened...\n");
uwsgi_log( "something horrible happened...\n");
reap_them_all();
exit(1);
}
@@ -1221,7 +1224,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
else if (rlen > 0) {
udp_len = sizeof(udp_client);
rlen = recvfrom(uwsgi_poll.fd, &uwsgi.wsgi_req->buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len);
rlen = recvfrom(uwsgi_poll.fd, uwsgi.wsgi_req->buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len);
if (rlen < 0) {
uwsgi_error("recvfrom()");
}
@@ -1232,7 +1235,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
#ifdef UWSGI_SNMP
else if (uwsgi.wsgi_req->buffer[0] == 0x30 && uwsgi.snmp) {
manage_snmp(uwsgi_poll.fd, (uint8_t *) &uwsgi.wsgi_req->buffer, rlen, &udp_client);
manage_snmp(uwsgi_poll.fd, (uint8_t *) uwsgi.wsgi_req->buffer, rlen, &udp_client);
}
#endif
else {
@@ -1249,7 +1252,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
else {
// a simple udp logger
fprintf(stderr, "[udp:%s:%d] %.*s", udp_client_addr, ntohs(udp_client.sin_port), rlen, uwsgi.wsgi_req->buffer);
uwsgi_log( "[udp:%s:%d] %.*s", udp_client_addr, ntohs(udp_client.sin_port), rlen, uwsgi.wsgi_req->buffer);
}
}
}
@@ -1281,7 +1284,10 @@ int main(int argc, char *argv[], char *envp[]) {
/* first try to invoke the harakiri() custom handler */
/* TODO */
/* then brutally kill the worker */
uwsgi_log("*** HARAKIRI ON WORKER %d (pid: %d) ***\n", i, uwsgi.workers[i].pid);
kill(uwsgi.workers[i].pid, SIGKILL);
// to avoid races
uwsgi.workers[i].harakiri = 0;
}
}
/* load counters */
@@ -1303,7 +1309,7 @@ int main(int argc, char *argv[], char *envp[]) {
if (master_cycles % ucn->errors == 0) {
if (!uwsgi_ping_node(i, uwsgi.wsgi_req)) {
ucn->status = UWSGI_NODE_OK;
fprintf(stderr, "re-enabled cluster node %d/%s\n", i, ucn->name);
uwsgi_log( "re-enabled cluster node %d/%s\n", i, ucn->name);
}
else {
ucn->errors++;
@@ -1319,7 +1325,7 @@ int main(int argc, char *argv[], char *envp[]) {
/* reload the spooler */
if (uwsgi.spool_dir && uwsgi.shared->spooler_pid > 0) {
if (diedpid == uwsgi.shared->spooler_pid) {
fprintf(stderr, "OOOPS the spooler is no more...trying respawn...\n");
uwsgi_log( "OOOPS the spooler is no more...trying respawn...\n");
uwsgi.shared->spooler_pid = spooler_start(uwsgi.serverfd, uwsgi.embedded_dict);
continue;
}
@@ -1332,7 +1338,7 @@ int main(int argc, char *argv[], char *envp[]) {
if (diedpid == uwsgi.shared->proxy_pid) {
if (WIFEXITED(waitpid_status)) {
if (WEXITSTATUS(waitpid_status) != UWSGI_END_CODE) {
fprintf(stderr, "OOOPS the proxy is no more...trying respawn...\n");
uwsgi_log( "OOOPS the proxy is no more...trying respawn...\n");
uwsgi.shared->spooler_pid = proxy_start(1);
continue;
}
@@ -1352,10 +1358,10 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
fprintf(stderr, "DAMN ! process %d died :( trying respawn ...\n", diedpid);
uwsgi_log( "DAMN ! process %d died :( trying respawn ...\n", diedpid);
gettimeofday(&last_respawn, NULL);
if (last_respawn.tv_sec == respawn_delta) {
fprintf(stderr, "worker respawning too fast !!! i have to sleep a bit...\n");
uwsgi_log( "worker respawning too fast !!! i have to sleep a bit...\n");
/* TODO, user configurable fork throttler */
sleep(2);
}
@@ -1379,7 +1385,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi_error("fork()");
}
else {
fprintf(stderr, "Respawned uWSGI worker (new pid: %d)\n", pid);
uwsgi_log( "Respawned uWSGI worker (new pid: %d)\n", pid);
#ifdef UWSGI_SPOOLER
if (uwsgi.mywid <= 0 && diedpid != uwsgi.shared->spooler_pid) {
#else
@@ -1389,7 +1395,7 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_PROXY
if (diedpid != uwsgi.shared->proxy_pid) {
#endif
fprintf(stderr, "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n");
uwsgi_log( "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n");
#ifdef UWSGI_PROXY
}
#endif
@@ -1413,7 +1419,7 @@ int main(int argc, char *argv[], char *envp[]) {
uwsgi.async_hvec = malloc((sizeof(struct iovec) * uwsgi.vec_size)*uwsgi.async);
if (uwsgi.async_hvec == NULL) {
fprintf(stderr, "unable to allocate memory for iovec.\n");
uwsgi_log( "unable to allocate memory for iovec.\n");
exit(1);
}
@@ -1440,10 +1446,10 @@ int main(int argc, char *argv[], char *envp[]) {
#ifdef UWSGI_ERLANG
if (uwsgi.erlang_nodes > 0) {
if (uwsgi.numproc <= uwsgi.erlang_nodes) {
fprintf(stderr, "You do not have enough worker for Erlang. Please respawn with at least %d processes.\n", uwsgi.erlang_nodes + 1);
uwsgi_log( "You do not have enough worker for Erlang. Please respawn with at least %d processes.\n", uwsgi.erlang_nodes + 1);
}
else if (uwsgi.mywid > (uwsgi.numproc - uwsgi.erlang_nodes)) {
fprintf(stderr, "Erlang mode enabled for worker %d.\n", uwsgi.mywid);
uwsgi_log( "Erlang mode enabled for worker %d.\n", uwsgi.mywid);
erlang_loop(uwsgi.wsgi_req);
// NEVER HERE
exit(1);
@@ -1605,7 +1611,7 @@ void init_uwsgi_vars() {
PyErr_Print();
}
else {
fprintf(stderr, "added %s to pythonpath.\n", uwsgi.python_path[i]);
uwsgi_log( "added %s to pythonpath.\n", uwsgi.python_path[i]);
}
}
#endif
@@ -1630,17 +1636,17 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (uwsgi.wsgi_req->wsgi_script_len == 0 && ((uwsgi.wsgi_req->wsgi_module_len == 0 || uwsgi.wsgi_req->wsgi_callable_len == 0) && uwsgi.wsgi_config == NULL && my_callable == NULL)) {
fprintf(stderr, "invalid application (%.*s). skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
uwsgi_log( "invalid application (%.*s). skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
return -1;
}
if (uwsgi.wsgi_config && uwsgi.wsgi_req->wsgi_callable_len == 0 && my_callable == NULL) {
fprintf(stderr, "invalid application (%.*s). skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
uwsgi_log( "invalid application (%.*s). skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
return -1;
}
if (uwsgi.wsgi_req->wsgi_script_len > 255 || uwsgi.wsgi_req->wsgi_module_len > 255 || uwsgi.wsgi_req->wsgi_callable_len > 255) {
fprintf(stderr, "invalid application's string size. skip.\n");
uwsgi_log( "invalid application's string size. skip.\n");
return -1;
}
@@ -1666,7 +1672,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (PyDict_GetItem(uwsgi.py_apps, zero) != NULL) {
Py_DECREF(zero);
fprintf(stderr, "mountpoint %.*s already configured. skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
uwsgi_log( "mountpoint %.*s already configured. skip.\n", uwsgi.wsgi_req->script_name_len, uwsgi.wsgi_req->script_name);
return -1;
}
@@ -1679,7 +1685,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (uwsgi.single_interpreter == 0) {
wi->interpreter = Py_NewInterpreter();
if (!wi->interpreter) {
fprintf(stderr, "unable to initialize the new interpreter\n");
uwsgi_log( "unable to initialize the new interpreter\n");
exit(1);
}
PyThreadState_Swap(wi->interpreter);
@@ -1689,7 +1695,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
init_uwsgi_embedded_module();
#endif
init_uwsgi_vars();
fprintf(stderr, "interpreter for app %d initialized.\n", id);
uwsgi_log( "interpreter for app %d initialized.\n", id);
}
if (uwsgi.paste) {
@@ -1809,7 +1815,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
if (wsgi_dict) {
wi->wsgi_harakiri = PyDict_GetItemString(wsgi_dict, "harakiri");
if (wi->wsgi_harakiri) {
fprintf(stderr, "initialized Harakiri custom handler: %p.\n", wi->wsgi_harakiri);
uwsgi_log( "initialized Harakiri custom handler: %p.\n", wi->wsgi_harakiri);
}
}
@@ -1840,7 +1846,7 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
pycprof = PyImport_ImportModule("cProfile");
if (!pycprof) {
PyErr_Print();
fprintf(stderr, "trying old profile module...\n");
uwsgi_log( "trying old profile module...\n");
pycprof = PyImport_ImportModule("profile");
if (!pycprof) {
PyErr_Print();
@@ -1952,10 +1958,10 @@ int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) {
PyDict_SetItemString(uwsgi.py_apps, tmpstring, PyInt_FromLong(id));
PyErr_Print();
fprintf(stderr, "application %d (%s) ready\n", id, tmpstring);
uwsgi_log( "application %d (%s) ready\n", id, tmpstring);
if (id == 0) {
fprintf(stderr, "setting default application to 0\n");
uwsgi_log( "setting default application to 0\n");
uwsgi.default_app = 0;
}
else {
@@ -1972,7 +1978,7 @@ void uwsgi_paste_config() {
uwsgi.single_interpreter = 1;
fprintf(stderr, "Loading paste environment: %s\n", uwsgi.paste);
uwsgi_log( "Loading paste environment: %s\n", uwsgi.paste);
paste_module = PyImport_ImportModule("paste.deploy");
if (!paste_module) {
PyErr_Print();
@@ -2033,7 +2039,7 @@ void uwsgi_wsgi_file_config() {
wsgi_file_node = PyParser_SimpleParseFile(wsgifile, uwsgi.wsgi_file, Py_file_input);
if (!wsgi_file_node) {
PyErr_Print();
fprintf(stderr, "failed to parse wsgi file %s\n", uwsgi.wsgi_file);
uwsgi_log( "failed to parse wsgi file %s\n", uwsgi.wsgi_file);
exit(1);
}
@@ -2043,7 +2049,7 @@ void uwsgi_wsgi_file_config() {
if (!wsgi_compiled_node) {
PyErr_Print();
fprintf(stderr, "failed to compile wsgi file %s\n", uwsgi.wsgi_file);
uwsgi_log( "failed to compile wsgi file %s\n", uwsgi.wsgi_file);
exit(1);
}
@@ -2065,12 +2071,12 @@ void uwsgi_wsgi_file_config() {
wsgi_file_callable = PyDict_GetItemString(wsgi_file_dict, "application");
if (!wsgi_file_callable) {
PyErr_Print();
fprintf(stderr, "unable to find \"application\" callable in wsgi file %s\n", uwsgi.wsgi_file);
uwsgi_log( "unable to find \"application\" callable in wsgi file %s\n", uwsgi.wsgi_file);
exit(1);
}
if (!PyFunction_Check(wsgi_file_callable) && !PyCallable_Check(wsgi_file_callable)) {
fprintf(stderr, "\"application\" must be a callable object in wsgi file %s\n", uwsgi.wsgi_file);
uwsgi_log( "\"application\" must be a callable object in wsgi file %s\n", uwsgi.wsgi_file);
exit(1);
}
@@ -2105,7 +2111,7 @@ void uwsgi_wsgi_config(char *filename) {
struct _node *uwsgi_file_node = PyParser_SimpleParseFile(uwsgifile, filename, Py_file_input);
if (!uwsgi_file_node) {
PyErr_Print();
fprintf(stderr, "failed to parse wsgi file %s\n", filename);
uwsgi_log( "failed to parse wsgi file %s\n", filename);
exit(1);
}
@@ -2115,7 +2121,7 @@ void uwsgi_wsgi_config(char *filename) {
if (!uwsgi_compiled_node) {
PyErr_Print();
fprintf(stderr, "failed to compile wsgi file %s\n", filename);
uwsgi_log( "failed to compile wsgi file %s\n", filename);
exit(1);
}
@@ -2143,7 +2149,7 @@ void uwsgi_wsgi_config(char *filename) {
exit(1);
}
fprintf(stderr, "...getting the applications list from the '%s' module...\n", uwsgi.wsgi_config);
uwsgi_log( "...getting the applications list from the '%s' module...\n", uwsgi.wsgi_config);
#ifdef UWSGI_EMBEDDED
uwsgi_module = PyImport_ImportModule("uwsgi");
@@ -2162,26 +2168,26 @@ void uwsgi_wsgi_config(char *filename) {
applications = PyDict_GetItemString(uwsgi_dict, "applications");
if (!PyDict_Check(applications)) {
fprintf(stderr, "uwsgi.applications dictionary is not defined, trying with the \"applications\" one...\n");
uwsgi_log( "uwsgi.applications dictionary is not defined, trying with the \"applications\" one...\n");
#endif
applications = PyDict_GetItemString(wsgi_dict, "applications");
if (!applications) {
fprintf(stderr, "applications dictionary is not defined, trying with the \"application\" callable.\n");
uwsgi_log( "applications dictionary is not defined, trying with the \"application\" callable.\n");
app_app = PyDict_GetItemString(wsgi_dict, "application");
if (app_app) {
applications = PyDict_New();
if (!applications) {
fprintf(stderr, "could not initialize applications dictionary\n");
uwsgi_log( "could not initialize applications dictionary\n");
exit(1);
}
if (PyDict_SetItemString(applications, "/", app_app)) {
PyErr_Print();
fprintf(stderr, "unable to set default application\n");
uwsgi_log( "unable to set default application\n");
exit(1);
}
}
else {
fprintf(stderr, "static applications not defined, you have to use the dynamic one...\n");
uwsgi_log( "static applications not defined, you have to use the dynamic one...\n");
return;
}
}
@@ -2190,7 +2196,7 @@ void uwsgi_wsgi_config(char *filename) {
#endif
if (!PyDict_Check(applications)) {
fprintf(stderr, "The 'applications' object must be a dictionary.\n");
uwsgi_log( "The 'applications' object must be a dictionary.\n");
exit(1);
}
@@ -2200,7 +2206,7 @@ void uwsgi_wsgi_config(char *filename) {
exit(1);
}
if (PyList_Size(app_list) < 1) {
fprintf(stderr, "You must define an app.\n");
uwsgi_log( "You must define an app.\n");
exit(1);
}
@@ -2208,7 +2214,7 @@ void uwsgi_wsgi_config(char *filename) {
app_mnt = PyList_GetItem(app_list, i);
if (!PyString_Check(app_mnt)) {
fprintf(stderr, "the app mountpoint must be a string.\n");
uwsgi_log( "the app mountpoint must be a string.\n");
exit(1);
}
@@ -2218,23 +2224,23 @@ void uwsgi_wsgi_config(char *filename) {
app_app = PyDict_GetItem(applications, app_mnt);
if (!PyString_Check(app_app) && !PyFunction_Check(app_app) && !PyCallable_Check(app_app)) {
fprintf(stderr, "the app callable must be a string, a function or a callable. (found %s)\n", app_app->ob_type->tp_name);
uwsgi_log( "the app callable must be a string, a function or a callable. (found %s)\n", app_app->ob_type->tp_name);
exit(1);
}
if (PyString_Check(app_app)) {
uwsgi.wsgi_req->wsgi_callable = PyString_AsString(app_app);
uwsgi.wsgi_req->wsgi_callable_len = strlen(uwsgi.wsgi_req->wsgi_callable);
fprintf(stderr, "initializing [%s => %s] app...\n", uwsgi.wsgi_req->script_name, uwsgi.wsgi_req->wsgi_callable);
uwsgi_log( "initializing [%s => %s] app...\n", uwsgi.wsgi_req->script_name, uwsgi.wsgi_req->wsgi_callable);
ret = init_uwsgi_app(wsgi_dict, NULL);
}
else {
fprintf(stderr, "initializing [%s] app...\n", uwsgi.wsgi_req->script_name);
uwsgi_log( "initializing [%s] app...\n", uwsgi.wsgi_req->script_name);
ret = init_uwsgi_app(wsgi_dict, app_app);
}
if (ret < 0) {
fprintf(stderr, "...goodbye cruel world...\n");
uwsgi_log( "...goodbye cruel world...\n");
exit(1);
}
Py_DECREF(app_mnt);
@@ -2301,13 +2307,13 @@ void init_uwsgi_embedded_module() {
new_uwsgi_module = Py_InitModule("uwsgi", null_methods);
#endif
if (new_uwsgi_module == NULL) {
fprintf(stderr, "could not initialize the uwsgi python module\n");
uwsgi_log( "could not initialize the uwsgi python module\n");
exit(1);
}
uwsgi.embedded_dict = PyModule_GetDict(new_uwsgi_module);
if (!uwsgi.embedded_dict) {
fprintf(stderr, "could not get uwsgi module __dict__\n");
uwsgi_log( "could not get uwsgi module __dict__\n");
exit(1);
}
@@ -2409,7 +2415,7 @@ pid_t proxy_start(has_master) {
}
if (uwsgi.proxyfd < 0) {
fprintf(stderr, "unable to create the server socket.\n");
uwsgi_log( "unable to create the server socket.\n");
exit(1);
}
@@ -2452,7 +2458,7 @@ pid_t spooler_start(int serverfd, PyObject * uwsgi_module_dict) {
spooler(&uwsgi, uwsgi_module_dict);
}
else if (pid > 0) {
fprintf(stderr, "spawned the uWSGI spooler on dir %s with pid %d\n", uwsgi.spool_dir, pid);
uwsgi_log( "spawned the uWSGI spooler on dir %s with pid %d\n", uwsgi.spool_dir, pid);
}
return pid;
@@ -2538,7 +2544,7 @@ void manage_opt(int i, char *optarg) {
uwsgi.python_path_cnt++;
}
else {
fprintf(stderr, "you can specify at most 64 --pythonpath options\n");
uwsgi_log( "you can specify at most 64 --pythonpath options\n");
}
break;
case LONG_ARGS_LIMIT_AS:
@@ -2602,7 +2608,7 @@ void manage_opt(int i, char *optarg) {
}
tmp_filename = malloc(8192);
if (!tmp_filename) {
fprintf(stderr, "unable to allocate space (8k) for tmp_filename\n");
uwsgi_log( "unable to allocate space (8k) for tmp_filename\n");
exit(1);
}
memset(tmp_filename, 0, 8192);
@@ -2716,7 +2722,6 @@ void manage_opt(int i, char *optarg) {
\t--chroot <dir>\t\t\tchroot to directory <dir> (only root)\n\
\t--gid <id>\t\t\tsetgid to <id> (only root)\n\
\t--uid <id>\t\t\tsetuid to <id> (only root)\n\
\t--sync-log\t\t\tlet uWSGI does its best to avoid logfile mess\n\
\t--no-server\t\t\tinitialize the uWSGI server then exit. Useful for testing and using uwsgi embedded module\n\
\t--no-defer-accept\t\tdisable the no-standard way to defer the accept() call (TCP_DEFER_ACCEPT, SO_ACCEPTFILTER...)\n\
\t--paste <config:/egg:>\t\tload applications using paste.deploy.loadapp()\n\
@@ -2743,7 +2748,7 @@ void manage_opt(int i, char *optarg) {
break;
default:
if (i != '?') {
fprintf(stderr, "invalid argument -%c exiting \n", i);
uwsgi_log( "invalid argument -%c exiting \n", i);
}
exit(1);
#endif
@@ -2758,7 +2763,7 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
char *tcp_port;
if (strlen(nodename) > 100) {
fprintf(stderr, "invalid cluster node name %s\n", nodename);
uwsgi_log( "invalid cluster node name %s\n", nodename);
return;
}
@@ -2772,7 +2777,7 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
ucn = &uwsgi.shared->nodes[i];
if (ucn->name[0] == 0) {
strcpy(ucn->name, nodename);
strlcpy(ucn->name, nodename, 101);
ucn->workers = workers;
ucn->ucn_addr.sin_family = AF_INET;
ucn->ucn_addr.sin_port = htons(atoi(tcp_port + 1));
@@ -2781,7 +2786,7 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
ucn->ucn_addr.sin_addr.s_addr = INADDR_ANY;
}
else {
fprintf(stderr, "%s\n", nodename);
uwsgi_log( "%s\n", nodename);
ucn->ucn_addr.sin_addr.s_addr = inet_addr(nodename);
}
@@ -2791,5 +2796,5 @@ void uwsgi_cluster_add_node(char *nodename, int workers) {
}
}
fprintf(stderr, "unable to add node %s\n", nodename);
uwsgi_log( "unable to add node %s\n", nodename);
}
+12 -4
View File
@@ -4,15 +4,22 @@
#define UWSGI_VERSION "0.9.5-dev"
#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>
@@ -423,9 +430,6 @@ struct uwsgi_server {
int page_size;
char *sync_page;
int synclog;
char *test_module;
char *pidfile;
@@ -663,6 +667,8 @@ void set_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 *);
@@ -819,3 +825,5 @@ void sanitize_args(struct uwsgi_server *);
void env_to_arg(char *, char *);
void parse_sys_envs(char **, struct option *);
void uwsgi_log(const char *, ...);
+14 -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,25 @@ 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;
}
@@ -62,7 +68,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 +110,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);
}
+12 -12
View File
@@ -51,7 +51,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 +74,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 +497,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 +579,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 +607,7 @@ PyObject *py_uwsgi_load_plugin(PyObject * self, PyObject * args) {
}
else {
fprintf(stderr, "%s\n", dlerror());
uwsgi_log( "%s\n", dlerror());
}
}
@@ -830,7 +830,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);
@@ -900,7 +900,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 +925,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 +942,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);
}
+5
View File
@@ -136,6 +136,8 @@ def unbit_setup():
def parse_vars():
global UGREEN
version = sys.version_info
uver = "%d.%d" % (version[0], version[1])
@@ -153,6 +155,9 @@ def parse_vars():
if uwsgi_os in kvm_list:
ldflags.append('-lkvm')
if uwsgi_os == 'OpenBSD':
UGREEN = False
if EMBEDDED:
cflags.append('-DUWSGI_EMBEDDED')
gcc_list.append('uwsgi_pymodule')
+5 -5
View File
@@ -98,12 +98,12 @@ 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;
}
@@ -158,13 +158,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 +183,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);
+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);
}