process-title.c revision d2470b3dfe91ca07459185384ee25080b42a1636
45312f52ff3a3d4c137447be4c7556500c2f8bf2Timo Sirainen/* Copyright (c) 2002-2010 Dovecot authors, see the included COPYING file */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic size_t process_title_len, process_title_clean_pos;
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainenstatic void proctitle_hack_init(char *argv[], char *env[])
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen unsigned int i;
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen /* find the last argv or environment string. it should always be the
42456ec33fe65feb411890f99d436071e0185ee3Timo Sirainen last string in environ, but don't rely on it. this is what openssh
1d2b188f0eedc3cab6e27ceac5425a037f38042eTimo Sirainen does, so hopefully it's safe enough. */
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen /* if there are problems with this approach, try to make sure we
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen memset(env[0], PROCTITLE_CLEAR_CHAR, last - env[0]);
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen process_title_clean_pos = env[0] - process_title;
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainenstatic char **argv_dup(char *old_argv[], void **memblock_r)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen /* @UNSAFE */
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen unsigned int i, count;
b5e6f6f27c1461f0f9f202615eeb738a645188c3Timo Sirainen for (count = 0; old_argv[count] != NULL; count++)
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen i_fatal_status(FATAL_OUTOFMEM, "malloc() failed: %m");
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainen memblock_end = PTR_OFFSET(memblock, memblock_len);
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen memblock = PTR_OFFSET(memblock, sizeof(char *) * (count + 1));
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainen for (i = 0; i < count; i++) {
8ed8c821ba8aab0b4ed0375f87d48737ef0e0d8eTimo Sirainenstatic void proctitle_hack_set(const char *title)
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen /* OS X wants two NULs */
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen memset(process_title + len, PROCTITLE_CLEAR_CHAR,
0a601ada15c7fe82f0db895fc2068b71b3a5243cTimo Sirainen } else if (process_title_clean_pos != 0) {
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen *environ_p = argv_dup(orig_environ, &environ_memblock);
04ab375449dd97eed50ada88dd0df2abab01cfeeTimo Sirainenvoid process_title_set(const char *title ATTR_UNUSED)