Changeset 285:f98e391595d4 for uwsgi.c

Show
Ignore:
Timestamp:
03/11/10 12:39:30 (5 months ago)
Author:
roberto@…
Branch:
default
Message:

re-indent all the code

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • uwsgi.c

    r284 r285  
    4545extern char **environ; 
    4646 
    47 int find_worker_id (pid_t pid) { 
     47int find_worker_id(pid_t pid) { 
    4848        int i; 
    4949        for (i = 1; i <= uwsgi.numproc; i++) { 
     
    6666int tmp_dir_fd = -1; 
    6767char *tmp_filename; 
    68 int uri_to_hex (void); 
     68int uri_to_hex(void); 
    6969int check_for_memory_errors = 0; 
    7070#endif 
     
    7575struct uwsgi_app *wi; 
    7676 
    77 void warn_pipe () { 
    78         fprintf (stderr, "writing to a closed pipe/socket/fd !!!\n"); 
     77void warn_pipe() { 
     78        fprintf(stderr, "writing to a closed pipe/socket/fd !!!\n"); 
    7979} 
    8080 
    81 void gracefully_kill () { 
    82         fprintf (stderr, "Gracefully killing worker %d...\n", uwsgi.mypid); 
     81void gracefully_kill() { 
     82        fprintf(stderr, "Gracefully killing worker %d...\n", uwsgi.mypid); 
    8383        if (UWSGI_IS_IN_REQUEST) { 
    8484                uwsgi.workers[uwsgi.mywid].manage_next_request = 0; 
    8585        } 
    8686        else { 
    87                 reload_me (); 
     87                reload_me(); 
    8888        } 
    8989} 
    9090 
    91 void reload_me () { 
    92         exit (UWSGI_RELOAD_CODE); 
     91void reload_me() { 
     92        exit(UWSGI_RELOAD_CODE); 
    9393} 
    9494 
    95 void end_me () { 
    96         exit (UWSGI_END_CODE); 
     95void end_me() { 
     96        exit(UWSGI_END_CODE); 
    9797} 
    9898 
    99 void goodbye_cruel_world () { 
    100         fprintf (stderr, "...The work of process %d is done. Seeya!\n", getpid ()); 
    101         exit (0); 
     99void goodbye_cruel_world() { 
     100        fprintf(stderr, "...The work of process %d is done. Seeya!\n", getpid()); 
     101        exit(0); 
    102102} 
    103103 
    104 void kill_them_all () { 
     104void kill_them_all() { 
    105105        int i; 
    106106        uwsgi.to_hell = 1; 
    107         fprintf (stderr, "SIGINT/SIGQUIT received...killing workers...\n"); 
     107        fprintf(stderr, "SIGINT/SIGQUIT received...killing workers...\n"); 
    108108        for (i = 1; i <= uwsgi.numproc; i++) { 
    109                 kill (uwsgi.workers[i].pid, SIGINT); 
     109                kill(uwsgi.workers[i].pid, SIGINT); 
    110110        } 
    111111} 
    112112 
    113 void grace_them_all () { 
     113void grace_them_all() { 
    114114        int i; 
    115115        uwsgi.to_heaven = 1; 
    116         fprintf (stderr, "...gracefully killing workers...\n"); 
     116        fprintf(stderr, "...gracefully killing workers...\n"); 
    117117        for (i = 1; i <= uwsgi.numproc; i++) { 
    118                 kill (uwsgi.workers[i].pid, SIGHUP); 
     118                kill(uwsgi.workers[i].pid, SIGHUP); 
    119119        } 
    120120} 
    121121 
    122 void reap_them_all () { 
     122void reap_them_all() { 
    123123        int i; 
    124         fprintf (stderr, "...brutally killing workers...\n"); 
     124        fprintf(stderr, "...brutally killing workers...\n"); 
    125125        for (i = 1; i <= uwsgi.numproc; i++) { 
    126                 kill (uwsgi.workers[i].pid, SIGTERM); 
     126                kill(uwsgi.workers[i].pid, SIGTERM); 
    127127        } 
    128128} 
    129129 
    130 void harakiri () { 
     130void harakiri() { 
    131131 
    132132        PyThreadState *_myself; 
     
    139139 end rock_solid */ 
    140140 
    141         PyGILState_Ensure (); 
    142         _myself = PyThreadState_Get (); 
     141        PyGILState_Ensure(); 
     142        _myself = PyThreadState_Get(); 
    143143        if (wi) { 
    144144/* 
     
    147147#else 
    148148*/ 
    149                 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, wsgi_req.app_id, wi, wi->wsgi_harakiri, _myself, _myself->frame); 
     149                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, wsgi_req.app_id, wi, wi->wsgi_harakiri, _myself, _myself->frame); 
    150150 
    151151                if (wi->wsgi_harakiri) { 
    152                         PyEval_CallObject (wi->wsgi_harakiri, wi->wsgi_args); 
    153                         if (PyErr_Occurred ()) { 
    154                                 PyErr_Print (); 
    155                         } 
    156                 } 
    157         } 
    158         Py_FatalError ("HARAKIRI !\n"); 
     152                        PyEval_CallObject(wi->wsgi_harakiri, wi->wsgi_args); 
     153                        if (PyErr_Occurred()) { 
     154                                PyErr_Print(); 
     155                        } 
     156                } 
     157        } 
     158        Py_FatalError("HARAKIRI !\n"); 
    159159} 
    160160 
    161161#ifndef UNBIT 
    162 void stats () { 
     162void stats() { 
    163163        struct uwsgi_app *ua = NULL; 
    164164        int i; 
    165165 
    166         fprintf (stderr, "*** pid %d stats ***\n", getpid ()); 
    167         fprintf (stderr, "\ttotal requests: %llu\n", uwsgi.workers[0].requests); 
     166        fprintf(stderr, "*** pid %d stats ***\n", getpid()); 
     167        fprintf(stderr, "\ttotal requests: %llu\n", uwsgi.workers[0].requests); 
    168168        for (i = 0; i < uwsgi.wsgi_cnt; i++) { 
    169169                ua = &uwsgi.wsgi_apps[i]; 
    170170                if (ua) { 
    171                         fprintf (stderr, "\tapp %d requests: %d\n", i, ua->requests); 
    172                 } 
    173         } 
    174         fprintf (stderr, "\n"); 
     171                        fprintf(stderr, "\tapp %d requests: %d\n", i, ua->requests); 
     172                } 
     173        } 
     174        fprintf(stderr, "\n"); 
    175175} 
    176176#endif 
    177177 
    178 void internal_server_error (int fd, char *message) { 
     178void internal_server_error(int fd, char *message) { 
    179179#ifndef UNBIT 
    180180        if (uwsgi.shared->options[UWSGI_OPTION_CGI_MODE] == 0) { 
    181181#endif 
    182                 wsgi_req.headers_size = write (fd, "HTTP/1.1 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 63); 
     182                wsgi_req.headers_size = write(fd, "HTTP/1.1 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 63); 
    183183#ifndef UNBIT 
    184184        } 
    185185        else { 
    186                 wsgi_req.headers_size = write (fd, "Status: 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 62); 
     186                wsgi_req.headers_size = write(fd, "Status: 500 Internal Server Error\r\nContent-type: text/html\r\n\r\n", 62); 
    187187        } 
    188188        wsgi_req.header_cnt = 2; 
    189189#endif 
    190         wsgi_req.response_size = write (fd, "<h1>uWSGI Error</h1>", 20); 
    191         wsgi_req.response_size += write (fd, message, strlen (message)); 
     190        wsgi_req.response_size = write(fd, "<h1>uWSGI Error</h1>", 20); 
     191        wsgi_req.response_size += write(fd, message, strlen(message)); 
    192192} 
    193193 
    194 PyObject *py_uwsgi_write (PyObject * self, PyObject * args) { 
     194PyObject *py_uwsgi_write(PyObject * self, PyObject * args) { 
    195195        PyObject *data; 
    196196        char *content; 
    197197        int len; 
    198         data = PyTuple_GetItem (args, 0); 
    199         if (PyString_Check (data)) { 
    200                 content = PyString_AsString (data); 
    201                 len = PyString_Size (data); 
     198        data = PyTuple_GetItem(args, 0); 
     199        if (PyString_Check(data)) { 
     200                content = PyString_AsString(data); 
     201                len = PyString_Size(data); 
    202202 
    203203#ifdef UWSGI_THREADING 
    204204                if (uwsgi.has_threads && uwsgi.shared->options[UWSGI_OPTION_THREADS] == 1) { 
    205                         Py_BEGIN_ALLOW_THREADS wsgi_req.response_size = write (uwsgi.poll.fd, content, len); 
     205                        Py_BEGIN_ALLOW_THREADS wsgi_req.response_size = write(uwsgi.poll.fd, content, len); 
    206206                Py_END_ALLOW_THREADS} 
    207207                else { 
    208208#endif 
    209                         wsgi_req.response_size = write (uwsgi.poll.fd, content, len); 
     209                        wsgi_req.response_size = write(uwsgi.poll.fd, content, len); 
    210210#ifdef UNBIT 
    211211                        if (save_to_disk >= 0) { 
    212                                 if (write (save_to_disk, content, len) != len) { 
    213                                         perror ("write()"); 
    214                                         close (save_to_disk); 
     212                                if (write(save_to_disk, content, len) != len) { 
     213                                        perror("write()"); 
     214                                        close(save_to_disk); 
    215215                                        save_to_disk = -1; 
    216216                                } 
     
    223223#ifdef UNBIT 
    224224        if (save_to_disk >= 0) { 
    225                 close (save_to_disk); 
     225                close(save_to_disk); 
    226226                save_to_disk = -1; 
    227                 fprintf (stderr, "[uWSGI cacher] output of request %llu (%.*s) on pid %d written to cache file %s\n", uwsgi.workers[0].requests, wsgi_req.uri_len, wsgi_req.uri, uwsgi.mypid, tmp_filename); 
    228         } 
    229 #endif 
    230         Py_INCREF (Py_None); 
     227                fprintf(stderr, "[uWSGI cacher] output of request %llu (%.*s) on pid %d written to cache file %s\n", uwsgi.workers[0].requests, wsgi_req.uri_len, wsgi_req.uri, uwsgi.mypid, tmp_filename); 
     228        } 
     229#endif 
     230        Py_INCREF(Py_None); 
    231231        return Py_None; 
    232232} 
     
    235235PyObject *wsgi_spitout; 
    236236 
    237 PyObject *py_uwsgi_spit (PyObject * self, PyObject * args) { 
     237PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { 
    238238        PyObject *headers, *head; 
    239239        PyObject *h_key, *h_value; 
     
    249249 
    250250 
    251         head = PyTuple_GetItem (args, 0); 
     251        head = PyTuple_GetItem(args, 0); 
    252252        if (!head) { 
    253253                goto clear; 
    254254        } 
    255255 
    256         if (!PyString_Check (head)) { 
    257                 fprintf (stderr, "http status must be a string !\n"); 
     256        if (!PyString_Check(head)) { 
     257                fprintf(stderr, "http status must be a string !\n"); 
    258258                goto clear; 
    259259        } 
     
    278278                uwsgi.hvec[1].iov_len = 1; 
    279279#ifdef PYTHREE 
    280                 uwsgi.hvec[2].iov_base = PyBytes_AsString (PyUnicode_AsASCIIString (head)); 
    281                 uwsgi.hvec[2].iov_len = strlen (uwsgi.hvec[2].iov_base); 
     280                uwsgi.hvec[2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head)); 
     281                uwsgi.hvec[2].iov_len = strlen(uwsgi.hvec[2].iov_base); 
    282282#else 
    283                 uwsgi.hvec[2].iov_base = PyString_AsString (head); 
    284                 uwsgi.hvec[2].iov_len = PyString_Size (head); 
    285 #endif 
    286                 wsgi_req.status = atoi (uwsgi.hvec[2].iov_base); 
     283                uwsgi.hvec[2].iov_base = PyString_AsString(head); 
     284                uwsgi.hvec[2].iov_len = PyString_Size(head); 
     285#endif 
     286                wsgi_req.status = atoi(uwsgi.hvec[2].iov_base); 
    287287                uwsgi.hvec[3].iov_base = nl; 
    288288                uwsgi.hvec[3].iov_len = NL_SIZE; 
     
    295295                uwsgi.hvec[0].iov_len = 8; 
    296296#ifdef PYTHREE 
    297                 uwsgi.hvec[1].iov_base = PyBytes_AsString (PyUnicode_AsASCIIString (head)); 
    298                 uwsgi.hvec[1].iov_len = strlen (uwsgi.hvec[1].iov_base); 
     297                uwsgi.hvec[1].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(head)); 
     298                uwsgi.hvec[1].iov_len = strlen(uwsgi.hvec[1].iov_base); 
    299299#else 
    300                 uwsgi.hvec[1].iov_base = PyString_AsString (head); 
    301                 uwsgi.hvec[1].iov_len = PyString_Size (head); 
    302 #endif 
    303                 wsgi_req.status = atoi (uwsgi.hvec[1].iov_base); 
     300                uwsgi.hvec[1].iov_base = PyString_AsString(head); 
     301                uwsgi.hvec[1].iov_len = PyString_Size(head); 
     302#endif 
     303                wsgi_req.status = atoi(uwsgi.hvec[1].iov_base); 
    304304                uwsgi.hvec[2].iov_base = nl; 
    305305                uwsgi.hvec[2].iov_len = NL_SIZE; 
     
    311311        if (wsgi_req.unbit_flags & (unsigned long long) 1) { 
    312312                if (tmp_dir_fd >= 0 && tmp_filename[0] != 0 && wsgi_req.status == 200 && wsgi_req.method_len == 3 && wsgi_req.method[0] == 'G' && wsgi_req.method[1] == 'E' && wsgi_req.method[2] == 'T') { 
    313                         save_to_disk = openat (tmp_dir_fd, tmp_filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP); 
    314                 } 
    315         } 
    316 #endif 
    317  
    318  
    319         headers = PyTuple_GetItem (args, 1); 
     313                        save_to_disk = openat(tmp_dir_fd, tmp_filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP); 
     314                } 
     315        } 
     316#endif 
     317 
     318 
     319        headers = PyTuple_GetItem(args, 1); 
    320320        if (!headers) { 
    321321                goto clear; 
    322322        } 
    323         if (!PyList_Check (headers)) { 
    324                 fprintf (stderr, "http headers must be in a python list\n"); 
     323        if (!PyList_Check(headers)) { 
     324                fprintf(stderr, "http headers must be in a python list\n"); 
    325325                goto clear; 
    326326        } 
    327         wsgi_req.header_cnt = PyList_Size (headers); 
     327        wsgi_req.header_cnt = PyList_Size(headers); 
    328328 
    329329 
     
    334334        for (i = 0; i < wsgi_req.header_cnt; i++) { 
    335335                j = (i * 4) + base; 
    336                 head = PyList_GetItem (headers, i); 
     336                head = PyList_GetItem(headers, i); 
    337337                if (!head) { 
    338338                        goto clear; 
    339339                } 
    340                 if (!PyTuple_Check (head)) { 
    341                         fprintf (stderr, "http header must be defined in a tuple !\n"); 
     340                if (!PyTuple_Check(head)) { 
     341                        fprintf(stderr, "http header must be defined in a tuple !\n"); 
    342342                        goto clear; 
    343343                } 
    344                 h_key = PyTuple_GetItem (head, 0); 
     344                h_key = PyTuple_GetItem(head, 0); 
    345345                if (!h_key) { 
    346346                        goto clear; 
    347347                } 
    348                 h_value = PyTuple_GetItem (head, 1); 
     348                h_value = PyTuple_GetItem(head, 1); 
    349349                if (!h_value) { 
    350350                        goto clear; 
    351351                } 
    352352#ifdef PYTHREE 
    353                 uwsgi.hvec[j].iov_base = PyBytes_AsString (PyUnicode_AsASCIIString (h_key)); 
    354                 uwsgi.hvec[j].iov_len = strlen (uwsgi.hvec[j].iov_base); 
     353                uwsgi.hvec[j].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(h_key)); 
     354                uwsgi.hvec[j].iov_len = strlen(uwsgi.hvec[j].iov_base); 
    355355#else 
    356                 uwsgi.hvec[j].iov_base = PyString_AsString (h_key); 
    357                 uwsgi.hvec[j].iov_len = PyString_Size (h_key); 
     356                uwsgi.hvec[j].iov_base = PyString_AsString(h_key); 
     357                uwsgi.hvec[j].iov_len = PyString_Size(h_key); 
    358358#endif 
    359359                uwsgi.hvec[j + 1].iov_base = h_sep; 
    360360                uwsgi.hvec[j + 1].iov_len = H_SEP_SIZE; 
    361361#ifdef PYTHREE 
    362                 uwsgi.hvec[j + 2].iov_base = PyBytes_AsString (PyUnicode_AsASCIIString (h_value)); 
    363                 uwsgi.hvec[j + 2].iov_len = strlen (uwsgi.hvec[j + 2].iov_base); 
     362                uwsgi.hvec[j + 2].iov_base = PyBytes_AsString(PyUnicode_AsASCIIString(h_value)); 
     363                uwsgi.hvec[j + 2].iov_len = strlen(uwsgi.hvec[j + 2].iov_base); 
    364364#else 
    365                 uwsgi.hvec[j + 2].iov_base = PyString_AsString (h_value); 
    366                 uwsgi.hvec[j + 2].iov_len = PyString_Size (h_value); 
     365                uwsgi.hvec[j + 2].iov_base = PyString_AsString(h_value); 
     366                uwsgi.hvec[j + 2].iov_len = PyString_Size(h_value); 
    367367#endif 
    368368                uwsgi.hvec[j + 3].iov_base = nl; 
     
    375375        if (save_to_disk >= 0) { 
    376376                for (j = 0; j < i; j += 4) { 
    377                         if (!strncasecmp (uwsgi.hvec[j].iov_base, "Set-Cookie", uwsgi.hvec[j].iov_len)) { 
    378                                 close (save_to_disk); 
     377                        if (!strncasecmp(uwsgi.hvec[j].iov_base, "Set-Cookie", uwsgi.hvec[j].iov_len)) { 
     378                                close(save_to_disk); 
    379379                                save_to_disk = -1; 
    380380                                break; 
     
    389389        uwsgi.hvec[j].iov_len = NL_SIZE; 
    390390 
    391         wsgi_req.headers_size = writev (uwsgi.poll.fd, uwsgi.hvec, j + 1); 
     391        wsgi_req.headers_size = writev(uwsgi.poll.fd, uwsgi.hvec, j + 1); 
    392392        if (wsgi_req.headers_size < 0) { 
    393                 perror ("writev()"); 
    394         } 
    395         Py_INCREF (wsgi_writeout); 
     393                perror("writev()"); 
     394        } 
     395        Py_INCREF(wsgi_writeout); 
    396396 
    397397 
     
    400400      clear: 
    401401 
    402         Py_INCREF (Py_None); 
     402        Py_INCREF(Py_None); 
    403403        return Py_None; 
    404404} 
    405405 
    406406#ifdef UWSGI_SENDFILE 
    407 PyObject *py_uwsgi_sendfile (PyObject * self, PyObject * args) { 
    408  
    409         //PyObject *zero ; 
    410  
    411         uwsgi.py_sendfile = PyTuple_GetItem (args, 0); 
     407PyObject *py_uwsgi_sendfile(PyObject * self, PyObject * args) { 
     408 
     409        //PyObject *zero ; 
     410 
     411        uwsgi.py_sendfile = PyTuple_GetItem(args, 0); 
    412412 
    413413#ifdef PYTHREE 
    414         if ((wsgi_req.sendfile_fd = PyObject_AsFileDescriptor (uwsgi.py_sendfile)) >= 0) { 
    415                 Py_INCREF (uwsgi.py_sendfile); 
    416         } 
     414        if ((wsgi_req.sendfile_fd = PyObject_AsFileDescriptor(uwsgi.py_sendfile)) >= 0) { 
     415                Py_INCREF(uwsgi.py_sendfile); 
     416        } 
    417417#else 
    418         if (PyFile_Check (uwsgi.py_sendfile)) { 
    419                 //zero = PyFile_Name(uwsgi.py_sendfile) ; 
    420                 //fprintf(stderr,"->serving %s as static file...", PyString_AsString(zero)); 
    421                 wsgi_req.sendfile_fd = PyObject_AsFileDescriptor (uwsgi.py_sendfile); 
    422                 Py_INCREF (uwsgi.py_sendfile); 
    423         } 
    424 #endif 
    425  
    426  
    427         return PyTuple_New (0); 
     418        if (PyFile_Check(uwsgi.py_sendfile)) { 
     419                //zero = PyFile_Name(uwsgi.py_sendfile) ; 
     420                //fprintf(stderr,"->serving %s as static file...", PyString_AsString(zero)); 
     421                wsgi_req.sendfile_fd = PyObject_AsFileDescriptor(uwsgi.py_sendfile); 
     422                Py_INCREF(uwsgi.py_sendfile); 
     423        } 
     424#endif 
     425 
     426 
     427        return PyTuple_New(0); 
    428428} 
    429429#endif 
     
    461461} 
    462462 
    463 int main (int argc, char *argv[], char *envp[]) { 
    464  
    465         uint64_t master_cycles = 0 ; 
     463int main(int argc, char *argv[], char *envp[]) { 
     464 
     465        uint64_t master_cycles = 0; 
    466466        struct timeval check_interval = {.tv_sec = 1,.tv_usec = 0 }; 
    467467 
     
    474474 
    475475        struct sockaddr_un c_addr; 
    476         int c_len = sizeof (struct sockaddr_un); 
     476        int c_len = sizeof(struct sockaddr_un); 
    477477        int i; 
    478478        int ret; 
     
    481481 
    482482#ifdef UWSGI_NAGIOS 
    483         int nagios = 0 ; 
     483        int nagios = 0; 
    484484#endif 
    485485 
     
    489489#endif 
    490490 
    491         char *udp_socket = NULL; 
    492491        struct pollfd uwsgi_poll; 
    493492        struct sockaddr_in udp_client; 
     
    509508        int ready_to_die = 0; 
    510509 
    511         char *env_reloads ; 
     510        char *env_reloads; 
    512511        unsigned int reloads = 0; 
    513512        char env_reload_buf[11]; 
     
    522521 
    523522        /* anti signal bombing */ 
    524         signal (SIGHUP, SIG_IGN); 
    525         signal (SIGTERM, SIG_IGN); 
    526  
    527         memset (&uwsgi, 0, sizeof (struct uwsgi_server)); 
     523        signal(SIGHUP, SIG_IGN); 
     524        signal(SIGTERM, SIG_IGN); 
     525 
     526        memset(&uwsgi, 0, sizeof(struct uwsgi_server)); 
    528527 
    529528        /* generic shared area */ 
    530         uwsgi.shared = (struct uwsgi_shared *) mmap (NULL, sizeof (struct uwsgi_shared), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
     529        uwsgi.shared = (struct uwsgi_shared *) mmap(NULL, sizeof(struct uwsgi_shared), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
    531530        if (!uwsgi.shared) { 
    532                 perror ("mmap()"); 
    533                 exit (1); 
    534         } 
    535         memset (uwsgi.shared, 0, sizeof (struct uwsgi_shared)); 
    536  
    537         for(i=0;i<0xFF;i++) { 
     531                perror("mmap()"); 
     532                exit(1); 
     533        } 
     534        memset(uwsgi.shared, 0, sizeof(struct uwsgi_shared)); 
     535 
     536        for (i = 0; i < 0xFF; i++) { 
    538537                uwsgi.shared->hooks[i] = unconfigured_hook; 
    539538                uwsgi.shared->after_hooks[i] = unconfigured_after_hook; 
     
    598597                {"limit-as", required_argument, 0, LONG_ARGS_LIMIT_AS}, 
    599598                {"udp", required_argument, 0, LONG_ARGS_UDP}, 
     599                {"snmp", no_argument, &uwsgi.snmp, 1}, 
    600600                {"check-interval", required_argument, 0, LONG_ARGS_CHECK_INTERVAL}, 
    601601                {"erlang", required_argument, 0, LONG_ARGS_ERLANG}, 
     
    613613 
    614614 
    615         gettimeofday (&uwsgi.start_tv, NULL); 
    616  
    617         setlinebuf (stdout); 
     615        gettimeofday(&uwsgi.start_tv, NULL); 
     616 
     617        setlinebuf(stdout); 
    618618 
    619619        uwsgi.rl.rlim_cur = 0; 
     
    627627                reloads++; 
    628628                // convert reloads to string 
    629                 rlen = snprintf(env_reload_buf, 10, "%u", reloads) ; 
     629                rlen = snprintf(env_reload_buf, 10, "%u", reloads); 
    630630                if (rlen > 0) { 
    631                         env_reload_buf[rlen] = 0 ; 
    632                         if (setenv("UWSGI_RELOADS",env_reload_buf, 1)) { 
     631                        env_reload_buf[rlen] = 0; 
     632                        if (setenv("UWSGI_RELOADS", env_reload_buf, 1)) { 
    633633                                perror("setenv()"); 
    634634                        } 
     
    636636        } 
    637637        else { 
    638                 if (setenv("UWSGI_RELOADS","0", 1)) { 
     638                if (setenv("UWSGI_RELOADS", "0", 1)) { 
    639639                        perror("setenv()"); 
    640640                } 
    641641        } 
    642642 
    643         socket_type_len = sizeof (int); 
    644         if (!getsockopt (3, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) { 
    645                 if (socket_type == SOCK_STREAM && reloads > 0) {  
    646                         fprintf (stderr, "...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n"); 
     643        socket_type_len = sizeof(int); 
     644        if (!getsockopt(3, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) { 
     645                if (socket_type == SOCK_STREAM && reloads > 0) { 
     646                        fprintf(stderr, "...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n"); 
    647647                        uwsgi.is_a_reload = 1; 
    648648#ifdef UNBIT 
    649649                        /* discard the 3'th fd as we will use the fd 0 */ 
    650                         close (3); 
     650                        close(3); 
    651651#else 
    652652                        uwsgi.serverfd = 3; 
     
    655655        } 
    656656 
    657         uwsgi.binary_path = argv[0] ; 
     657        uwsgi.binary_path = argv[0]; 
    658658 
    659659#ifndef UNBIT 
    660         while ((i = getopt_long (argc, argv, "s:p:t:x:d:l:O:v:b:mcaCTPiMhrR:z:w:j:H:A:Q:L", long_options, &option_index)) != -1) { 
     660        while ((i = getopt_long(argc, argv, "s:p:t:x:d:l:O:v:b:mcaCTPiMhrR:z:w:j:H:A:Q:L", long_options, &option_index)) != -1) { 
    661661#else 
    662         while ((i = getopt (argc, argv, "p:t:mTPiv:b:rMR:Sz:w:C:j:H:A:EQ:L")) != -1) { 
     662        while ((i = getopt(argc, argv, "p:t:mTPiv:b:rMR:Sz:w:C:j:H:A:EQ:L")) != -1) { 
    663663#endif 
    664664                manage_opt(i, optarg); 
     
    667667 
    668668#ifdef UWSGI_XML 
    669         if (uwsgi.xml_config != NULL) { 
    670                 uwsgi_xml_config (&wsgi_req, long_options); 
    671         } 
     669        if (uwsgi.xml_config != NULL) { 
     670                uwsgi_xml_config(&wsgi_req, long_options); 
     671        } 
    672672#endif 
    673673 
    674674        if (uwsgi.binary_path == argv[0]) { 
    675                 cwd = uwsgi_get_cwd (); 
    676                 uwsgi.binary_path = malloc (strlen (argv[0]) + 1); 
     675                cwd = uwsgi_get_cwd(); 
     676                uwsgi.binary_path = malloc(strlen(argv[0]) + 1); 
    677677                if (uwsgi.binary_path == NULL) { 
    678                         perror ("malloc()"); 
    679                         exit (1); 
    680                 } 
    681                 strcpy (uwsgi.binary_path, argv[0]); 
     678                        perror("malloc()"); 
     679                        exit(1); 
     680                } 
     681                strcpy(uwsgi.binary_path, argv[0]); 
    682682        } 
    683683 
     
    686686#endif 
    687687                if (uwsgi.test_module == NULL) { 
    688                         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)); 
     688                        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)); 
    689689                } 
    690690#ifndef UNBIT 
    691691        } 
    692692        else { 
    693                 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)); 
     693                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)); 
    694694        } 
    695695#endif 
    696696 
    697697#ifdef __BIG_ENDIAN__ 
    698         fprintf (stderr, "*** big endian arch detected ***\n"); 
     698        fprintf(stderr, "*** big endian arch detected ***\n"); 
    699699#endif 
    700700 
    701701#ifdef PYTHREE 
    702         fprintf (stderr, "*** Warning Python3.x support is experimental, do not use it in production environment ***\n"); 
    703 #endif 
    704  
    705         fprintf (stderr, "Python version: %s\n", Py_GetVersion ()); 
     702        fprintf(stderr, "*** Warning Python3.x support is experimental, do not use it in production environment ***\n"); 
     703#endif 
     704 
     705        fprintf(stderr, "Python version: %s\n", Py_GetVersion()); 
    706706 
    707707#ifndef UNBIT 
    708         if (!getuid ()) { 
    709                 fprintf (stderr, "uWSGI running as root, you can use --uid/--gid/--chroot options\n"); 
     708        if (!getuid()) { 
     709                fprintf(stderr, "uWSGI running as root, you can use --uid/--gid/--chroot options\n"); 
    710710                if (uwsgi.chroot) { 
    711                         fprintf (stderr, "chroot() to %s\n", uwsgi.chroot); 
    712                         if (chroot (uwsgi.chroot)) { 
    713                                 perror ("chroot()"); 
    714                                 exit (1); 
     711                        fprintf(stderr, "chroot() to %s\n", uwsgi.chroot); 
     712                        if (chroot(uwsgi.chroot)) { 
     713                                perror("chroot()"); 
     714                                exit(1); 
    715715                        } 
    716716#ifdef __linux__ 
    717717                        if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG]) { 
    718                                 fprintf (stderr, "*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n"); 
     718                                fprintf(stderr, "*** Warning, on linux system you have to bind-mount the /proc fs in your chroot to get memory debug/report.\n"); 
    719719                        } 
    720720#endif 
    721721                } 
    722722                if (uwsgi.gid) { 
    723                         fprintf (stderr, "setgid() to %d\n", uwsgi.gid); 
    724                         if (setgid (uwsgi.gid)) { 
    725                                 perror ("setgid()"); 
    726                                 exit (1); 
     723                        fprintf(stderr, "setgid() to %d\n", uwsgi.gid); 
     724                        if (setgid(uwsgi.gid)) { 
     725                                perror("setgid()"); 
     726                                exit(1); 
    727727                        } 
    728728                } 
    729729                if (uwsgi.uid) { 
    730                         fprintf (stderr, "setuid() to %d\n", uwsgi.uid); 
    731                         if (setuid (uwsgi.uid)) { 
    732                                 perror ("setuid()"); 
    733                                 exit (1); 
     730                        fprintf(stderr, "setuid() to %d\n", uwsgi.uid); 
     731                        if (setuid(uwsgi.uid)) { 
     732                                perror("setuid()"); 
     733                                exit(1); 
    734734                        } 
    735735                } 
    736736 
    737737                if (!getuid()) { 
    738                         fprintf(stderr," *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** \n"); 
     738                        fprintf(stderr, " *** WARNING: you are running uWSGI as root !!! (use the --uid flag) *** \n"); 
    739739                } 
    740740        } 
    741741        else { 
    742742                if (uwsgi.chroot) { 
    743                         fprintf (stderr, "cannot chroot() as non-root user\n"); 
    744                         exit (1); 
     743                        fprintf(stderr, "cannot chroot() as non-root user\n"); 
     744                        exit(1); 
    745745                } 
    746746                if (uwsgi.gid) { 
    747                         fprintf (stderr, "cannot setgid() as non-root user\n"); 
    748                         exit (1); 
     747                        fprintf(stderr, "cannot setgid() as non-root user\n"); 
     748                        exit(1); 
    749749                } 
    750750                if (uwsgi.uid) { 
    751                         fprintf (stderr, "cannot setuid() as non-root user\n"); 
    752                         exit (1); 
    753                 } 
    754         } 
    755  
    756          
     751                        fprintf(stderr, "cannot setuid() as non-root user\n"); 
     752                        exit(1); 
     753                } 
     754        } 
     755 
     756 
    757757 
    758758#endif 
     
    760760#ifndef UNBIT 
    761761        if (uwsgi.rl.rlim_max > 0) { 
    762                 fprintf (stderr, "limiting address space of processes...\n"); 
    763                 if (setrlimit (RLIMIT_AS, &uwsgi.rl)) { 
    764                         perror ("setrlimit()"); 
    765                 } 
    766         } 
    767 #endif 
    768  
    769         if (!getrlimit (RLIMIT_AS, &uwsgi.rl)) { 
     762                fprintf(stderr, "limiting address space of processes...\n"); 
     763                if (setrlimit(RLIMIT_AS, &uwsgi.rl)) { 
     764                        perror("setrlimit()"); 
     765                } 
     766        } 
     767#endif 
     768 
     769        if (!getrlimit(RLIMIT_AS, &uwsgi.rl)) { 
    770770#ifndef UNBIT 
    771771                // check for overflow 
    772                 if ((sizeof (void *) == 4 && (uint32_t) uwsgi.rl.rlim_max < UINT32_MAX) || (sizeof (void *) == 8 && (uint64_t) uwsgi.rl.rlim_max < UINT64_MAX)) { 
    773 #endif 
    774                         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); 
     772                if ((sizeof(void *) == 4 && (uint32_t) uwsgi.rl.rlim_max < UINT32_MAX) || (sizeof(void *) == 8 && (uint64_t) uwsgi.rl.rlim_max < UINT64_MAX)) { 
     773#endif 
     774                        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); 
    775775#ifndef UNBIT 
    776776                } 
     
    778778        } 
    779779 
    780         uwsgi.page_size = getpagesize (); 
    781         fprintf (stderr, "your memory page size is %d bytes\n", uwsgi.page_size); 
     780        uwsgi.page_size = getpagesize(); 
     781        fprintf(stderr, "your memory page size is %d bytes\n", uwsgi.page_size); 
    782782 
    783783 
    784784        if (uwsgi.synclog) { 
    785                 fprintf (stderr, "allocating a memory page for synced logging.\n"); 
    786                 uwsgi.sync_page = malloc (uwsgi.page_size); 
     785                fprintf(stderr, "allocating a memory page for synced logging.\n"); 
     786                uwsgi.sync_page = malloc(uwsgi.page_size); 
    787787                if (!uwsgi.sync_page) { 
    788                         perror ("malloc()"); 
    789                         exit (1); 
     788                        perror("malloc()"); 
     789                        exit(1); 
    790790                } 
    791791        } 
    792792 
    793793        if (uwsgi.pyhome != NULL) { 
    794                 fprintf (stderr, "Setting PythonHome to %s...\n", uwsgi.pyhome); 
     794                fprintf(stderr, "Setting PythonHome to %s...\n", uwsgi.pyhome); 
    795795#ifdef PYTHREE 
    796796                wchar_t *wpyhome; 
    797                 wpyhome = malloc ((sizeof (wchar_t) * strlen (uwsgi.pyhome)) + 2); 
     797                wpyhome = malloc((sizeof(wchar_t) * strlen(uwsgi.pyhome)) + 2); 
    798798                if (!wpyhome) { 
    799                         perror ("malloc()"); 
    800                         exit (1); 
    801                 } 
    802                 mbstowcs (wpyhome, uwsgi.pyhome, strlen (uwsgi.pyhome)); 
    803                 Py_SetPythonHome (wpyhome); 
    804                 free (wpyhome); 
     799                        perror("malloc()"); 
     800                        exit(1); 
     801                } 
     802                mbstowcs(wpyhome, uwsgi.pyhome, strlen(uwsgi.pyhome)); 
     803                Py_SetPythonHome(wpyhome); 
     804                free(wpyhome); 
    805805#else 
    806                 Py_SetPythonHome (uwsgi.pyhome); 
     806                Py_SetPythonHome(uwsgi.pyhome); 
    807807#endif 
    808808        } 
     
    813813#ifdef PYTHREE 
    814814        wchar_t pname[6]; 
    815         mbstowcs (pname, "uWSGI", 6); 
    816         Py_SetProgramName (pname); 
     815        mbstowcs(pname, "uWSGI", 6); 
     816        Py_SetProgramName(pname); 
    817817#else 
    818         Py_SetProgramName ("uWSGI"); 
    819 #endif 
    820  
    821  
    822         Py_Initialize (); 
     818        Py_SetProgramName("uWSGI"); 
     819#endif 
     820 
     821 
     822        Py_Initialize(); 
    823823 
    824824        pyargv[0] = "uwsgi"; 
     
    826826        if (uwsgi.pyargv != NULL) { 
    827827                char *ap; 
    828                 while ((ap = strsep (&uwsgi.pyargv, " \t")) != NULL) { 
     828                while ((ap = strsep(&uwsgi.pyargv, " \t")) != NULL) { 
    829829                        if (*ap != '\0') { 
    830830                                pyargv[pyargc] = ap; 
     
    836836        } 
    837837 
    838         PySys_SetArgv (pyargc, pyargv); 
    839  
    840  
    841         uwsgi.py_apps = PyDict_New (); 
     838        PySys_SetArgv(pyargc, pyargv); 
     839 
     840 
     841        uwsgi.py_apps = PyDict_New(); 
    842842        if (!uwsgi.py_apps) { 
    843                 PyErr_Print (); 
    844                 exit (1); 
    845         } 
    846  
    847  
    848         wsgi_spitout = PyCFunction_New (uwsgi_spit_method, NULL); 
    849         wsgi_writeout = PyCFunction_New (uwsgi_write_method, NULL); 
     843                PyErr_Print(); 
     844                exit(1); 
     845        } 
     846 
     847 
     848        wsgi_spitout = PyCFunction_New(uwsgi_spit_method, NULL); 
     849        wsgi_writeout = PyCFunction_New(uwsgi_write_method, NULL); 
    850850 
    851851#ifdef UWSGI_EMBEDDED 
    852         uwsgi_module = Py_InitModule ("uwsgi", null_methods); 
     852        uwsgi_module = Py_InitModule("uwsgi", null_methods); 
    853853        if (uwsgi_module == NULL) { 
    854                 fprintf (stderr, "could not initialize the uwsgi python module\n"); 
    855                 exit (1); 
     854                fprintf(stderr, "could not initialize the uwsgi python module\n"); 
     855                exit(1); 
    856856        } 
    857857        if (uwsgi.sharedareasize > 0) { 
    858858#ifndef __OpenBSD__ 
    859                 uwsgi.sharedareamutex = mmap (NULL, sizeof (pthread_mutexattr_t) + sizeof (pthread_mutex_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
     859                uwsgi.sharedareamutex = mmap(NULL, sizeof(pthread_mutexattr_t) + sizeof(pthread_mutex_t), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
    860860                if (!uwsgi.sharedareamutex) { 
    861                         perror ("mmap()"); 
    862                         exit (1); 
     861                        perror("mmap()"); 
     862                        exit(1); 
    863863                } 
    864864#else 
    865                 fprintf (stderr, "***WARNING*** the sharedarea on OpenBSD is not SMP-safe. Beware of race conditions !!!\n"); 
    866 #endif 
    867                 uwsgi.sharedarea = mmap (NULL, uwsgi.page_size * uwsgi.sharedareasize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
     865                fprintf(stderr, "***WARNING*** the sharedarea on OpenBSD is not SMP-safe. Beware of race conditions !!!\n"); 
     866#endif 
     867                uwsgi.sharedarea = mmap(NULL, uwsgi.page_size * uwsgi.sharedareasize, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
    868868                if (uwsgi.sharedarea) { 
    869                         fprintf (stderr, "shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea); 
     869                        fprintf(stderr, "shared area mapped at %p, you can access it with uwsgi.sharedarea* functions.\n", uwsgi.sharedarea); 
    870870 
    871871#ifdef __APPLE__ 
    872                         memset (uwsgi.sharedareamutex, 0, sizeof (OSSpinLock)); 
     872                        memset(uwsgi.sharedareamutex, 0, sizeof(OSSpinLock)); 
    873873#else 
    874874#ifndef __OpenBSD__ 
    875                         if (pthread_mutexattr_init ((pthread_mutexattr_t *) uwsgi.sharedareamutex)) { 
    876                                 fprintf (stderr, "unable to allocate mutexattr structure\n"); 
    877                                 exit (1); 
    878                         } 
    879                         if (pthread_mutexattr_setpshared ((pthread_mutexattr_t *) uwsgi.sharedareamutex, PTHREAD_PROCESS_SHARED)) { 
    880                                 fprintf (stderr, "unable to share mutex\n"); 
    881                                 exit (1); 
    882                         } 
    883                         if (pthread_mutex_init ((pthread_mutex_t *) uwsgi.sharedareamutex + sizeof (pthread_mutexattr_t), (pthread_mutexattr_t *) uwsgi.sharedareamutex)) { 
    884                                 fprintf (stderr, "unable to initialize mutex\n"); 
    885                                 exit (1); 
     875                        if (pthread_mutexattr_init((pthread_mutexattr_t *) uwsgi.sharedareamutex)) { 
     876                                fprintf(stderr, "unable to allocate mutexattr structure\n"); 
     877                                exit(1); 
     878                        } 
     879                        if (pthread_mutexattr_setpshared((pthread_mutexattr_t *) uwsgi.sharedareamutex, PTHREAD_PROCESS_SHARED)) { 
     880                                fprintf(stderr, "unable to share mutex\n"); 
     881                                exit(1); 
     882                        } 
     883                        if (pthread_mutex_init((pthread_mutex_t *) uwsgi.sharedareamutex + sizeof(pthread_mutexattr_t), (pthread_mutexattr_t *) uwsgi.sharedareamutex)) { 
     884                                fprintf(stderr, "unable to initialize mutex\n"); 
     885                                exit(1); 
    886886                        } 
    887887#endif 
     
    890890                } 
    891891                else { 
    892                         perror ("mmap()"); 
    893                         exit (1); 
    894                 } 
    895  
    896         } 
    897  
    898         init_uwsgi_embedded_module (); 
     892                        perror("mmap()"); 
     893                        exit(1); 
     894                } 
     895 
     896        } 
     897 
     898        init_uwsgi_embedded_module(); 
    899899#endif 
    900900 
     
    904904 
    905905 
    906         wi = malloc (sizeof (struct uwsgi_app)); 
     906        wi = malloc(sizeof(struct uwsgi_app)); 
    907907        if (wi == NULL) { 
    908                 perror ("malloc()"); 
    909                 exit (1); 
    910         } 
    911         memset (wi, 0, sizeof (struct uwsgi_app)); 
     908                perror("malloc()"); 
     909                exit(1); 
     910        } 
     911        memset(wi, 0, sizeof(struct uwsgi_app)); 
    912912 
    913913        // load wsgi module/script 
    914914        for (i = optind; i < argc; i++) { 
    915                 init_uwsgi_vars (); 
    916                 wi->wsgi_module = PyImport_ImportModule (argv[i]); 
     915                init_uwsgi_vars(); 
     916                wi->wsgi_module = PyImport_ImportModule(argv[i]); 
    917917                if (!wi->wsgi_module) { 
    918                         PyErr_Print (); 
    919                         exit (1); 
    920                 } 
    921                 wi->wsgi_dict = PyModule_GetDict (wi->wsgi_module); 
     918                        PyErr_Print(); 
     919                        exit(1); 
     920                } 
     921                wi->wsgi_dict = PyModule_GetDict(wi->wsgi_module); 
    922922                if (!wi->wsgi_dict) { 
    923                         PyErr_Print (); 
    924                         exit (1); 
    925                 } 
    926                 wi->wsgi_callable = PyDict_GetItemString (wi->wsgi_dict, "application"); 
     923                        PyErr_Print(); 
     924                        exit(1); 
     925                } 
     926                wi->wsgi_callable = PyDict_GetItemString(wi->wsgi_dict, "application"); 
    927927                if (!wi->wsgi_callable) { 
    928                         PyErr_Print (); 
    929                         exit (1); 
    930                 } 
    931                 wi->wsgi_environ = PyDict_New (); 
     928                        PyErr_Print(); 
     929                        exit(1); 
     930                } 
     931                wi->wsgi_environ = PyDict_New(); 
    932932                if (!wi->wsgi_environ) { 
    933                         PyErr_Print (); 
    934                         exit (1); 
    935                 } 
    936  
    937                 wi->wsgi_harakiri = PyDict_GetItemString (wi->wsgi_dict, "harakiri"); 
    938  
    939                 wi->wsgi_args = PyTuple_New (2); 
     933                        PyErr_Print(); 
     934                        exit(1); 
     935                } 
     936 
     937                wi->wsgi_harakiri = PyDict_GetItemString(wi->wsgi_dict, "harakiri"); 
     938 
     939                wi->wsgi_args = PyTuple_New(2); 
    940940                if (!wi->wsgi_args) { 
    941                         PyErr_Print (); 
    942                         exit (1); 
    943                 } 
    944                 if (PyTuple_SetItem (wi->wsgi_args, 0, wi->wsgi_environ)) { 
    945                         PyErr_Print (); 
    946                         exit (1); 
    947                 } 
    948                 if (PyTuple_SetItem (wi->wsgi_args, 1, wsgi_spitout)) { 
    949                         PyErr_Print (); 
    950                         exit (1); 
     941                        PyErr_Print(); 
     942                        exit(1); 
     943                } 
     944                if (PyTuple_SetItem(wi->wsgi_args, 0, wi->wsgi_environ)) { 
     945                        PyErr_Print(); 
     946                        exit(1); 
     947                } 
     948                if (PyTuple_SetItem(wi->wsgi_args, 1, wsgi_spitout)) { 
     949                        PyErr_Print(); 
     950                        exit(1); 
    951951                } 
    952952                break; 
     
    954954 
    955955        if (!wi->wsgi_module) { 
    956                 fprintf (stderr, "unable to find the wsgi script. Have you specified it ?\n"); 
    957                 exit (1); 
     956                fprintf(stderr, "unable to find the wsgi script. Have you specified it ?\n"); 
     957                exit(1); 
    958958        } 
    959959#endif 
     
    961961        Py_OptimizeFlag = uwsgi.py_optimize; 
    962962 
    963         uwsgi.main_thread = PyThreadState_Get (); 
     963        uwsgi.main_thread = PyThreadState_Get(); 
    964964 
    965965 
    966966#ifdef UWSGI_THREADING 
    967967        if (uwsgi.has_threads) { 
    968                 PyEval_InitThreads (); 
    969                 fprintf (stderr, "threads support enabled\n"); 
     968                PyEval_InitThreads(); 
     969                fprintf(stderr, "threads support enabled\n"); 
    970970        } 
    971971 
     
    973973 
    974974        if (uwsgi.buffer_size > 65536) { 
    975                 fprintf (stderr, "invalid buffer size.\n"); 
    976                 exit (1); 
    977         } 
    978         uwsgi.buffer = malloc (uwsgi.buffer_size); 
     975                fprintf(stderr, "invalid buffer size.\n"); 
     976                exit(1); 
     977        } 
     978        uwsgi.buffer = malloc(uwsgi.buffer_size); 
    979979        if (uwsgi.buffer == NULL) { 
    980                 fprintf (stderr, "unable to allocate memory for buffer.\n"); 
    981                 exit (1); 
    982         } 
    983  
    984         fprintf (stderr, "request/response buffer (%d bytes) allocated.\n", uwsgi.buffer_size); 
     980                fprintf(stderr, "unable to allocate memory for buffer.\n"); 
     981                exit(1); 
     982        } 
     983 
     984        fprintf(stderr, "request/response buffer (%d bytes) allocated.\n", uwsgi.buffer_size); 
    985985 
    986986#ifdef UWSGI_NAGIOS 
     
    988988                // connect and send 
    989989                if (uwsgi.socket_name == NULL) { 
    990                         fprintf(stdout,"UWSGI UNKNOWN: you have specified an invalid socket\n"); 
     990                        fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n"); 
    991991                        exit(3); 
    992992                } 
    993                 char *tcp_port = strchr (uwsgi.socket_name, ':'); 
    994                 if (tcp_port == NULL) { 
    995                         fprintf(stdout,"UWSGI UNKNOWN: you have specified an invalid socket\n"); 
     993                char *tcp_port = strchr(uwsgi.socket_name, ':'); 
     994                if (tcp_port == NULL) { 
     995                        fprintf(stdout, "UWSGI UNKNOWN: you have specified an invalid socket\n"); 
    996996                        exit(3); 
    997997                } 
    998998 
    999                 tcp_port[0] = 0 ; 
    1000  
    1001                 uwsgi_poll.fd = connect_to_tcp(uwsgi.socket_name, atoi(tcp_port+1), uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); 
     999                tcp_port[0] = 0; 
     1000 
     1001                uwsgi_poll.fd = connect_to_tcp(uwsgi.socket_name, atoi(tcp_port + 1), uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT]); 
    10021002                if (uwsgi_poll.fd < 0) { 
    1003                         fprintf(stdout,"UWSGI CRITICAL: could not connect() to workers\n"); 
     1003                        fprintf(stdout, "UWSGI CRITICAL: could not connect() to workers\n"); 
    10041004                        exit(2); 
    10051005                } 
    1006                 wsgi_req.modifier = UWSGI_MODIFIER_PING ; 
    1007                 wsgi_req.size = 0 ; 
    1008                 wsgi_req.modifier_arg = 0 ; 
     1006                wsgi_req.modifier = UWSGI_MODIFIER_PING; 
     1007                wsgi_req.size = 0; 
     1008                wsgi_req.modifier_arg = 0; 
    10091009                if (write(uwsgi_poll.fd, &wsgi_req, 4) != 4) { 
    10101010                        perror("write()"); 
    1011                         fprintf(stdout,"UWSGI CRITICAL: could not send ping packet to workers\n"); 
     1011                        fprintf(stdout, "UWSGI CRITICAL: could not send ping packet to workers\n"); 
    10121012                        exit(2); 
    10131013                } 
    1014                 uwsgi_poll.events = POLLIN ; 
    1015                 if (!uwsgi_parse_response (&uwsgi_poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) &wsgi_req, uwsgi.buffer)) { 
    1016                         fprintf(stdout,"UWSGI CRITICAL: timed out waiting for response\n"); 
    1017                         exit(2);         
     1014                uwsgi_poll.events = POLLIN; 
     1015                if (!uwsgi_parse_response(&uwsgi_poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) &wsgi_req, uwsgi.buffer)) { 
     1016                        fprintf(stdout, "UWSGI CRITICAL: timed out waiting for response\n"); 
     1017                        exit(2); 
    10181018                } 
    10191019                else { 
    10201020                        if (wsgi_req.size > 0) { 
    1021                                 fprintf(stdout,"UWSGI WARNING: %.*s\n", wsgi_req.size, uwsgi.buffer);  
     1021                                fprintf(stdout, "UWSGI WARNING: %.*s\n", wsgi_req.size, uwsgi.buffer); 
    10221022                                exit(1); 
    10231023                        } 
    10241024                        else { 
    1025                                 fprintf(stdout,"UWSGI OK: armed and ready\n"); 
     1025                                fprintf(stdout, "UWSGI OK: armed and ready\n"); 
    10261026                                exit(0); 
    10271027                        } 
     
    10291029 
    10301030                // never here 
    1031                 fprintf(stdout,"UWSGI UNKNOWN: probably you hit a bug of uWSGI !!!\n"); 
     1031                fprintf(stdout, "UWSGI UNKNOWN: probably you hit a bug of uWSGI !!!\n"); 
    10321032                exit(3); 
    1033                  
     1033 
    10341034        } 
    10351035#endif 
     
    10391039                if (uwsgi.socket_name != NULL && !uwsgi.is_a_reload) { 
    10401040#ifdef UWSGI_SCTP 
    1041                         if (!strncmp (uwsgi.socket_name, "sctp:", 5)) { 
    1042                                 char *sctp_port = strchr (uwsgi.socket_name + 5, ':'); 
     1041                        if (!strncmp(uwsgi.socket_name, "sctp:", 5)) { 
     1042                                char *sctp_port = strchr(uwsgi.socket_name + 5, ':'); 
    10431043                                if (sctp_port == NULL) { 
    1044                                         fprintf (stderr, "invalid SCTP port ! syntax: sctp:ip1,ip2,ipN:port\n"); 
    1045                                         exit (1); 
     1044                                        fprintf(stderr, "invalid SCTP port ! syntax: sctp:ip1,ip2,ipN:port\n"); 
     1045                                        exit(1); 
    10461046                                } 
    1047                                 uwsgi.serverfd = bind_to_sctp (uwsgi.socket_name + 5, uwsgi.listen_queue, sctp_port); 
     1047                                uwsgi.serverfd = bind_to_sctp(uwsgi.socket_name + 5, uwsgi.listen_queue, sctp_port); 
    10481048                                i_am_sctp = 1; 
    10491049                        } 
    10501050                        else { 
    10511051#endif 
    1052                                 char *tcp_port = strchr (uwsgi.socket_name, ':'); 
     1052                                char *tcp_port = strchr(uwsgi.socket_name, ':'); 
    10531053                                if (tcp_port == NULL) { 
    1054                                         uwsgi.serverfd = bind_to_unix (uwsgi.socket_name, uwsgi.listen_queue, uwsgi.chmod_socket, uwsgi.abstract_socket); 
     1054                                        uwsgi.serverfd = bind_to_unix(uwsgi.socket_name, uwsgi.listen_queue, uwsgi.chmod_socket, uwsgi.abstract_socket); 
    10551055                                } 
    10561056                                else { 
    1057                                         uwsgi.serverfd = bind_to_tcp (uwsgi.socket_name, uwsgi.listen_queue, tcp_port); 
     1057                                        uwsgi.serverfd = bind_to_tcp(uwsgi.socket_name, uwsgi.listen_queue, tcp_port); 
    10581058                                } 
    10591059 
    10601060                                if (uwsgi.serverfd < 0) { 
    1061                                         fprintf (stderr, "unable to create the server socket.\n"); 
    1062                                         exit (1); 
     1061                                        fprintf(stderr, "unable to create the server socket.\n"); 
     1062                                        exit(1); 
    10631063                                } 
    10641064#ifdef UWSGI_SCTP 
     
    10681068#endif 
    10691069 
    1070                 socket_type_len = sizeof (int); 
    1071                 if (getsockopt (uwsgi.serverfd, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) { 
     1070                socket_type_len = sizeof(int); 
     1071                if (getsockopt(uwsgi.serverfd, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) { 
    10721072                        //perror ("getsockopt()"); 
    1073                         uwsgi.numproc = 0 ; 
     1073                        uwsgi.numproc = 0; 
    10741074                } 
    10751075 
     
    10891089#endif 
    10901090                fprintf(stderr, "The -s/--socket option is missing and stdin is not a socket.\n"); 
    1091                 exit (1); 
     1091                exit(1); 
    10921092        } 
    10931093 
     
    10951095 
    10961096#ifndef UNBIT 
    1097         fprintf (stderr, "your server socket listen backlog is limited to %d connections\n", uwsgi.listen_queue); 
     1097        fprintf(stderr, "your server socket listen backlog is limited to %d connections\n", uwsgi.listen_queue); 
    10981098#endif 
    10991099 
    11001100 
    11011101        if (uwsgi.single_interpreter == 1) { 
    1102                 init_uwsgi_vars (); 
    1103         } 
    1104  
    1105         memset (uwsgi.wsgi_apps, 0, sizeof (uwsgi.wsgi_apps)); 
     1102                init_uwsgi_vars(); 
     1103        } 
     1104 
     1105        memset(uwsgi.wsgi_apps, 0, sizeof(uwsgi.wsgi_apps)); 
    11061106 
    11071107 
     
    11091109        uwsgi.poll.events = POLLIN; 
    11101110 
    1111         memset (&wsgi_req, 0, sizeof (struct wsgi_request)); 
     1111        memset(&wsgi_req, 0, sizeof(struct wsgi_request)); 
    11121112 
    11131113        /* shared area for workers */ 
    1114         uwsgi.workers = (struct uwsgi_worker *) mmap (NULL, sizeof (struct uwsgi_worker) * uwsgi.numproc + 1, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
     1114        uwsgi.workers = (struct uwsgi_worker *) mmap(NULL, sizeof(struct uwsgi_worker) * uwsgi.numproc + 1, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, -1, 0); 
    11151115        if (!uwsgi.workers) { 
    1116                 perror ("mmap()"); 
    1117                 exit (1); 
    1118         } 
    1119         memset (uwsgi.workers, 0, sizeof (struct uwsgi_worker) * uwsgi.numproc + 1); 
    1120  
    1121         uwsgi.mypid = getpid (); 
     1116                perror("mmap()"); 
     1117                exit(1); 
     1118        } 
     1119        memset(uwsgi.workers, 0, sizeof(struct uwsgi_worker) * uwsgi.numproc + 1); 
     1120 
     1121        uwsgi.mypid = getpid(); 
    11221122        masterpid = uwsgi.mypid; 
    11231123 
    11241124#ifndef UNBIT 
    11251125        if (uwsgi.pidfile) { 
    1126                 fprintf (stderr, "writing pidfile to %s\n", uwsgi.pidfile); 
    1127                 pidfile = fopen (uwsgi.pidfile, "w"); 
     1126                fprintf(stderr, "writing pidfile to %s\n", uwsgi.pidfile); 
     1127                pidfile = fopen(uwsgi.pidfile, "w"); 
    11281128                if (!pidfile) { 
    1129                         perror ("fopen"); 
    1130                         exit (1); 
    1131                 } 
    1132                 if (fprintf (pidfile, "%d\n", masterpid) < 0) { 
    1133                         fprintf (stderr, "could not write pidfile.\n"); 
    1134                 } 
    1135                 fclose (pidfile); 
     1129                        perror("fopen"); 
     1130                        exit(1); 
     1131                } 
     1132                if (fprintf(pidfile, "%d\n", masterpid) < 0) { 
     1133                        fprintf(stderr, "could not write pidfile.\n"); 
     1134                } 
     1135                fclose(pidfile); 
    11361136        } 
    11371137#endif 
     
    11411141        uwsgi.workers[0].pid = masterpid; 
    11421142 
    1143         fprintf(stderr,"initializing hooks..."); 
    1144  
    1145         uwsgi.shared->hooks[0] = uwsgi_request_wsgi ;  
    1146         uwsgi.shared->after_hooks[0] = uwsgi_after_request_wsgi ;  
    1147  
    1148         uwsgi.shared->hooks[UWSGI_MODIFIER_ADMIN_REQUEST] = uwsgi_request_admin ; //10 
     1143        fprintf(stderr, "initializing hooks..."); 
     1144 
     1145        uwsgi.shared->hooks[0] = uwsgi_request_wsgi; 
     1146        uwsgi.shared->after_hooks[0] = uwsgi_after_request_wsgi; 
     1147 
     1148        uwsgi.shared->hooks[UWSGI_MODIFIER_ADMIN_REQUEST] = uwsgi_request_admin;        //10 
    11491149#ifdef UWSGI_SPOOLER 
    1150         uwsgi.shared->hooks[UWSGI_MODIFIER_SPOOL_REQUEST] = uwsgi_request_spooler ; //17 
    1151 #endif 
    1152         uwsgi.shared->hooks[UWSGI_MODIFIER_FASTFUNC] = uwsgi_request_fastfunc ; //26 
    1153  
    1154         uwsgi.shared->hooks[UWSGI_MODIFIER_MANAGE_PATH_INFO] = uwsgi_request_wsgi ; // 30 
    1155         uwsgi.shared->after_hooks[UWSGI_MODIFIER_MANAGE_PATH_INFO] = uwsgi_after_request_wsgi; // 30 
    1156  
    1157         uwsgi.shared->hooks[UWSGI_MODIFIER_MESSAGE_MARSHAL] = uwsgi_request_marshal ; //33 
    1158         uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping ; //100 
    1159  
    1160         fprintf(stderr,"done.\n"); 
     1150        uwsgi.shared->hooks[UWSGI_MODIFIER_SPOOL_REQUEST] = uwsgi_request_spooler;      //17 
     1151#endif 
     1152        uwsgi.shared->hooks[UWSGI_MODIFIER_FASTFUNC] = uwsgi_request_fastfunc//26 
     1153 
     1154        uwsgi.shared->hooks[UWSGI_MODIFIER_MANAGE_PATH_INFO] = uwsgi_request_wsgi;      // 30 
     1155        uwsgi.shared->after_hooks[UWSGI_MODIFIER_MANAGE_PATH_INFO] = uwsgi_after_request_wsgi;  // 30 
     1156 
     1157        uwsgi.shared->hooks[UWSGI_MODIFIER_MESSAGE_MARSHAL] = uwsgi_request_marshal;    //33 
     1158        uwsgi.shared->hooks[UWSGI_MODIFIER_PING] = uwsgi_request_ping//100 
     1159 
     1160        fprintf(stderr, "done.\n"); 
    11611161 
    11621162#ifdef UWSGI_ERLANG 
     
    11701170 
    11711171        if (uwsgi.wsgi_config != NULL) { 
    1172                 uwsgi_wsgi_config (); 
     1172                uwsgi_wsgi_config(); 
    11731173        } 
    11741174        else if (uwsgi.wsgi_file != NULL) { 
    1175                 uwsgi_wsgi_file_config(); 
    1176         } 
     1175                uwsgi_wsgi_file_config(); 
     1176        } 
    11771177#ifdef UWSGI_XML 
    11781178        else if (uwsgi.xml_config != NULL) { 
    1179                 uwsgi_xml_config (&wsgi_req, NULL); 
     1179                uwsgi_xml_config(&wsgi_req, NULL); 
    11801180        } 
    11811181#endif 
     
    11831183#ifdef UWSGI_PASTE 
    11841184        else if (uwsgi.paste != NULL) { 
    1185                 uwsgi_paste_config (); 
     1185                uwsgi_paste_config(); 
    11861186        } 
    11871187#endif 
    11881188 
    11891189        if (uwsgi.test_module != NULL) { 
    1190                 if (PyImport_ImportModule (uwsgi.test_module)) { 
    1191                         exit (0); 
    1192                 } 
    1193                 exit (1); 
     1190                if (PyImport_ImportModule(uwsgi.test_module)) { 
     1191                        exit(0); 
     1192                } 
     1193                exit(1); 
    11941194        } 
    11951195 
     
    11981198#ifndef UNBIT 
    11991199        if (no_server) { 
    1200                 fprintf (stderr, "no-server mode requested. Goodbye.\n"); 
    1201                 exit (0); 
     1200                fprintf(stderr, "no-server mode requested. Goodbye.\n"); 
     1201                exit(0); 
    12021202        } 
    12031203#endif 
     
    12101210 
    12111211        if (!uwsgi.single_interpreter) { 
    1212                 fprintf(stderr,"*** uWSGI is running in multiple interpreter mode !!! ***\n"); 
     1212                fprintf(stderr, "*** uWSGI is running in multiple interpreter mode !!! ***\n"); 
    12131213        } 
    12141214 
     
    12161216        if (uwsgi.master_process) { 
    12171217                if (uwsgi.is_a_reload) { 
    1218                         fprintf (stderr, "gracefully (RE)spawned uWSGI master process (pid: %d)\n", uwsgi.mypid); 
     1218                        fprintf(stderr, "gracefully (RE)spawned uWSGI master process (pid: %d)\n", uwsgi.mypid); 
    12191219                } 
    12201220                else { 
    1221                         fprintf (stderr, "spawned uWSGI master process (pid: %d)\n", uwsgi.mypid); 
     1221                        fprintf(stderr, "spawned uWSGI master process (pid: %d)\n", uwsgi.mypid); 
    12221222                } 
    12231223        } 
     
    12251225#ifdef UNBIT 
    12261226        if (single_app_mode == 1) { 
    1227                 wsgi_req.wsgi_script = getenv ("UWSGI_SCRIPT"); 
     1227                wsgi_req.wsgi_script = getenv("UWSGI_SCRIPT"); 
    12281228                if (wsgi_req.wsgi_script) { 
    1229                         wsgi_req.wsgi_script_len = strlen (wsgi_req.wsgi_script); 
     1229                        wsgi_req.wsgi_script_len = strlen(wsgi_req.wsgi_script); 
    12301230                } 
    12311231                else { 
    1232                         fprintf (stderr, "UWSGI_SCRIPT env var not set !\n"); 
    1233                         exit (1); 
    1234                 } 
    1235  
    1236                 init_uwsgi_app (NULL, NULL); 
     1232                        fprintf(stderr, "UWSGI_SCRIPT env var not set !\n"); 
     1233                        exit(1); 
     1234                } 
     1235 
     1236                init_uwsgi_app(NULL, NULL); 
    12371237        } 
    12381238#endif 
     
    12401240#ifdef UWSGI_SPOOLER 
    12411241        if (spool_dir != NULL && uwsgi.numproc > 0) { 
    1242                 uwsgi.shared->spooler_pid = spooler_start (uwsgi.serverfd, uwsgi_module); 
     1242                uwsgi.shared->spooler_pid = spooler_start(uwsgi.serverfd, uwsgi_module); 
    12431243        } 
    12441244#endif 
     
    12471247        if (!uwsgi.master_process) { 
    12481248                if (uwsgi.numproc == 1) { 
    1249                         fprintf (stderr, "spawned uWSGI worker 1 (and the only) (pid: %d)\n", masterpid); 
     1249                        fprintf(stderr, "spawned uWSGI worker 1 (and the only) (pid: %d)\n", masterpid); 
    12501250                } 
    12511251                else { 
    1252                         fprintf (stderr, "spawned uWSGI worker 1 (pid: %d)\n", masterpid); 
     1252                        fprintf(stderr, "spawned uWSGI worker 1 (pid: %d)\n", masterpid); 
    12531253                } 
    12541254                uwsgi.workers[1].pid = masterpid; 
    12551255                uwsgi.workers[1].id = 1; 
    1256                 uwsgi.workers[1].last_spawn = time (NULL); 
     1256                uwsgi.workers[1].last_spawn = time(NULL); 
    12571257                uwsgi.workers[1].manage_next_request = 1; 
    12581258#ifdef UWSGI_THREADING 
     
    12601260#endif 
    12611261                uwsgi.mywid = 1; 
    1262                 gettimeofday (&last_respawn, NULL); 
     1262                gettimeofday(&last_respawn, NULL); 
    12631263                respawn_delta = last_respawn.tv_sec; 
    12641264        } 
    12651265 
    12661266 
    1267                 for (i = 2-uwsgi.master_process ; i < uwsgi.numproc + 1; i++) { 
    1268                         /* let the worker know his worker_id (wid) */ 
    1269                         pid = fork (); 
    1270                         if (pid == 0) { 
    1271                                 uwsgi.mypid = getpid (); 
    1272                                 uwsgi.workers[i].pid = uwsgi.mypid; 
    1273                                 uwsgi.workers[i].id = i; 
    1274                                 uwsgi.workers[i].last_spawn = time (NULL); 
    1275                                 uwsgi.workers[i].manage_next_request = 1; 
     1267        for (i = 2 - uwsgi.master_process; i < uwsgi.numproc + 1; i++) { 
     1268                /* let the worker know his worker_id (wid) */ 
     1269                pid = fork(); 
     1270                if (pid == 0) { 
     1271                        uwsgi.mypid = getpid(); 
     1272                        uwsgi.workers[i].pid = uwsgi.mypid; 
     1273                        uwsgi.workers[i].id = i; 
     1274                        uwsgi.workers[i].last_spawn = time(NULL); 
     1275                        uwsgi.workers[i].manage_next_request = 1; 
    12761276#ifdef UWSGI_THREADING 
    1277                                 uwsgi.workers[i].i_have_gil = 1; 
    1278 #endif 
    1279                                 uwsgi.mywid = i; 
    1280                                 if (uwsgi.serverfd != 0 && uwsgi.master_process == 1) { 
    1281                                         /* close STDIN for workers */ 
    1282                                         close (0); 
    1283                                 } 
    1284                                 break; 
    1285                         } 
    1286                         else if (pid < 1) { 
    1287                                 perror ("fork()"); 
    1288                                 exit (1); 
    1289                         } 
    1290                         else { 
    1291                                 fprintf (stderr, "spawned uWSGI worker %d (pid: %d)\n", i, pid); 
    1292                                 gettimeofday (&last_respawn, NULL); 
    1293                                 respawn_delta = last_respawn.tv_sec; 
    1294                         } 
    1295                 } 
    1296  
    1297  
    1298         if (getpid () == masterpid && uwsgi.master_process == 1) { 
     1277                        uwsgi.workers[i].i_have_gil = 1; 
     1278#endif 
     1279                        uwsgi.mywid = i; 
     1280                        if (uwsgi.serverfd != 0 && uwsgi.master_process == 1) { 
     1281                                /* close STDIN for workers */ 
     1282                                close(0); 
     1283                        } 
     1284                        break; 
     1285                } 
     1286                else if (pid < 1) { 
     1287                        perror("fork()"); 
     1288                        exit(1); 
     1289                } 
     1290                else { 
     1291                        fprintf(stderr, "spawned uWSGI worker %d (pid: %d)\n", i, pid); 
     1292                        gettimeofday(&last_respawn, NULL); 
     1293                        respawn_delta = last_respawn.tv_sec; 
     1294                } 
     1295        } 
     1296 
     1297 
     1298        if (getpid() == masterpid && uwsgi.master_process == 1) { 
    12991299                /* route signals to workers... */ 
    1300                 signal (SIGHUP, (void *) &grace_them_all); 
    1301                 signal (SIGTERM, (void *) &reap_them_all); 
    1302                 signal (SIGINT, (void *) &kill_them_all); 
    1303                 signal (SIGQUIT, (void *) &kill_them_all); 
     1300                signal(SIGHUP, (void *) &grace_them_all); 
     1301                signal(SIGTERM, (void *) &reap_them_all); 
     1302                signal(SIGINT, (void *) &kill_them_all); 
     1303                signal(SIGQUIT, (void *) &kill_them_all); 
    13041304                /* used only to avoid human-errors */ 
    13051305#ifndef UNBIT 
    1306                 signal (SIGUSR1, (void *) &stats); 
    1307 #endif 
    1308  
    1309                 if (udp_socket) { 
    1310                         uwsgi_poll.fd = bind_to_udp (udp_socket); 
     1306                signal(SIGUSR1, (void *) &stats); 
     1307#endif 
     1308 
     1309                if (uwsgi.udp_socket) { 
     1310                        uwsgi_poll.fd = bind_to_udp(uwsgi.udp_socket); 
    13111311                        if (uwsgi_poll.fd < 0) { 
    1312                                 fprintf (stderr, "unable to bind to udp socket. SNMP and cluster management services will be disabled.\n"); 
     1312                                fprintf(stderr, "unable to bind to udp socket. SNMP and cluster management services will be disabled.\n"); 
    13131313                        } 
    13141314                        else { 
    1315                                 fprintf (stderr, "UDP server enabled.\n"); 
     1315                                fprintf(stderr, "UDP server enabled.\n"); 
    13161316                                uwsgi_poll.events = POLLIN; 
    13171317                        } 
     
    13211321#ifdef UWSGI_SPOOLER 
    13221322                                if (spool_dir && uwsgi.shared->spooler_pid > 0) { 
    1323                                         kill (uwsgi.shared->spooler_pid, SIGKILL); 
    1324                                         fprintf(stderr,"killed the spooler with pid %d\n", uwsgi.shared->spooler_pid); 
     1323                                        kill(uwsgi.shared->spooler_pid, SIGKILL); 
     1324                                        fprintf(stderr, "killed the spooler with pid %d\n", uwsgi.shared->spooler_pid); 
    13251325                                } 
    13261326 
     
    13291329#ifdef UWSGI_PROXY 
    13301330                                if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { 
    1331                                         kill (uwsgi.shared->proxy_pid, SIGKILL); 
    1332                                         fprintf(stderr,"killed proxy with pid %d\n", uwsgi.shared->proxy_pid); 
     1331                                        kill(uwsgi.shared->proxy_pid, SIGKILL); 
     1332                                        fprintf(stderr, "killed proxy with pid %d\n", uwsgi.shared->proxy_pid); 
    13331333                                } 
    13341334#endif 
    1335                                 fprintf (stderr, "goodbye to uWSGI.\n"); 
    1336                                 exit (0); 
     1335                                fprintf(stderr, "goodbye to uWSGI.\n"); 
     1336                                exit(0); 
    13371337                        } 
    13381338                        if (ready_to_reload >= uwsgi.numproc && uwsgi.to_heaven) { 
    13391339#ifdef UWSGI_SPOOLER 
    13401340                                if (spool_dir && uwsgi.shared->spooler_pid > 0) { 
    1341                                         kill (uwsgi.shared->spooler_pid, SIGKILL); 
    1342                                         fprintf(stderr,"wait4() the spooler with pid %d...", uwsgi.shared->spooler_pid); 
    1343                                         diedpid = waitpid(uwsgi.shared->spooler_pid, &waitpid_status, 0); 
    1344                                         fprintf(stderr,"done."); 
     1341                                        kill(uwsgi.shared->spooler_pid, SIGKILL); 
     1342                                        fprintf(stderr, "wait4() the spooler with pid %d...", uwsgi.shared->spooler_pid); 
     1343                                        diedpid = waitpid(uwsgi.shared->spooler_pid, &waitpid_status, 0); 
     1344                                        fprintf(stderr, "done."); 
    13451345                                } 
    13461346#endif 
     
    13481348#ifdef UWSGI_PROXY 
    13491349                                if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { 
    1350                                         kill (uwsgi.shared->proxy_pid, SIGKILL); 
    1351                                         fprintf(stderr,"wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid); 
    1352                                         diedpid = waitpid(uwsgi.shared->proxy_pid, &waitpid_status, 0); 
    1353                                         fprintf(stderr,"done."); 
     1350                                        kill(uwsgi.shared->proxy_pid, SIGKILL); 
     1351                                        fprintf(stderr, "wait4() the proxy with pid %d...", uwsgi.shared->proxy_pid); 
     1352                                        diedpid = waitpid(uwsgi.shared->proxy_pid, &waitpid_status, 0); 
     1353                                        fprintf(stderr, "done."); 
    13541354                                } 
    13551355#endif 
    1356                                 fprintf (stderr, "binary reloading uWSGI...\n"); 
     1356                                fprintf(stderr, "binary reloading uWSGI...\n"); 
    13571357                                if (cwd) { 
    1358                                         if (chdir (cwd)) { 
    1359                                                 perror ("chdir()"); 
    1360                                                 exit (1); 
     1358                                        if (chdir(cwd)) { 
     1359                                                perror("chdir()"); 
     1360                                                exit(1); 
    13611361                                        } 
    13621362                                } 
    13631363                                /* check fd table (a module can obviosly open some fd on initialization...) */ 
    1364                                 fprintf (stderr, "closing all fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf (_SC_OPEN_MAX)); 
    1365                                 for (i = 3; i < sysconf (_SC_OPEN_MAX); i++) { 
     1364                                fprintf(stderr, "closing all fds > 2 (_SC_OPEN_MAX = %ld)...\n", sysconf(_SC_OPEN_MAX)); 
     1365                                for (i = 3; i < sysconf(_SC_OPEN_MAX); i++) { 
    13661366                                        if (i == uwsgi.serverfd) { 
    13671367                                                continue; 
    13681368                                        } 
    1369                                         close (i); 
     1369                                        close(i); 
    13701370                                } 
    13711371                                if (uwsgi.serverfd != 3) { 
    1372                                         if (dup2 (uwsgi.serverfd, 3) < 0) { 
    1373                                                 perror ("dup2()"); 
    1374                                                 exit (1); 
     1372                                        if (dup2(uwsgi.serverfd, 3) < 0) { 
     1373                                                perror("dup2()"); 
     1374                                                exit(1); 
    13751375                                        } 
    13761376                                } 
    1377                                 fprintf (stderr, "running %s\n", uwsgi.binary_path); 
    1378                                 argv[0] = uwsgi.binary_path ; 
     1377                                fprintf(stderr, "running %s\n", uwsgi.binary_path); 
     1378                                argv[0] = uwsgi.binary_path; 
    13791379                                //strcpy (argv[0], uwsgi.binary_path); 
    1380                                 execve (uwsgi.binary_path, argv, environ); 
    1381                                 perror ("execve()"); 
     1380                                execve(uwsgi.binary_path, argv, environ); 
     1381                                perror("execve()"); 
    13821382                                // never here 
    1383                                 exit (1); 
    1384                         } 
    1385                         diedpid = waitpid (WAIT_ANY, &waitpid_status, WNOHANG); 
     1383                                exit(1); 
     1384                        } 
     1385                        diedpid = waitpid(WAIT_ANY, &waitpid_status, WNOHANG); 
    13861386                        if (diedpid == -1) { 
    1387                                 perror ("waitpid()"); 
     1387                                perror("waitpid()"); 
    13881388                                /* here is better to reload all the uWSGI stack */ 
    1389                                 fprintf (stderr, "something horrible happened...\n"); 
    1390                                 reap_them_all (); 
    1391                                 exit (1); 
     1389                                fprintf(stderr, "something horrible happened...\n"); 
     1390                                reap_them_all(); 
     1391                                exit(1); 
    13921392                        } 
    13931393                        else if (diedpid == 0) { 
     
    13971397#ifdef UWSGI_THREADING 
    13981398                                if (uwsgi.has_threads && uwsgi.shared->options[UWSGI_OPTION_THREADS] == 1) { 
    1399                                         uwsgi._save = PyEval_SaveThread (); 
     1399                                        uwsgi._save = PyEval_SaveThread(); 
    14001400                                        uwsgi.workers[uwsgi.mywid].i_have_gil = 0; 
    14011401                                } 
     
    14051405                                if (!check_interval.tv_sec) 
    14061406                                        check_interval.tv_sec = 1; 
    1407                                  
    1408                                 if (udp_socket && uwsgi_poll.fd >= 0) { 
    1409                                         rlen = poll (&uwsgi_poll, 1, check_interval.tv_sec * 1000); 
     1407 
     1408                                if (uwsgi.udp_socket && uwsgi_poll.fd >= 0) { 
     1409                                        rlen = poll(&uwsgi_poll, 1, check_interval.tv_sec * 1000); 
    14101410                                        if (rlen < 0) { 
    1411                                                 perror ("poll()"); 
     1411                                                perror("poll()"); 
    14121412                                        } 
    14131413                                        else if (rlen > 0) { 
    1414                                                 udp_len = sizeof (udp_client); 
    1415                                                 rlen = recvfrom (uwsgi_poll.fd, uwsgi.buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len); 
     1414                                                udp_len = sizeof(udp_client); 
     1415                                                rlen = recvfrom(uwsgi_poll.fd, uwsgi.buffer, uwsgi.buffer_size, 0, (struct sockaddr *) &udp_client, &udp_len); 
    14161416                                                if (rlen < 0) { 
    1417                                                         perror ("recvfrom()"); 
     1417                                                        perror("recvfrom()"); 
    14181418                                                } 
    14191419                                                else if (rlen > 0) { 
    1420                                                         memset (udp_client_addr, 0, 16); 
    1421                                                         if (inet_ntop (AF_INET, &udp_client.sin_addr.s_addr, udp_client_addr, 16)) { 
    1422                                                                 fprintf (stderr, "received udp packet of %d bytes from %s:%d\n", rlen, udp_client_addr, ntohs (udp_client.sin_port)); 
     1420                                                        memset(udp_client_addr, 0, 16); 
     1421                                                        if (inet_ntop(AF_INET, &udp_client.sin_addr.s_addr, udp_client_addr, 16)) { 
     1422                                                                fprintf(stderr, "received udp packet of %d bytes from %s:%d\n", rlen, udp_client_addr, ntohs(udp_client.sin_port)); 
    14231423#ifdef UWSGI_SNMP 
    1424                                                                 if (uwsgi.buffer[0] == 0x30) { 
    1425                                                                         manage_snmp (uwsgi_poll.fd, (uint8_t *) uwsgi.buffer, rlen, &udp_client); 
     1424                                                                if (uwsgi.buffer[0] == 0x30 && uwsgi.snmp) { 
     1425                                                                        manage_snmp(uwsgi_poll.fd, (uint8_t *) uwsgi.buffer, rlen, &udp_client); 
    14261426                                                                } 
    14271427#endif 
    14281428                                                        } 
    14291429                                                        else { 
    1430                                                                 perror ("inet_ntop()"); 
     1430                                                                perror("inet_ntop()"); 
    14311431                                                        } 
    14321432                                                } 
     
    14341434                                } 
    14351435                                else { 
    1436                                         select (0, NULL, NULL, NULL, &check_interval); 
     1436                                        select(0, NULL, NULL, NULL, &check_interval); 
    14371437                                } 
    14381438                                master_cycles++; 
     
    14411441#ifdef UWSGI_THREADING 
    14421442                                if (uwsgi.has_threads && !uwsgi.workers[uwsgi.mywid].i_have_gil) { 
    1443                                         PyEval_RestoreThread (uwsgi._save); 
     1443                                        PyEval_RestoreThread(uwsgi._save); 
    14441444                                        uwsgi.workers[uwsgi.mywid].i_have_gil = 1; 
    14451445                                } 
     
    14511451                                        /* first check for harakiri */ 
    14521452                                        if (uwsgi.workers[i].harakiri > 0) { 
    1453                                                 if (uwsgi.workers[i].harakiri < time (NULL)) { 
     1453                                                if (uwsgi.workers[i].harakiri < time(NULL)) { 
    14541454                                                        /* first try to invoke the harakiri() custom handler */ 
    14551455                                                        /* TODO */ 
    14561456                                                        /* then brutally kill the worker */ 
    1457                                                         kill (uwsgi.workers[i].pid, SIGKILL); 
     1457                                                        kill(uwsgi.workers[i].pid, SIGKILL); 
    14581458                                                } 
    14591459                                        } 
     
    14691469 
    14701470                                // check for cluster nodes 
    1471                                 for(i=0;i<MAX_CLUSTER_NODES;i++) { 
     1471                                for (i = 0; i < MAX_CLUSTER_NODES; i++) { 
    14721472                                        struct uwsgi_cluster_node *ucn = &uwsgi.shared->nodes[i]; 
    1473                                          
     1473 
    14741474                                        if (ucn->name[0] != 0 && ucn->status == UWSGI_NODE_FAILED) { 
    14751475                                                // should i retry ? 
    14761476                                                if (master_cycles % ucn->errors == 0) { 
    14771477                                                        if (!uwsgi_ping_node(i, &wsgi_req)) { 
    1478                                                                 ucn->status = UWSGI_NODE_OK ; 
    1479                                                                 fprintf(stderr,"re-enabled cluster node %d/%s\n", i, ucn->name); 
     1478                                                                ucn->status = UWSGI_NODE_OK; 
     1479                                                                fprintf(stderr, "re-enabled cluster node %d/%s\n", i, ucn->name); 
    14801480                                                        } 
    14811481                                                        else { 
     
    14931493                        if (spool_dir && uwsgi.shared->spooler_pid > 0) { 
    14941494                                if (diedpid == uwsgi.shared->spooler_pid) { 
    1495                                         fprintf(stderr,"OOOPS the spooler is no more...trying respawn...\n"); 
    1496                                         uwsgi.shared->spooler_pid = spooler_start (uwsgi.serverfd, uwsgi_module); 
     1495                                        fprintf(stderr, "OOOPS the spooler is no more...trying respawn...\n"); 
     1496                                        uwsgi.shared->spooler_pid = spooler_start(uwsgi.serverfd, uwsgi_module); 
    14971497                                        continue; 
    14981498                                } 
     
    15041504                        if (uwsgi.proxy_socket_name && uwsgi.shared->proxy_pid > 0) { 
    15051505                                if (diedpid == uwsgi.shared->proxy_pid) { 
    1506                                         if (WIFEXITED (waitpid_status)) { 
    1507                                                 if (WEXITSTATUS (waitpid_status) != UWSGI_END_CODE) {    
    1508                                                         fprintf(stderr,"OOOPS the proxy is no more...trying respawn...\n"); 
     1506                                        if (WIFEXITED(waitpid_status)) { 
     1507                                                if (WEXITSTATUS(waitpid_status) != UWSGI_END_CODE) { 
     1508                                                        fprintf(stderr, "OOOPS the proxy is no more...trying respawn...\n"); 
    15091509                                                        uwsgi.shared->spooler_pid = proxy_start(1); 
    15101510                                                        continue; 
     
    15151515#endif 
    15161516                        /* check for reloading */ 
    1517                         if (WIFEXITED (waitpid_status)) { 
    1518                                 if (WEXITSTATUS (waitpid_status) == UWSGI_RELOAD_CODE && uwsgi.to_heaven) { 
     1517                        if (WIFEXITED(waitpid_status)) { 
     1518                                if (WEXITSTATUS(waitpid_status) == UWSGI_RELOAD_CODE && uwsgi.to_heaven) { 
    15191519                                        ready_to_reload++; 
    15201520                                        continue; 
    15211521                                } 
    1522                                 else if (WEXITSTATUS (waitpid_status) == UWSGI_END_CODE && uwsgi.to_hell) { 
     1522                                else if (WEXITSTATUS(waitpid_status) == UWSGI_END_CODE && uwsgi.to_hell) { 
    15231523                                        ready_to_die++; 
    15241524                                        continue; 
     
    15261526                        } 
    15271527 
    1528                         fprintf (stderr, "DAMN ! process %d died :( trying respawn ...\n", diedpid); 
    1529                         gettimeofday (&last_respawn, NULL); 
     1528                        fprintf(stderr, "DAMN ! process %d died :( trying respawn ...\n", diedpid); 
     1529                        gettimeofday(&last_respawn, NULL); 
    15301530                        if (last_respawn.tv_sec == respawn_delta) { 
    1531                                 fprintf (stderr, "worker respawning too fast !!! i have to sleep a bit...\n"); 
     1531                                fprintf(stderr, "worker respawning too fast !!! i have to sleep a bit...\n"); 
    15321532                                /* TODO, user configurable fork throttler */ 
    1533                                 sleep (2); 
    1534                         } 
    1535                         gettimeofday (&last_respawn, NULL); 
     1533                                sleep(2); 
     1534                        } 
     1535                        gettimeofday(&last_respawn, NULL); 
    15361536                        respawn_delta = last_respawn.tv_sec; 
    1537                         uwsgi.mywid = find_worker_id (diedpid); 
    1538                         pid = fork (); 
     1537                        uwsgi.mywid = find_worker_id(diedpid); 
     1538                        pid = fork(); 
    15391539                        if (pid == 0) { 
    1540                                 uwsgi.mypid = getpid (); 
     1540                                uwsgi.mypid = getpid(); 
    15411541                                uwsgi.workers[uwsgi.mywid].pid = uwsgi.mypid; 
    15421542                                uwsgi.workers[uwsgi.mywid].harakiri = 0; 
     
    15441544                                uwsgi.workers[uwsgi.mywid].failed_requests = 0; 
    15451545                                uwsgi.workers[uwsgi.mywid].respawn_count++; 
    1546                                 uwsgi.workers[uwsgi.mywid].last_spawn = time (NULL); 
     1546                                uwsgi.workers[uwsgi.mywid].last_spawn = time(NULL); 
    15471547                                uwsgi.workers[uwsgi.mywid].manage_next_request = 1; 
    15481548                                uwsgi.workers[uwsgi.mywid].i_have_gil = 1; 
     
    15501550                        } 
    15511551                        else if (pid < 1) { 
    1552                                 perror ("fork()"); 
     1552                                perror("fork()"); 
    15531553                        } 
    15541554                        else { 
    1555                                 fprintf (stderr, "Respawned uWSGI worker (new pid: %d)\n", pid); 
     1555                                fprintf(stderr, "Respawned uWSGI worker (new pid: %d)\n", pid); 
    15561556#ifdef UWSGI_SPOOLER 
    15571557                                if (uwsgi.mywid <= 0 && diedpid != uwsgi.shared->spooler_pid) { 
     
    15631563                                        if (diedpid != uwsgi.shared->proxy_pid) { 
    15641564#endif 
    1565                                                 fprintf (stderr, "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n"); 
     1565                                                fprintf(stderr, "warning the died pid was not in the workers list. Probably you hit a BUG of uWSGI\n"); 
    15661566#ifdef UWSGI_PROXY 
    15671567                                        } 
     
    15751575 
    15761576 
    1577         uwsgi.hvec = malloc (sizeof (struct iovec) * uwsgi.vec_size); 
     1577        uwsgi.hvec = malloc(sizeof(struct iovec) * uwsgi.vec_size); 
    15781578        if (uwsgi.hvec == NULL) { 
    1579                 fprintf (stderr, "unable to allocate memory for iovec.\n"); 
    1580                 exit (1); 
     1579                fprintf(stderr, "unable to allocate memory for iovec.\n"); 
     1580                exit(1); 
    15811581        } 
    15821582 
    15831583        if (uwsgi.shared->options[UWSGI_OPTION_HARAKIRI] > 0 && !uwsgi.master_process) { 
    1584                 signal (SIGALRM, (void *) &harakiri); 
     1584                signal(SIGALRM, (void *) &harakiri); 
    15851585        } 
    15861586 
    15871587        /* gracefully reload */ 
    1588         signal (SIGHUP, (void *) &gracefully_kill); 
     1588        signal(SIGHUP, (void *) &gracefully_kill); 
    15891589        /* close the process (useful for master INT) */ 
    1590         signal (SIGINT, (void *) &end_me); 
     1590        signal(SIGINT, (void *) &end_me); 
    15911591        /* brutally reload */ 
    1592         signal (SIGTERM, (void *) &reload_me); 
     1592        signal(SIGTERM, (void *) &reload_me); 
    15931593 
    15941594 
    15951595#ifndef UNBIT 
    1596         signal (SIGUSR1, (void *) &stats); 
    1597 #endif 
    1598  
    1599  
    1600         signal (SIGPIPE, (void *) &warn_pipe); 
     1596        signal(SIGUSR1, (void *) &stats); 
     1597#endif 
     1598 
     1599 
     1600        signal(SIGPIPE, (void *) &warn_pipe); 
    16011601 
    16021602 
     
    16041604        if (uwsgi.erlang_nodes > 0) { 
    16051605                if (uwsgi.numproc <= uwsgi.erlang_nodes) { 
    1606                         fprintf(stderr,"You do not have enough worker for Erlang. Please respawn with at least %d processes.\n", uwsgi.erlang_nodes+1); 
    1607                 } 
    1608                 else if ( uwsgi.mywid > (uwsgi.numproc - uwsgi.erlang_nodes) ) { 
    1609                         fprintf(stderr,"Erlang mode enabled for worker %d.\n", uwsgi.mywid); 
     1606                        fprintf(stderr, "You do not have enough worker for Erlang. Please respawn with at least %d processes.\n", uwsgi.erlang_nodes + 1); 
     1607                } 
     1608                else if (uwsgi.mywid > (uwsgi.numproc - uwsgi.erlang_nodes)) { 
     1609                        fprintf(stderr, "Erlang mode enabled for worker %d.\n", uwsgi.mywid); 
    16101610                        erlang_loop(); 
    16111611                        // NEVER HERE 
     
    16201620        // release the GIL 
    16211621        if (uwsgi.has_threads) { 
    1622                 uwsgi._save = PyEval_SaveThread (); 
     1622                uwsgi._save = PyEval_SaveThread(); 
    16231623                uwsgi.workers[uwsgi.mywid].i_have_gil = 0; 
    16241624        } 
     
    16341634#endif 
    16351635                // clear all status bits 
    1636                 UWSGI_CLEAR_STATUS ; 
    1637  
    1638                 uwsgi.poll.fd = accept (uwsgi.serverfd, (struct sockaddr *) &c_addr, (socklen_t *) & c_len); 
     1636                UWSGI_CLEAR_STATUS; 
     1637 
     1638                uwsgi.poll.fd = accept(uwsgi.serverfd, (struct sockaddr *) &c_addr, (socklen_t *) & c_len); 
    16391639 
    16401640                if (uwsgi.poll.fd < 0) { 
    1641                         perror ("accept()"); 
     1641                        perror("accept()"); 
    16421642                        continue; 
    16431643                } 
     
    16461646 
    16471647                if (uwsgi.shared->options[UWSGI_OPTION_LOGGING]) 
    1648                         gettimeofday (&wsgi_req.start_of_request, NULL); 
    1649  
    1650                  
     1648                        gettimeofday(&wsgi_req.start_of_request, NULL); 
     1649 
     1650 
    16511651 
    16521652#ifdef UWSGI_SCTP 
     
    16541654                        // get stream id, and map it to uwsgi modifiers 
    16551655                        struct sctp_status sstatus; 
    1656                         memset (&sstatus, 0, sizeof (sstatus)); 
    1657                         socklen_t slen = sizeof (sstatus); 
     1656                        memset(&sstatus, 0, sizeof(sstatus)); 
     1657                        socklen_t slen = sizeof(sstatus); 
    16581658                        sstatus.sstat_assoc_id = 1; 
    1659                         if (getsockopt (uwsgi.poll.fd, IPPROTO_SCTP, SCTP_STATUS, &sstatus, &slen)) { 
    1660                                 perror ("getsockopt()"); 
    1661                         } 
    1662  
    1663                         memset (&sctp_ss, 0, sizeof (sctp_ss)); 
    1664  
    1665                         fprintf (stderr, "%d %d\n", sstatus.sstat_instrms, sstatus.sstat_outstrms); 
     1659                        if (getsockopt(uwsgi.poll.fd, IPPROTO_SCTP, SCTP_STATUS, &sstatus, &slen)) { 
     1660                                perror("getsockopt()"); 
     1661                        } 
     1662 
     1663                        memset(&sctp_ss, 0, sizeof(sctp_ss)); 
     1664 
     1665                        fprintf(stderr, "%d %d\n", sstatus.sstat_instrms, sstatus.sstat_outstrms); 
    16661666 
    16671667                        i = 0; 
    1668                         wsgi_req.size = sctp_recvmsg (uwsgi.poll.fd, uwsgi.buffer, uwsgi.buffer_size, 0, 0, &sctp_ss, 0); 
     1668                        wsgi_req.size = sctp_recvmsg(uwsgi.poll.fd, uwsgi.buffer, uwsgi.buffer_size, 0, 0, &sctp_ss, 0); 
    16691669                        if (wsgi_req.size < 0) { 
    1670                                 perror ("sctp_recvmsg()"); 
    1671                         } 
    1672                         fprintf (stderr, "received uwsgi message of %d bytes on stream id %d flags %d\n", wsgi_req.size, ntohs (sctp_ss.sinfo_stream), i); 
     1670                                perror("sctp_recvmsg()"); 
     1671                        } 
     1672                        fprintf(stderr, "received uwsgi message of %d bytes on stream id %d flags %d\n", wsgi_req.size, ntohs(sctp_ss.sinfo_stream), i); 
    16731673 
    16741674                } 
    16751675                else { 
    16761676#endif 
    1677                         if (!uwsgi_parse_response (&uwsgi.poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) &wsgi_req, uwsgi.buffer)) { 
     1677                        if (!uwsgi_parse_response(&uwsgi.poll, uwsgi.shared->options[UWSGI_OPTION_SOCKET_TIMEOUT], (struct uwsgi_header *) &wsgi_req, uwsgi.buffer)) { 
    16781678                                continue; 
    16791679                        } 
     
    16871687                } 
    16881688 
    1689                 ret = (*uwsgi.shared->hooks[wsgi_req.modifier])(&uwsgi, &wsgi_req); 
     1689                ret = (*uwsgi.shared->hooks[wsgi_req.modifier]) (&uwsgi, &wsgi_req); 
    16901690                // calculate execution time 
    1691                 gettimeofday(&wsgi_req.end_of_request, NULL) ; 
    1692                 uwsgi.workers[uwsgi.mywid].running_time += (double) (( (double)(wsgi_req.end_of_request.tv_sec*1000000+wsgi_req.end_of_request.tv_usec)-(double)(wsgi_req.start_of_request.tv_sec*1000000+wsgi_req.start_of_request.tv_usec))/ (double)1000.0) ; 
     1691                gettimeofday(&wsgi_req.end_of_request, NULL); 
     1692                uwsgi.workers[uwsgi.mywid].running_time += (double) (((double) (wsgi_req.end_of_request.tv_sec * 1000000 + wsgi_req.end_of_request.tv_usec) - (double) (wsgi_req.start_of_request.tv_sec * 1000000 + wsgi_req.start_of_request.tv_usec)) / (double) 1000.0); 
    16931693 
    16941694 
    16951695                // get memory usage 
    16961696                if (uwsgi.shared->options[UWSGI_OPTION_MEMORY_DEBUG] == 1) 
    1697                         get_memusage(); 
     1697                        get_memusage(); 
    16981698 
    16991699                // close the connection with the webserver 
     
    17031703 
    17041704                if (!ret) 
    1705                         (*uwsgi.shared->after_hooks[wsgi_req.modifier])(&uwsgi, &wsgi_req); 
     1705                        (*uwsgi.shared->after_hooks[wsgi_req.modifier]) (&uwsgi, &wsgi_req); 
    17061706 
    17071707 
     
    17141714                // defunct process reaper 
    17151715                if (uwsgi.shared->options[UWSGI_OPTION_REAPER] == 1) { 
    1716                         waitpid (-1, &waitpid_status, WNOHANG); 
     1716                        waitpid(-1, &waitpid_status, WNOHANG); 
    17171717                } 
    17181718                // reset request 
    1719                 memset (&wsgi_req, 0, sizeof (struct wsgi_request)); 
     1719                memset(&wsgi_req, 0, sizeof(struct wsgi_request)); 
    17201720#ifdef UNBIT 
    17211721                if (tmp_filename && tmp_dir_fd >= 0) { 
     
    17251725 
    17261726                if (uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS] > 0 && uwsgi.workers[uwsgi.mywid].requests >= uwsgi.shared->options[UWSGI_OPTION_MAX_REQUESTS]) { 
    1727                         goodbye_cruel_world (); 
     1727                        goodbye_cruel_world(); 
    17281728                } 
    17291729 
    17301730#ifdef UNBIT 
    17311731                if (check_for_memory_errors) { 
    1732                         if (syscall (357, &us, 0) > 0) { 
     1732                        if (syscall(357, &us, 0) > 0) { 
    17331733                                if (us.memory_errors > 0) { 
    1734                                         fprintf (stderr, "Unbit Kernel found a memory allocation error for process %d.\n", uwsgi.mypid); 
    1735                                         goodbye_cruel_world (); 
     1734                                        fprintf(stderr, "Unbit Kernel found a memory allocation error for process %d.\n", uwsgi.mypid); 
     1735                                        goodbye_cruel_world(); 
    17361736                                } 
    17371737                        } 
     
    17421742 
    17431743        if (uwsgi.workers[uwsgi.mywid].manage_next_request == 0) { 
    1744                 reload_me (); 
     1744                reload_me(); 
    17451745        } 
    17461746        else { 
    1747                 goodbye_cruel_world (); 
     1747                goodbye_cruel_world(); 
    17481748        } 
    17491749 
     
    17521752} 
    17531753 
    1754 void init_uwsgi_vars () { 
     1754void init_uwsgi_vars() { 
    17551755 
    17561756#ifndef UNBIT 
     
    17601760 
    17611761        /* add cwd to pythonpath */ 
    1762         pysys = PyImport_ImportModule ("sys"); 
     1762        pysys = PyImport_ImportModule("sys"); 
    17631763        if (!pysys) { 
    1764                 PyErr_Print (); 
    1765                 exit (1); 
    1766         } 
    1767         pysys_dict = PyModule_GetDict (pysys); 
    1768         pypath = PyDict_GetItemString (pysys_dict, "path"); 
     1764                PyErr_Print(); 
     1765                exit(1); 
     1766        } 
     1767        pysys_dict = PyModule_GetDict(pysys); 
     1768        pypath = PyDict_GetItemString(pysys_dict, "path"); 
    17691769        if (!pypath) { 
    1770                 PyErr_Print (); 
    1771                 exit (1); 
    1772         } 
    1773         if (PyList_Insert (pypath, 0, PyString_FromString (".")) != 0) { 
    1774                 PyErr_Print (); 
     1770                PyErr_Print(); 
     1771                exit(1); 
     1772        } 
     1773        if (PyList_Insert(pypath, 0, PyString_FromString(".")) != 0) { 
     1774                PyErr_Print(); 
    17751775        } 
    17761776 
    17771777#ifndef UNBIT 
    17781778        for (i = 0; i < uwsgi.python_path_cnt; i++) { 
    1779                 if (PyList_Insert (pypath, 0, PyString_FromString (uwsgi.python_path[i])) != 0) { 
    1780                         PyErr_Print (); 
     1779                if (PyList_Insert(pypath, 0, PyString_FromString(uwsgi.python_path[i])) != 0) { 
     1780                        PyErr_Print(); 
    17811781                } 
    17821782                else { 
    1783                         fprintf (stderr, "added %s to pythonpath.\n", uwsgi.python_path[i]); 
     1783                        fprintf(stderr, "added %s to pythonpath.\n", uwsgi.python_path[i]); 
    17841784                } 
    17851785        } 
     
    17881788} 
    17891789 
    1790 int init_uwsgi_app (PyObject * force_wsgi_dict, PyObject * my_callable) { 
     1790int init_uwsgi_app(PyObject * force_wsgi_dict, PyObject * my_callable) { 
    17911791        PyObject *wsgi_module, *wsgi_dict = NULL; 
    17921792        PyObject *pymain, *zero; 
     
    17971797        struct uwsgi_app *wi; 
    17981798 
    1799         memset (tmpstring, 0, 256); 
     1799        memset(tmpstring, 0, 256); 
    18001800 
    18011801 
    18021802        if (wsgi_req.wsgi_script_len == 0 && ((wsgi_req.wsgi_module_len == 0 || wsgi_req.wsgi_callable_len == 0) && uwsgi.wsgi_config == NULL && my_callable == NULL)) { 
    1803                 fprintf (stderr, "invalid application (%.*s). skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
     1803                fprintf(stderr, "invalid application (%.*s). skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
    18041804                return -1; 
    18051805        } 
    18061806 
    18071807        if (uwsgi.wsgi_config && wsgi_req.wsgi_callable_len == 0 && my_callable == NULL) { 
    1808                 fprintf (stderr, "invalid application (%.*s). skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
     1808                fprintf(stderr, "invalid application (%.*s). skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
    18091809                return -1; 
    18101810        } 
    18111811 
    18121812        if (wsgi_req.wsgi_script_len > 255 || wsgi_req.wsgi_module_len > 255 || wsgi_req.wsgi_callable_len > 255) { 
    1813                 fprintf (stderr, "invalid application's string size. skip.\n"); 
     1813                fprintf(stderr, "invalid application's string size. skip.\n"); 
    18141814                return -1; 
    18151815        } 
     
    18301830 
    18311831 
    1832         zero = PyString_FromStringAndSize (wsgi_req.script_name, wsgi_req.script_name_len); 
     1832        zero = PyString_FromStringAndSize(wsgi_req.script_name, wsgi_req.script_name_len); 
    18331833        if (!zero) { 
    1834                 Py_FatalError ("cannot get mountpoint python object !\n"); 
    1835         } 
    1836  
    1837         if (PyDict_GetItem (uwsgi.py_apps, zero) != NULL) { 
    1838                 Py_DECREF (zero); 
    1839                 fprintf (stderr, "mountpoint %.*s already configured. skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
     1834                Py_FatalError("cannot get mountpoint python object !\n"); 
     1835        } 
     1836 
     1837        if (PyDict_GetItem(uwsgi.py_apps, zero) != NULL) { 
     1838                Py_DECREF(zero); 
     1839                fprintf(stderr, "mountpoint %.*s already configured. skip.\n", wsgi_req.script_name_len, wsgi_req.script_name); 
    18401840                return -1; 
    18411841        } 
    18421842 
    1843         Py_DECREF (zero); 
     1843        Py_DECREF(zero); 
    18441844 
    18451845        wi = &uwsgi.wsgi_apps[id]; 
    18461846 
    1847         memset (wi, 0, sizeof (struct uwsgi_app)); 
     1847        memset(wi, 0, sizeof(struct uwsgi_app)); 
    18481848 
    18491849        if (uwsgi.single_interpreter == 0) { 
    1850                 wi->interpreter = Py_NewInterpreter (); 
     1850                wi->interpreter = Py_NewInterpreter(); 
    18511851                if (!wi->interpreter) { 
    1852                         fprintf (stderr, "unable to initialize the new interpreter\n"); 
    1853                         exit (1); 
    1854                 } 
    1855                 PyThreadState_Swap (wi->interpreter); 
     1852                        fprintf(stderr, "unable to initialize the new interpreter\n"); 
     1853                        exit(1); 
     1854                } 
     1855                PyThreadState_Swap(wi->interpreter); 
    18561856#ifndef PYTHREE 
    1857                 init_uwsgi_embedded_module (); 
    1858 #endif 
    1859                 init_uwsgi_vars (); 
    1860                 fprintf (stderr, "interpreter for app %d initialized.\n", id); 
     1857                init_uwsgi_embedded_module(); 
     1858#endif 
     1859                init_uwsgi_vars(); 
     1860                fprintf(stderr, "interpreter for app %d initialized.\n", id); 
    18611861        } 
    18621862 
    18631863        if (uwsgi.paste) { 
    18641864                wi->wsgi_callable = my_callable; 
    1865                 Py_INCREF (my_callable); 
     1865                Py_INCREF(my_callable); 
    18661866        } 
    18671867        else if (uwsgi.wsgi_file) { 
    1868                 wi->wsgi_callable = my_callable; 
    1869                 Py_INCREF (my_callable); 
    1870         } 
     1868                wi->wsgi_callable = my_callable; 
     1869                Py_INCREF(my_callable); 
     1870        } 
    18711871        else { 
    18721872 
    18731873                if (uwsgi.wsgi_config == NULL) { 
    18741874                        if (wsgi_req.wsgi_script_len > 0) { 
    1875                                 memcpy (tmpstring, wsgi_req.wsgi_script, wsgi_req.wsgi_script_len); 
    1876                                 wsgi_module = PyImport_ImportModule (tmpstring); 
     1875                                memcpy(tmpstring, wsgi_req.wsgi_script, wsgi_req.wsgi_script_len); 
     1876                                wsgi_module = PyImport_ImportModule(tmpstring); 
    18771877                                if (!wsgi_module) { 
    1878                                         PyErr_Print (); 
     1878                                        PyErr_Print(); 
    18791879                                        if (uwsgi.single_interpreter == 0) { 
    1880                                                 Py_EndInterpreter (wi->interpreter); 
    1881                                                 PyThreadState_Swap (uwsgi.main_thread); 
     1880                                                Py_EndInterpreter(wi->interpreter); 
     1881                                                PyThreadState_Swap(uwsgi.main_thread); 
    18821882                                        } 
    18831883                                        return -1; 
     
    18871887                        } 
    18881888                        else { 
    1889                                 memcpy (tmpstring, wsgi_req.wsgi_module, wsgi_req.wsgi_module_len); 
    1890                                 wsgi_module = PyImport_ImportModule (tmpstring); 
     1889                                memcpy(tmpstring, wsgi_req.wsgi_module, wsgi_req.wsgi_module_len); 
     1890                                wsgi_module = PyImport_ImportModule(tmpstring); 
    18911891                                if (!wsgi_module) { 
    1892                                         PyErr_Print (); 
     1892                                        PyErr_Print(); 
    18931893                                        if (uwsgi.single_interpreter == 0) { 
    1894                                                 Py_EndInterpreter (wi->interpreter); 
    1895                                                 PyThreadState_Swap (uwsgi.main_thread); 
     1894                                                Py_EndInterpreter(wi->interpreter); 
     1895                                                PyThreadState_Swap(uwsgi.main_thread); 
    18961896                                        } 
    18971897                                        return -1; 
     
    18991899                        } 
    19001900 
    1901                         wsgi_dict = PyModule_GetDict (wsgi_module); 
     1901                        wsgi_dict = PyModule_GetDict(wsgi_module); 
    19021902                        if (!wsgi_dict) { 
    1903                                 PyErr_Print (); 
     1903                                PyErr_Print(); 
    19041904                                if (uwsgi.single_interpreter == 0) { 
    1905                                         Py_EndInterpreter (wi->interpreter); 
    1906                                         PyThreadState_Swap (uwsgi.main_thread); 
     1905                                        Py_EndInterpreter(wi->interpreter); 
     1906                                        PyThreadState_Swap(uwsgi.main_thread); 
    19071907                                } 
    19081908                                return -1; 
     
    19151915 
    19161916 
    1917                 memset (tmpstring, 0, 256); 
    1918                 memcpy (tmpstring, wsgi_req.wsgi_callable, wsgi_req.wsgi_callable_len); 
     1917                memset(tmpstring, 0, 256); 
     1918