Solaris/Sparc fixes

This commit is contained in:
roberto@solaris
2010-04-19 08:34:46 +02:00
parent 688ffe32a9
commit 47847ee471
12 changed files with 82 additions and 25 deletions
+5 -2
View File
@@ -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 ;
}
+23 -3
View File
@@ -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 <kvm.h>
#include <sys/sysctl.h>
#include <sys/user.h>
#elif defined(__sun__)
/* Terrible Hack !!! */
#ifndef _LP64
#undef _FILE_OFFSET_BITS
#endif
#include <procfs.h>
#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) {
+1 -1
View File
@@ -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);
}
+3 -2
View File
@@ -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;
}
+1 -1
View File
@@ -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) {
+2
View File
@@ -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);
+2 -1
View File
@@ -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;
}
+32 -8
View File
@@ -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<uwsgi.async;i++) {
uwsgi.async_buf[i] = malloc(uwsgi.buffer_size);
if (!uwsgi.async_buf[i]) {
perror("malloc()");
exit(1);
}
}
// 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.buffer_size-1) ) * uwsgi.async,
(uint64_t)( (sizeof(struct wsgi_request) + (uwsgi.buffer_size-1) * uwsgi.async ) / 1024),
fprintf(stderr, "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) {
@@ -595,6 +610,7 @@ int main(int argc, char *argv[], char *envp[]) {
}
}
if (uwsgi.pyhome != NULL) {
fprintf(stderr, "Setting PythonHome to %s...\n", uwsgi.pyhome);
#ifdef PYTHREE
@@ -626,6 +642,8 @@ int main(int argc, char *argv[], char *envp[]) {
Py_Initialize();
#ifdef PYTHREE
mbstowcs(pname, "uwsgi", 6);
pyargv[0] = pname;
@@ -643,7 +661,13 @@ int main(int argc, char *argv[], char *envp[]) {
wchar_t *wa;
#endif
char *ap;
#ifdef __sun__
// FIX THIS !!!
ap = strtok(uwsgi.pyargv, " ");
while ((ap = strtok(NULL, " ")) != NULL) {
#else
while ((ap = strsep(&uwsgi.pyargv, " \t")) != NULL) {
#endif
if (*ap != '\0') {
#ifdef PYTHREE
wa = (wchar_t *) ( (ap-uwsgi.pyargv) * sizeof(wchar_t) );
@@ -1204,10 +1228,10 @@ int main(int argc, char *argv[], char *envp[]) {
else if (rlen > 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;
+9 -4
View File
@@ -58,8 +58,9 @@
#undef _POSIX_C_SOURCE
#endif
#ifdef __sun__
#undef _FILE_OFFSET_BITS
#define WAIT_ANY (-1)
#include <sys/filio.h>
#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 <endian.h>
#elif __sun__
#include <sys/byteorder.h>
#ifdef _BIG_ENDIAN
#define __BIG_ENDIAN__ 1
#endif
#elif __apple__
#include <libkern/OSByteOrder.h>
#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) ;
+1 -1
View File
@@ -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)) {
+1 -1
View File
@@ -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
+2 -1
View File
@@ -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')