X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=src%2Fcoloredstderr.c;h=e6f1f6aab30999a2ecb55b017dfe4ae171658e95;hb=ac9101941e5ea97fdec35a480d6270bf68bbab90;hp=66467b402e14d0a95b630dea38e1e3d59a77a7d7;hpb=d49cd5d92a07d708ddcb3c29cad67403cf8eb836;p=coloredstderr%2Fcoloredstderr.git diff --git a/src/coloredstderr.c b/src/coloredstderr.c index 66467b4..e6f1f6a 100644 --- a/src/coloredstderr.c +++ b/src/coloredstderr.c @@ -81,6 +81,12 @@ static int force_write_to_non_tty; /* Was ENV_NAME_FDS found and used when init_from_environment() was called? * This is not true if the process set it manually after initialization. */ static int used_fds_set_by_user; +/* Was any of our handle_*_pre()/handle_*_post() functions called recursively? + * If so don't print the pre/post string for the recursive calls. This is + * necessary on some systems (e.g. FreeBSD 9.1) which call multiple hooked + * functions while printing a string (e.g. a FILE * and a fd hook function is + * called). */ +static int handle_recursive; #include "constants.h" @@ -181,9 +187,13 @@ static void handle_file_pre(FILE *stream) noinline; static void handle_file_post(FILE *stream) noinline; static void handle_fd_pre(int fd) { + if (handle_recursive++ > 0) { + return; + } + int saved_errno = errno; - if (unlikely(!pre_string || !post_string)) { + if (unlikely(!pre_string)) { init_pre_post_string(); } @@ -193,6 +203,10 @@ static void handle_fd_pre(int fd) { errno = saved_errno; } static void handle_fd_post(int fd) { + if (--handle_recursive > 0) { + return; + } + int saved_errno = errno; /* write() already loaded above in handle_fd_pre(). */ @@ -202,9 +216,13 @@ static void handle_fd_post(int fd) { } static void handle_file_pre(FILE *stream) { + if (handle_recursive++ > 0) { + return; + } + int saved_errno = errno; - if (unlikely(!pre_string || !post_string)) { + if (unlikely(!pre_string)) { init_pre_post_string(); } @@ -214,6 +232,10 @@ static void handle_file_pre(FILE *stream) { errno = saved_errno; } static void handle_file_post(FILE *stream) { + if (--handle_recursive > 0) { + return; + } + int saved_errno = errno; /* fwrite() already loaded above in handle_file_pre(). */