]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Linux, OSX, etc: Avoid race conditions showing \xAB chars in ps title
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 May 2018 14:29:09 +0000 (17:29 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 10 Sep 2019 07:01:21 +0000 (10:01 +0300)
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 '?')

src/lib/process-title.c

index 50b35b5c5fc38771e41d7148f46cf1bbf4370635..6c680c32f18252532d2c0a7672e6444ac3ffe70b 100644 (file)
@@ -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;