Changeset 239:d6735a53d498 for uwsgi.c

Show
Ignore:
Timestamp:
02/15/10 14:55:20 (6 months ago)
Author:
roberto@…
Branch:
default
Message:

stronger reload recognition

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • uwsgi.c

    r238 r239  
    5555static const char *app_slash = "/"; 
    5656#endif 
     57 
     58extern char **environ; 
    5759 
    5860int find_worker_id (pid_t pid) { 
     
    532534        int ready_to_die = 0; 
    533535 
     536        char *env_reloads ; 
     537        unsigned int reloads = 0; 
    534538        int is_a_reload = 0; 
     539        char env_reload_buf[11]; 
    535540 
    536541        char *buffer; 
     
    668673        strcpy (binary_path, argv[0]); 
    669674 
     675        env_reloads = getenv("UWSGI_RELOADS"); 
     676        if (env_reloads) { 
     677                // convert env value to int 
     678                reloads = atoi(env_reloads); 
     679                reloads++; 
     680                // convert reloads to string 
     681                rlen = snprintf(env_reload_buf, 10, "%u", reloads) ; 
     682                if (rlen > 0) { 
     683                        env_reload_buf[rlen] = 0 ; 
     684                        if (setenv("UWSGI_RELOADS",env_reload_buf, 1)) { 
     685                                perror("setenv()"); 
     686                        } 
     687                } 
     688        } 
     689        else { 
     690                fprintf(stderr,"setting UWSGI_RELOADS\n"); 
     691                if (setenv("UWSGI_RELOADS","0", 1)) { 
     692                        perror("setenv()"); 
     693                } 
     694        } 
     695 
    670696        socket_type_len = sizeof (int); 
    671697        if (!getsockopt (3, SOL_SOCKET, SO_TYPE, &socket_type, &socket_type_len)) { 
    672                 if (socket_type == SOCK_STREAM) {  
     698                if (socket_type == SOCK_STREAM && reloads > 0) {  
    673699                        fprintf (stderr, "...fd 3 is a socket, i suppose this is a graceful reload of uWSGI, i will try to do my best...\n"); 
    674700                        is_a_reload = 1; 
     
    15171543                                fprintf (stderr, "running %s\n", binary_path); 
    15181544                                strcpy (argv[0], binary_path); 
    1519                                 execve (binary_path, argv, envp); 
     1545                                execve (binary_path, argv, environ); 
    15201546                                perror ("execve()"); 
    15211547                                exit (1);