unbit / uwsgi

uWSGI application server container
http://projects.unbit.it/uwsgi
Other
3.46k stars 691 forks source link

uwsgi_set_processname clobbers /proc/*/environ #737

Open akx opened 10 years ago

akx commented 10 years ago

It seems any options that end up calling uwsgi_set_processname (auto-procname, procname-prefix in my case) may clobber more data than required, making debugging the actual environ values of a process difficult, see below.

# xxd /proc/15173/environ 
0000000: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000010: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000020: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000030: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000040: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000050: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000060: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000070: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000080: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000090: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000a0: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000b0: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000c0: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000d0: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000e0: 2020 2020 2020 2020 2020 2020 2020 2020                  
00000f0: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000100: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000110: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000120: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000130: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000140: 2020 2020 2020 2020 2020 2020 2020 2020                  
0000150: 2000 3d65 6e5f 5553 2e55 5446 2d38 00     .=en_US.UTF-8.

I suppose this has to do with this bit that calculates environ length into uwsgi.max_procname in uwsgi.c:

    for (i = 0; environ[i] != NULL; i++) {
        uwsgi.max_procname += strlen(environ[i]) + 1;
        env_count++;
    }

(However, it's interesting to note that not all of the environ gets cleared out. An off-by-one error, maybe?)

If it helps, this occurred on Linux 3.2.0 / x86_64.

unbit commented 10 years ago

Unfortunately it is expected as changing process name in Linux is a horrible hack :(

Basically you use the memory area assigned to environment variables as process name storage

akx commented 10 years ago

Okay. Well, would it be possible to "opportunistically" clear that memory, i.e. only clear as much as required and not all of what's available?

unbit commented 10 years ago

not by default, as the user is free to set the process name with uwsgi.set_process_name() in any moment