If in_exit_cleanup is set, some of our functions return instead of
authorWayne Davison <wayned@samba.org>
Fri, 13 Oct 2006 07:38:18 +0000 (07:38 +0000)
committerWayne Davison <wayned@samba.org>
Fri, 13 Oct 2006 07:38:18 +0000 (07:38 +0000)
calling exit_cleanup() (which is a safer way to avoid an infinite
loop when the exit code uses the log functions than allowing the
_exit_cleanup() function to return back into our code).

log.c

diff --git a/log.c b/log.c
index f529adb..2355214 100644 (file)
--- a/log.c
+++ b/log.c
@@ -37,6 +37,7 @@ extern int msg_fd_out;
 extern int allow_8bit_chars;
 extern int protocol_version;
 extern int preserve_times;
+extern int in_exit_cleanup;
 extern int stdout_format_has_i;
 extern int stdout_format_has_o_or_i;
 extern int logfile_format_has_i;
@@ -90,6 +91,13 @@ struct {
        { 0, NULL }
 };
 
+#define EXIT_OR_RETURN(err) \
+       do { \
+               if (in_exit_cleanup) \
+                       return; \
+               exit_cleanup(err); \
+       } while (0)
+
 
 /*
  * Map from rsync error code to name, or return NULL.
@@ -222,13 +230,13 @@ static void filtered_fwrite(FILE *f, const char *buf, int len, int use_isprint)
                  && ((use_isprint && !isprint(*(uchar*)s))
                   || *(uchar*)s < ' '))) {
                        if (s != buf && fwrite(buf, s - buf, 1, f) != 1)
-                               exit_cleanup(RERR_MESSAGEIO);
+                               EXIT_OR_RETURN(RERR_MESSAGEIO);
                        fprintf(f, "\\#%03o", *(uchar*)s);
                        buf = s + 1;
                }
        }
        if (buf != end && fwrite(buf, end - buf, 1, f) != 1)
-               exit_cleanup(RERR_MESSAGEIO);
+               EXIT_OR_RETURN(RERR_MESSAGEIO);
 }
 
 /* this is the underlying (unformatted) rsync debugging function. Call
@@ -240,7 +248,7 @@ void rwrite(enum logcode code, char *buf, int len)
        FILE *f = NULL;
 
        if (len < 0)
-               exit_cleanup(RERR_MESSAGEIO);
+               EXIT_OR_RETURN(RERR_MESSAGEIO);
 
        if (am_server && msg_fd_out >= 0) {
                /* Pass the message to our sibling. */
@@ -294,7 +302,7 @@ void rwrite(enum logcode code, char *buf, int len)
                f = am_server ? stderr : stdout;
                break;
        default:
-               exit_cleanup(RERR_MESSAGEIO);
+               EXIT_OR_RETURN(RERR_MESSAGEIO);
        }
 
        trailing_CR_or_NL = len && (buf[len-1] == '\n' || buf[len-1] == '\r')
@@ -398,7 +406,7 @@ void rsyserr(enum logcode code, int errcode, const char *format, ...)
                                ": %s (%d)\n", strerror(errcode), errcode);
        }
        if (len >= sizeof buf)
-               exit_cleanup(RERR_MESSAGEIO);
+               EXIT_OR_RETURN(RERR_MESSAGEIO);
 
        rwrite(code, buf, len);
 }
@@ -436,7 +444,7 @@ static void log_formatted(enum logcode code, char *format, char *op,
        total = strlcpy(buf, format, sizeof buf);
        if (total > MAXPATHLEN) {
                rprintf(FERROR, "log-format string is WAY too long!\n");
-               exit_cleanup(RERR_MESSAGEIO);
+               EXIT_OR_RETURN(RERR_MESSAGEIO);
        }
        buf[total++] = '\n';
        buf[total] = '\0';