From 7434d3113cc7cdfc5aa348b29eb8a06f0662eca4 Mon Sep 17 00:00:00 2001 From: "roberto@haiku" Date: Sat, 11 Sep 2010 14:49:02 +0000 Subject: [PATCH] Haiku OS and gcc 2.95 support --- http.c | 15 ++++++---- nagios.c | 3 +- pyutils.c | 4 ++- socket.c | 2 ++ spooler.c | 6 ++++ uwsgi.c | 71 ++++++++++++++++++++++++++++++++++++------------ uwsgi.h | 10 +++++++ uwsgi_pymodule.c | 9 ++++-- uwsgiconfig.py | 9 +++++- wsgi_handlers.c | 9 ++++-- 10 files changed, 105 insertions(+), 33 deletions(-) diff --git a/http.c b/http.c index 58b20d02..ae9030dc 100644 --- a/http.c +++ b/http.c @@ -174,10 +174,8 @@ static void *http_request(void *u_h_r) char buf[4096]; char tmp_buf[4096]; - char *ptr; char uwsgipkt[4096]; - char *up; struct uwsgi_http_req *ur = (struct uwsgi_http_req *) u_h_r ; @@ -197,14 +195,17 @@ static void *http_request(void *u_h_r) uint16_t ulen; - ptr = tmp_buf; + char *ptr = tmp_buf; int qs = 0; - up = uwsgipkt; + char *up = uwsgipkt; char *watermark = up + 4096 ; char *watermark2 = tmp_buf + 4096 ; + + int path_info_len; + char *ip; up[0] = 0; up[3] = 0; @@ -230,7 +231,7 @@ static void *http_request(void *u_h_r) up = add_uwsgi_var(up, "REQUEST_URI", 11, tmp_buf, ptr - tmp_buf, 0, watermark); - int path_info_len = ptr - tmp_buf; + path_info_len = ptr - tmp_buf; for (j = 0; j < ptr - tmp_buf; j++) { if (tmp_buf[j] == '?') { path_info_len = j; @@ -301,7 +302,7 @@ static void *http_request(void *u_h_r) up = add_uwsgi_var(up, "SCRIPT_NAME", 11, "", 0, 0, watermark); - char *ip = inet_ntoa(ur->c_addr.sin_addr); + ip = inet_ntoa(ur->c_addr.sin_addr); up = add_uwsgi_var(up, "REMOTE_ADDR", 11, ip, strlen(ip), 0, watermark); //up = add_uwsgi_var(up, "REMOTE_ADDR", 11, "127.0.0.1", 9, 0, watermark); @@ -391,4 +392,6 @@ clear: free(ur); pthread_exit(NULL); + + return NULL; } diff --git a/nagios.c b/nagios.c index 39b12ecc..e1397331 100644 --- a/nagios.c +++ b/nagios.c @@ -2,13 +2,14 @@ void nagios(struct uwsgi_server *uwsgi) { + char *tcp_port; struct pollfd nagios_poll; // connect and send if (uwsgi->socket_name == NULL) { fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n"); exit(3); } - char *tcp_port = strchr(uwsgi->socket_name, ':'); + tcp_port = strchr(uwsgi->socket_name, ':'); if (tcp_port == NULL) { fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n"); exit(3); diff --git a/pyutils.c b/pyutils.c index 2048619d..b9b94464 100644 --- a/pyutils.c +++ b/pyutils.c @@ -210,6 +210,8 @@ int uwsgi_python_call(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, } void init_pyargv(struct uwsgi_server *uwsgi) { + + char *ap; #ifdef PYTHREE wchar_t pname[6]; @@ -229,7 +231,7 @@ void init_pyargv(struct uwsgi_server *uwsgi) { } memset(wcargv, 0, sizeof( wchar_t ) * (strlen(uwsgi->pyargv)+1)); #endif - char *ap; + #ifdef __sun__ // FIX THIS !!! ap = strtok(uwsgi->pyargv, " "); diff --git a/socket.c b/socket.c index 4c0e082d..084b717d 100644 --- a/socket.c +++ b/socket.c @@ -39,11 +39,13 @@ int bind_to_unix(char *socket_name, int listen_queue, int chmod_socket, int abst uws_addr->sun_family = AF_UNIX; memcpy(uws_addr->sun_path + abstract_socket, socket_name, 102); + if (bind(serverfd, (struct sockaddr *) uws_addr, strlen(socket_name) + abstract_socket + ((void *) uws_addr->sun_path - (void *) uws_addr)) != 0) { uwsgi_error("bind()"); exit(1); } + if (listen(serverfd, listen_queue) != 0) { uwsgi_error("listen()"); diff --git a/spooler.c b/spooler.c index cd1c5de8..df2f9720 100644 --- a/spooler.c +++ b/spooler.c @@ -111,8 +111,14 @@ void spooler(struct uwsgi_server *uwsgi, PyObject * uwsgi_module_dict) { } // asked by Marco Beri + +#ifdef __HAIKU__ + uwsgi_log( "lowering spooler priority to %d\n", B_LOW_PRIORITY); + set_thread_priority(find_thread(NULL), B_LOW_PRIORITY); +#else uwsgi_log( "lowering spooler priority to %d\n", PRIO_MAX); setpriority(PRIO_PROCESS, getpid(), PRIO_MAX); +#endif nullfd = open("/dev/null", O_RDONLY); if (nullfd < 0) { diff --git a/uwsgi.c b/uwsgi.c index b1cb6c3b..fa89bced 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -447,6 +447,18 @@ int main(int argc, char *argv[], char *envp[]) { unsigned int reloads = 0; char env_reload_buf[11]; + int option_index = 0; + +#ifdef UWSGI_UDP + PyObject *udp_callable; + PyObject *udp_callable_args = NULL; + PyObject *udp_response; +#endif + + +#ifdef UWSGI_HTTP + pid_t http_pid; +#endif #ifdef UNBIT //struct uidsec_struct us; @@ -454,6 +466,16 @@ int main(int argc, char *argv[], char *envp[]) { int socket_type = 0; socklen_t socket_type_len; + + PyObject *random_module, *random_dict, *random_seed; + + int master_has_children = 0; + +#ifdef UWSGI_DEBUG + struct utsname uuts; + int so_bufsize ; + socklen_t so_bufsize_len; +#endif /* anti signal bombing */ signal(SIGHUP, SIG_IGN); @@ -470,7 +492,7 @@ int main(int argc, char *argv[], char *envp[]) { #ifdef UWSGI_DEBUG /* get system information */ - struct utsname uuts; + if (uname(&uuts)) { uwsgi_error("uname()"); } @@ -518,7 +540,7 @@ int main(int argc, char *argv[], char *envp[]) { uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT] = 4; uwsgi.shared->options[UWSGI_OPTION_LOGGING] = 1; - int option_index = 0; + gettimeofday(&uwsgi.start_tv, NULL); @@ -669,8 +691,14 @@ int main(int argc, char *argv[], char *envp[]) { } if (uwsgi.prio != 0) { +#ifdef __HAIKU__ + if (set_thread_priority(find_thread(NULL),uwsgi.prio) == B_BAD_THREAD_ID) { + uwsgi_error("set_thread_priority()"); +#else if (setpriority(PRIO_PROCESS, 0, uwsgi.prio)) { uwsgi_error("setpriority()"); +#endif + } else { uwsgi_log("scheduler priority set to %d\n", uwsgi.prio); @@ -717,15 +745,20 @@ int main(int argc, char *argv[], char *envp[]) { } if (!uwsgi.socket_name) { + uwsgi.socket_name = malloc(64); if (!uwsgi.socket_name) { uwsgi_error("malloc()"); exit(1); } - snprintf(uwsgi.socket_name, 64, "%d_%d.sock", (int) time(NULL), (int) getpid()); - uwsgi_log("using %s as uwsgi protocol socket\n", uwsgi.socket_name); + + snprintf(uwsgi.socket_name, 64, "%d_%d.sock", (int) time(NULL), (int) getpid()); + + + + uwsgi_log("using %s as uwsgi protocol socket\n", uwsgi.socket_name); } @@ -735,10 +768,10 @@ int main(int argc, char *argv[], char *envp[]) { exit(1); } - pid_t http_pid = fork(); + http_pid = fork(); if (http_pid > 0) { - masterpid = http_pid; + masterpid = http_pid; http_loop(&uwsgi); // never here exit(1); @@ -1007,8 +1040,7 @@ int main(int argc, char *argv[], char *envp[]) { #ifdef UWSGI_DEBUG - int so_bufsize ; - socklen_t so_bufsize_len = sizeof(int) ; + so_bufsize_len = sizeof(int) ; if (getsockopt(uwsgi.serverfd, SOL_SOCKET, SO_RCVBUF, &so_bufsize, &so_bufsize_len)) { uwsgi_error("getsockopt()"); } @@ -1283,8 +1315,7 @@ int main(int argc, char *argv[], char *envp[]) { #endif #ifdef UWSGI_UDP - PyObject *udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable"); - PyObject *udp_callable_args = NULL; + udp_callable = PyDict_GetItemString(uwsgi.embedded_dict, "udp_callable"); if (udp_callable) { udp_callable_args = PyTuple_New(3); } @@ -1354,7 +1385,7 @@ int main(int argc, char *argv[], char *envp[]) { exit(1); } - int master_has_children = 0; + if (uwsgi.numproc > 0 ) { master_has_children = 1; @@ -1426,7 +1457,7 @@ int main(int argc, char *argv[], char *envp[]) { 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)); - PyObject *udp_response = python_call(udp_callable, udp_callable_args, 0); + udp_response = python_call(udp_callable, udp_callable_args, 0); if (udp_response) { Py_DECREF(udp_response); } @@ -1629,11 +1660,11 @@ int main(int argc, char *argv[], char *envp[]) { } // reinitialize the random seed (thanks Jonas Borgström) - PyObject *random_module = PyImport_ImportModule("random"); + random_module = PyImport_ImportModule("random"); if (random_module) { - PyObject *random_dict = PyModule_GetDict(random_module); + random_dict = PyModule_GetDict(random_module); if (random_dict) { - PyObject *random_seed = PyDict_GetItemString(random_dict, "seed"); + random_seed = PyDict_GetItemString(random_dict, "seed"); if (random_seed) { PyObject *random_args = PyTuple_New(1); // pass no args @@ -2498,6 +2529,10 @@ void uwsgi_wsgi_config(char *filename) { char *quick_callable = NULL; + PyObject *uwsgi_compiled_node; + struct _node *uwsgi_file_node; + PyObject *tmp_callable; + uwsgi.single_interpreter = 1; if (filename) { @@ -2512,7 +2547,7 @@ void uwsgi_wsgi_config(char *filename) { exit(1); } - struct _node *uwsgi_file_node = PyParser_SimpleParseFile(uwsgifile, filename, Py_file_input); + uwsgi_file_node = PyParser_SimpleParseFile(uwsgifile, filename, Py_file_input); if (!uwsgi_file_node) { PyErr_Print(); uwsgi_log( "failed to parse wsgi file %s\n", filename); @@ -2521,7 +2556,7 @@ void uwsgi_wsgi_config(char *filename) { fclose(uwsgifile); - PyObject *uwsgi_compiled_node = (PyObject *) PyNode_Compile(uwsgi_file_node, filename); + uwsgi_compiled_node = (PyObject *) PyNode_Compile(uwsgi_file_node, filename); if (!uwsgi_compiled_node) { PyErr_Print(); @@ -2617,7 +2652,7 @@ void uwsgi_wsgi_config(char *filename) { // we have extended the concept a bit... if (quick_callable[strlen(quick_callable) -2 ] == '(' && quick_callable[strlen(quick_callable) -1] ==')') { quick_callable[strlen(quick_callable) -2 ] = 0 ; - PyObject *tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable); + tmp_callable = PyDict_GetItemString(wsgi_dict, quick_callable); if (tmp_callable) { app_app = python_call(tmp_callable, PyTuple_New(0), 0); } diff --git a/uwsgi.h b/uwsgi.h index fe4c9017..584eef49 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -90,6 +90,10 @@ #define PRIO_MAX 20 #endif +#ifdef __HAIKU__ +#define WAIT_ANY (-1) +#endif + #define MAX_PYARGV 10 #include @@ -100,10 +104,15 @@ #elif defined(__sun__) #include #include +#elif defined(__HAIKU__) #else #include #endif +#ifdef __HAIKU__ +#include +#endif + #undef _XOPEN_SOURCE #include @@ -218,6 +227,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #endif #elif __APPLE__ #include +#elif defined(__HAIKU__) #else #include #endif diff --git a/uwsgi_pymodule.c b/uwsgi_pymodule.c index 6ede4f56..33e77910 100644 --- a/uwsgi_pymodule.c +++ b/uwsgi_pymodule.c @@ -531,6 +531,8 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) { char *buffer; struct uwsgi_header uh; PyObject *arg_cluster; + + PyObject *cluster_node; PyObject *arg_host, *arg_port, *arg_message; @@ -588,7 +590,7 @@ PyObject *py_uwsgi_send_multi_message(PyObject * self, PyObject * args) { for (i = 0; i < clen; i++) { multipoll[i].events = POLLIN; - PyObject *cluster_node = PyTuple_GetItem(arg_cluster, i); + cluster_node = PyTuple_GetItem(arg_cluster, i); arg_host = PyTuple_GetItem(cluster_node, 0); if (!PyString_Check(arg_host)) { goto clear; @@ -969,9 +971,10 @@ PyObject *py_uwsgi_mem(PyObject * self, PyObject * args) { } PyObject *py_uwsgi_disconnect(PyObject * self, PyObject * args) { - uwsgi_log( "disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid); - + struct wsgi_request *wsgi_req = current_wsgi_req(&uwsgi); + + uwsgi_log( "disconnecting worker %d (pid :%d) from session...\n", uwsgi.mywid, uwsgi.mypid); fclose(wsgi_req->async_post); wsgi_req->fd_closed = 1 ; diff --git a/uwsgiconfig.py b/uwsgiconfig.py index 07838dba..36e4ad4b 100644 --- a/uwsgiconfig.py +++ b/uwsgiconfig.py @@ -279,9 +279,16 @@ def parse_vars(): if uwsgi_os in kvm_list: libs.append('-lkvm') - if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm': + if uwsgi_os == 'OpenBSD' or uwsgi_cpu[0:3] == 'arm' or uwsgi_os == 'Haiku': UGREEN = False + if uwsgi_os == 'Haiku': + ASYNC = False + PROXY = False + libs.remove('-rdynamic') + libs.remove('-lpthread') + libs.append('-lroot') + if EMBEDDED: cflags.append('-DUWSGI_EMBEDDED') gcc_list.append('uwsgi_pymodule') diff --git a/wsgi_handlers.c b/wsgi_handlers.c index 71eea8f2..64c423ab 100644 --- a/wsgi_handlers.c +++ b/wsgi_handlers.c @@ -73,6 +73,9 @@ PyObject *py_eventfd_write(PyObject * self, PyObject * args) { int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req) { int i; + + size_t post_remains = wsgi_req->post_cl; + ssize_t post_chunk; PyObject *zero, *wsgi_socket; @@ -81,6 +84,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req char *path_info; struct uwsgi_app *wi ; + int tmp_stderr; #ifdef UWSGI_ASYNC if (wsgi_req->async_status == UWSGI_AGAIN) { @@ -257,8 +261,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req uwsgi_error("tmpfile()"); goto clear; } - size_t post_remains = wsgi_req->post_cl; - ssize_t post_chunk; + while(post_remains > 0) { if (uwsgi->shared->options[UWSGI_OPTION_HARAKIRI] > 0) { @@ -401,7 +404,7 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req sorry that is a hack to avoid the rewrite of PyErr_Print temporarily map (using dup2) stderr to wsgi_req->poll.fd */ - int tmp_stderr = dup(2); + tmp_stderr = dup(2); if (tmp_stderr < 0) { uwsgi_error("dup()"); goto clear;