From 82b95114a871d4846e2628640cf184cdad3e7dfc Mon Sep 17 00:00:00 2001 From: "roberto@goyle" Date: Thu, 2 Jun 2011 11:38:18 +0200 Subject: [PATCH] added welcome.py --- socket.c | 8 +++++++- welcome.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 welcome.py diff --git a/socket.c b/socket.c index c8e17057..0b434e7a 100644 --- a/socket.c +++ b/socket.c @@ -260,12 +260,18 @@ int connect_to_unix(char *socket_name, int timeout, int async) { struct pollfd uwsgi_poll; struct sockaddr_un uws_addr; + socklen_t un_size = sizeof(struct sockaddr_un); memset(&uws_addr, 0, sizeof(struct sockaddr_un)); uws_addr.sun_family = AF_UNIX; memcpy(uws_addr.sun_path, socket_name, 102); + if (socket_name[0] == '@'){ + un_size = sizeof(uws_addr.sun_family) + strlen(socket_name); + uws_addr.sun_path[0] = 0; + } + uwsgi_poll.fd = socket(AF_UNIX, SOCK_STREAM, 0); if (uwsgi_poll.fd < 0) { uwsgi_error("socket()"); @@ -274,7 +280,7 @@ int connect_to_unix(char *socket_name, int timeout, int async) { uwsgi_poll.events = POLLIN; - if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, sizeof(struct sockaddr_un), timeout, async)) { + if (timed_connect(&uwsgi_poll, (const struct sockaddr *) &uws_addr, un_size, timeout, async)) { uwsgi_error("connect()"); close(uwsgi_poll.fd); return -1; diff --git a/welcome.py b/welcome.py new file mode 100644 index 00000000..eb07ea22 --- /dev/null +++ b/welcome.py @@ -0,0 +1,46 @@ +import uwsgi + + +def serve_logo(e, sr): + sr('200 OK', [('Content-Type', 'image/png')]) + return uwsgi.sendfile('logo_uWSGI.png') + +def serve_options(e, sr): + sr('200 OK', [('Content-Type', 'text/html')]) + for opt in xrange(0,256): + yield "%d = %d
" % (opt, uwsgi.get_option(opt)) + +def serve_config(e, sr): + sr('200 OK', [('Content-Type', 'text/html')]) + for opt in uwsgi.opt.keys(): + yield "%s = %s
" % (opt, uwsgi.opt[opt]) + +routes = {} +routes['/logo'] = serve_logo +routes['/config'] = serve_config +routes['/options'] = serve_options + +def application(env, start_response): + + if routes.has_key(env['PATH_INFO']): + return routes[env['PATH_INFO']](env, start_response) + + return """ + version %s
+
+ +Configuration
+
+ +
+ +Dynamic options
+
+ + """ % (uwsgi.version) + + + + + +