From: Timo Sirainen Date: Fri, 18 May 2018 14:29:09 +0000 (+0300) Subject: lib: Linux, OSX, etc: Avoid race conditions showing \xAB chars in ps title X-Git-Tag: 2.3.9~1844 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca4c2579f0456072bdb505932a9cf7602e42afd2;p=thirdparty%2Fdovecot%2Fcore.git lib: Linux, OSX, etc: Avoid race conditions showing \xAB chars in ps title With bad luck "ps" reads the process title when it hasn't been fully written. Since the trailing NULs are written last and the previous code kept the ps title otherwise filled with \xAB chars, this could have caused ps to sometimes show the process title filled with \xAB chars (visible as '?') --- diff --git a/src/lib/process-title.c b/src/lib/process-title.c index 50b35b5c5f..6c680c32f1 100644 --- a/src/lib/process-title.c +++ b/src/lib/process-title.c @@ -19,7 +19,15 @@ static char *current_process_title; #ifdef PROCTITLE_HACK -#define PROCTITLE_CLEAR_CHAR 0xab +#ifdef DEBUG +/* if there are problems with this approach, try to make sure we notice it */ +# define PROCTITLE_CLEAR_CHAR 0xab +#else +/* There are always race conditions when updating the process title. ps might + read a partially written title. Try to at least minimize this by using NUL + as the fill character, so ps won't show a large number of 0xab chars. */ +# define PROCTITLE_CLEAR_CHAR 0 +#endif static char *process_title; static size_t process_title_len, process_title_clean_pos; @@ -54,8 +62,6 @@ static void proctitle_hack_init(char *argv[], char *env[]) process_title = argv[0]; process_title_len = last - argv[0]; - /* if there are problems with this approach, try to make sure we - notice it */ if (clear_env) { memset(env[0], PROCTITLE_CLEAR_CHAR, last - env[0]); process_title_clean_pos = env[0] - process_title;