From 47847ee4712f916cc5f2b67f2f6bcc9cc7947ea5 Mon Sep 17 00:00:00 2001 From: "roberto@solaris" Date: Mon, 19 Apr 2010 08:34:46 +0200 Subject: [PATCH] Solaris/Sparc fixes --- async.c | 7 +++++-- logging.c | 26 +++++++++++++++++++++++--- nagios.c | 2 +- protocol.c | 5 +++-- spooler.c | 2 +- ugreen.c | 2 ++ utils.c | 3 ++- uwsgi.c | 40 ++++++++++++++++++++++++++++++++-------- uwsgi.h | 13 +++++++++---- uwsgi_handlers.c | 2 +- uwsgi_pymodule.c | 2 +- uwsgiconfig.py | 3 ++- 12 files changed, 82 insertions(+), 25 deletions(-) diff --git a/async.c b/async.c index 4330bf86..a124ec19 100644 --- a/async.c +++ b/async.c @@ -101,6 +101,7 @@ int async_queue_init(int serverfd) { int dpfd ; struct pollfd dpev; + dpfd = open("/dev/poll", O_RDWR); if (dpfd < 0) { @@ -108,6 +109,7 @@ int async_queue_init(int serverfd) { return -1 ; } + dpev.fd = serverfd; dpev.events = POLLIN ; @@ -116,6 +118,7 @@ int async_queue_init(int serverfd) { return -1; } + return dpfd; } @@ -260,11 +263,11 @@ int async_del(int queuefd, int fd, int etype) { #endif -struct wsgi_request *next_wsgi_req(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) { +inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) { uint8_t *ptr = (uint8_t *) wsgi_req ; - ptr += sizeof(struct wsgi_request)+(uwsgi->buffer_size-1) ; + ptr += sizeof(struct wsgi_request) ; return (struct wsgi_request *) ptr ; } diff --git a/logging.c b/logging.c index 1aee2b9a..241f0ae4 100644 --- a/logging.c +++ b/logging.c @@ -1,9 +1,15 @@ #include "uwsgi.h" -#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__OpenBSD__) +#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) #include -#include #include +#elif defined(__sun__) +/* Terrible Hack !!! */ +#ifndef _LP64 +#undef _FILE_OFFSET_BITS +#endif +#include +#define _FILE_OFFSET_BITS 64 #endif extern struct uwsgi_server uwsgi; @@ -96,6 +102,19 @@ void get_memusage() { fclose(procfile); } uwsgi.workers[uwsgi.mywid].rss_size = uwsgi.workers[uwsgi.mywid].rss_size * uwsgi.page_size; +#elif defined (__sun__) + psinfo_t info; + int procfd ; + + procfd = open("/proc/self/psinfo", O_RDONLY); + if (procfd >= 0) { + if ( read(procfd, (char *) &info, sizeof(info)) > 0) { + uwsgi.workers[uwsgi.mywid].rss_size = (uint64_t) info.pr_rssize * 1024 ; + uwsgi.workers[uwsgi.mywid].vsz_size = (uint64_t) info.pr_size * 1024 ; + } + close(procfd); + } + #elif defined( __APPLE__) /* darwin documentation says that the value are in pages, but they are bytes !!! */ struct task_basic_info t_info; @@ -105,13 +124,14 @@ void get_memusage() { uwsgi.workers[uwsgi.mywid].rss_size = t_info.resident_size; uwsgi.workers[uwsgi.mywid].vsz_size = t_info.virtual_size; } -#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__sun__) || defined(__OpenBSD__) +#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) || defined(__OpenBSD__) kvm_t *kv; int cnt; kv = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); if (kv) { #if defined(__FreeBSD__) || defined(__DragonFly__) + struct kinfo_proc *kproc; kproc = kvm_getprocs(kv, KERN_PROC_PID, uwsgi.mypid, &cnt); if (kproc && cnt > 0) { diff --git a/nagios.c b/nagios.c index 975fc79d..6a4663df 100644 --- a/nagios.c +++ b/nagios.c @@ -30,7 +30,7 @@ void nagios(struct uwsgi_server *uwsgi) { exit(2); } nagios_poll.events = POLLIN; - if (!uwsgi_parse_response(&nagios_poll, uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) uwsgi->wsgi_req, &uwsgi->wsgi_req->buffer)) { + if (!uwsgi_parse_response(&nagios_poll, uwsgi->shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) uwsgi->wsgi_req, uwsgi->wsgi_req->buffer)) { fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n"); exit(2); } diff --git a/protocol.c b/protocol.c index 73911bb1..62b1f6b2 100644 --- a/protocol.c +++ b/protocol.c @@ -292,7 +292,7 @@ int uwsgi_parse_response(struct pollfd *upoll, int timeout, struct uwsgi_header int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) { - char *buffer = &wsgi_req->buffer; + char *buffer = wsgi_req->buffer; char *ptrbuf, *bufferend; @@ -392,6 +392,7 @@ int uwsgi_parse_vars(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) // 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); if (wsgi_req->var_cnt < uwsgi->vec_size - (4 + 1)) { wsgi_req->var_cnt++; } @@ -454,7 +455,7 @@ int uwsgi_ping_node(int node, struct wsgi_request *wsgi_req) { } uwsgi_poll.events = POLLIN; - if (!uwsgi_parse_response(&uwsgi_poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) wsgi_req, &wsgi_req->buffer)) { + if (!uwsgi_parse_response(&uwsgi_poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) wsgi_req, wsgi_req->buffer)) { return -1; } diff --git a/spooler.c b/spooler.c index 07fd6dd6..d8699e52 100644 --- a/spooler.c +++ b/spooler.c @@ -295,7 +295,7 @@ int uwsgi_request_spooler(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_ } fprintf(stderr, "managing spool request...\n"); - i = spool_request(uwsgi, spool_filename, uwsgi->workers[0].requests + 1, &wsgi_req->buffer, wsgi_req->uh.pktsize); + 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) { diff --git a/ugreen.c b/ugreen.c index d2c6ab5c..9ada5281 100644 --- a/ugreen.c +++ b/ugreen.c @@ -313,6 +313,7 @@ void u_green_init(struct uwsgi_server *uwsgi) { } getcontext(uwsgi->ugreen_contexts[i]); uwsgi->ugreen_contexts[i]->uc_stack.ss_sp = mmap(NULL, u_stack_size + (uwsgi->page_size*2) , PROT_READ | PROT_WRITE | PROT_EXEC, MAP_ANON | MAP_PRIVATE, -1, 0) + uwsgi->page_size; + if (!uwsgi->ugreen_contexts[i]->uc_stack.ss_sp) { perror("mmap()"); exit(1); @@ -326,6 +327,7 @@ void u_green_init(struct uwsgi_server *uwsgi) { perror("mprotect()"); exit(1); } + uwsgi->ugreen_contexts[i]->uc_stack.ss_size = u_stack_size ; uwsgi->ugreen_contexts[i]->uc_link = NULL; makecontext(uwsgi->ugreen_contexts[i], (void (*) (void)) &u_green_request, 3, uwsgi, wsgi_req, i); diff --git a/utils.c b/utils.c index 6c314a56..2e827b6e 100644 --- a/utils.c +++ b/utils.c @@ -292,6 +292,7 @@ void wsgi_req_setup(struct wsgi_request *wsgi_req, int async_id) { wsgi_req->async_waiting_fd = -1; #endif wsgi_req->hvec = &uwsgi.async_hvec[wsgi_req->async_id]; + wsgi_req->buffer = uwsgi.async_buf[wsgi_req->async_id]; } @@ -301,7 +302,7 @@ int wsgi_req_recv(struct wsgi_request *wsgi_req) { if (uwsgi.shared->options[UWSGI_OPTION_LOGGING]) gettimeofday(&wsgi_req->start_of_request, NULL); - if (!uwsgi_parse_response(&wsgi_req->poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) wsgi_req, &wsgi_req->buffer)) { + if (!uwsgi_parse_response(&wsgi_req->poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) wsgi_req, wsgi_req->buffer)) { return -1; } diff --git a/uwsgi.c b/uwsgi.c index 3adbeedd..4f5a1cda 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -572,18 +572,33 @@ int main(int argc, char *argv[], char *envp[]) { } // allocate more wsgi_req for async mode - uwsgi.wsgi_requests = malloc((sizeof(struct wsgi_request) + (uwsgi.buffer_size-1) ) * uwsgi.async); + uwsgi.wsgi_requests = malloc(sizeof(struct wsgi_request) * uwsgi.async); if (uwsgi.wsgi_requests == NULL) { fprintf(stderr, "unable to allocate memory for requests.\n"); exit(1); } - memset(uwsgi.wsgi_requests, 0, (sizeof(struct wsgi_request) + (uwsgi.buffer_size-1) ) * uwsgi.async); + memset(uwsgi.wsgi_requests, 0, sizeof(struct wsgi_request) * uwsgi.async); + + uwsgi.async_buf = malloc( sizeof(char *) * uwsgi.async); + if (!uwsgi.async_buf) { + perror("malloc()"); + exit(1); + } + + for(i=0;i 0) { memset(udp_client_addr, 0, 16); if (inet_ntop(AF_INET, &udp_client.sin_addr.s_addr, udp_client_addr, 16)) { - if (uwsgi.wsgi_req->buffer == UWSGI_MODIFIER_MULTICAST_ANNOUNCE) { + if (uwsgi.wsgi_req->buffer[0] == UWSGI_MODIFIER_MULTICAST_ANNOUNCE) { } #ifdef UWSGI_SNMP - else if (uwsgi.wsgi_req->buffer == 0x30 && 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); } #endif @@ -1215,7 +1239,7 @@ int main(int argc, char *argv[], char *envp[]) { if (udp_callable && udp_callable_args) { PyTuple_SetItem(udp_callable_args, 0, PyString_FromString(udp_client_addr)); PyTuple_SetItem(udp_callable_args, 1, PyInt_FromLong(ntohs(udp_client.sin_port))); - PyTuple_SetItem(udp_callable_args, 2, PyString_FromStringAndSize(&uwsgi.wsgi_req->buffer, rlen)); + PyTuple_SetItem(udp_callable_args, 2, PyString_FromStringAndSize(uwsgi.wsgi_req->buffer, rlen)); PyObject *udp_response = python_call(udp_callable, udp_callable_args); if (udp_response) { Py_DECREF(udp_response); @@ -1485,7 +1509,7 @@ int main(int argc, char *argv[], char *envp[]) { goto cycle; } - wsgi_req_setup(uwsgi.wsgi_req, ( (uint8_t *) uwsgi.wsgi_req - (uint8_t *) uwsgi.wsgi_requests)/(sizeof(struct wsgi_request)+(uwsgi.buffer_size-1))) ; + wsgi_req_setup(uwsgi.wsgi_req, ( (uint8_t *)uwsgi.wsgi_req - (uint8_t *)uwsgi.wsgi_requests)/sizeof(struct wsgi_request) ); if (wsgi_req_accept(uwsgi.serverfd, uwsgi.wsgi_req)) { continue; diff --git a/uwsgi.h b/uwsgi.h index 804f5f5a..33fd8209 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -58,8 +58,9 @@ #undef _POSIX_C_SOURCE #endif #ifdef __sun__ -#undef _FILE_OFFSET_BITS #define WAIT_ANY (-1) +#include +#define PRIO_MAX 20 #endif #define MAX_PYARGV 10 @@ -160,6 +161,10 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #ifdef __linux__ #include #elif __sun__ +#include +#ifdef _BIG_ENDIAN +#define __BIG_ENDIAN__ 1 +#endif #elif __apple__ #include #else @@ -337,8 +342,7 @@ struct wsgi_request { PyTaskletObject* tasklet; #endif - // buffer MUST BE THE LAST VAR !!! - char buffer; + char *buffer; }; struct uwsgi_server { @@ -369,6 +373,7 @@ struct uwsgi_server { #endif struct iovec *async_hvec; + char **async_buf; struct rlimit rl; @@ -717,7 +722,7 @@ struct wsgi_request *find_first_available_wsgi_req(struct uwsgi_server *); struct wsgi_request *find_wsgi_req_by_fd(struct uwsgi_server *, int, int); struct wsgi_request *find_wsgi_req_by_id(struct uwsgi_server *, int); -struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *); +inline struct wsgi_request *next_wsgi_req(struct uwsgi_server *, struct wsgi_request *); int async_add(int, int , int) ; int async_mod(int, int , int) ; diff --git a/uwsgi_handlers.c b/uwsgi_handlers.c index e0891e43..addb18d4 100644 --- a/uwsgi_handlers.c +++ b/uwsgi_handlers.c @@ -76,7 +76,7 @@ int uwsgi_request_marshal(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_ PyObject *umm = PyDict_GetItemString(uwsgi->embedded_dict, "message_manager_marshal"); if (umm) { - PyObject *ummo = PyMarshal_ReadObjectFromString(&wsgi_req->buffer, + PyObject *ummo = PyMarshal_ReadObjectFromString(wsgi_req->buffer, wsgi_req->uh.pktsize); if (ummo) { if (!PyTuple_SetItem(uwsgi->embedded_args, 0, ummo)) { diff --git a/uwsgi_pymodule.c b/uwsgi_pymodule.c index 7dc4e579..7165c19d 100644 --- a/uwsgi_pymodule.c +++ b/uwsgi_pymodule.c @@ -9,7 +9,7 @@ extern struct uwsgi_server uwsgi; #ifdef __APPLE__ #define UWSGI_LOCK OSSpinLockLock((OSSpinLock *) uwsgi.sharedareamutex); #define UWSGI_UNLOCK OSSpinLockUnlock((OSSpinLock *) uwsgi.sharedareamutex); -#elif defined(__linux__) +#elif defined(__linux__) || defined(__sun__) || defined(__FreeBSD__) #define UWSGI_LOCK pthread_mutex_lock((pthread_mutex_t *) uwsgi.sharedareamutex + sizeof(pthread_mutexattr_t)); #define UWSGI_UNLOCK pthread_mutex_unlock((pthread_mutex_t *) uwsgi.sharedareamutex + sizeof(pthread_mutexattr_t)); #else diff --git a/uwsgiconfig.py b/uwsgiconfig.py index db45c1af..89b8e858 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -144,10 +144,11 @@ def parse_vars(): if str(PYLIB_PATH) != '': ldflags.insert(0,'-L' + PYLIB_PATH) - kvm_list = ['SunOS', 'FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly'] + kvm_list = ['FreeBSD', 'OpenBSD', 'NetBSD', 'DragonFly'] if uwsgi_os == 'SunOS': ldflags.append('-lsendfile') + ldflags.remove('-rdynamic') if uwsgi_os in kvm_list: ldflags.append('-lkvm')