Alert is often followed by exit. Alert_exit embedded the exit call. --- include/proto/log.h | 9 +++++++++ src/log.c | 31 ++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-)
diff --git a/include/proto/log.h b/include/proto/log.h index e606a3c..7afa2a0 100644 --- a/include/proto/log.h +++ b/include/proto/log.h @@ -90,8 +90,17 @@ void parse_logformat_string(const char *str, struct proxy *curproxy, struct list * Displays the message on stderr with the date and pid. Overrides the quiet * mode during startup. */ +void Alert_va(const char *fmt, va_list argp); +/* + * Same as Alert_va with printf argument style + */ void Alert(const char *fmt, ...) __attribute__ ((format(printf, 1, 2))); +/* + * Give the possibility to exit just after Alert. + */ +void Alert_exit(int exit_code, const char *fmt, ...) + __attribute__ ((format(printf, 2, 3))); /* * Displays the message on stderr with the date and pid. diff --git a/src/log.c b/src/log.c index 2d02247..949436a 100644 --- a/src/log.c +++ b/src/log.c @@ -622,23 +622,44 @@ void parse_logformat_string(const char *fmt, struct proxy *curproxy, struct list * Displays the message on stderr with the date and pid. Overrides the quiet * mode during startup. */ -void Alert(const char *fmt, ...) +void Alert_va(const char *fmt, va_list argp) { - va_list argp; struct tm tm; if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { - va_start(argp, fmt); - get_localtime(date.tv_sec, &tm); fprintf(stderr, "[ALERT] %03d/%02d%02d%02d (%d) : ", tm.tm_yday, tm.tm_hour, tm.tm_min, tm.tm_sec, (int)getpid()); vfprintf(stderr, fmt, argp); fflush(stderr); - va_end(argp); } } +/* + * Same as Alert_va with printf argument style + */ +void Alert(const char *fmt, ...) +{ + va_list argp; + + va_start(argp, fmt); + Alert_va(fmt, argp); + va_end(argp); +} + +/* + * Give the possibility to exit just after Alert. + */ +void Alert_exit(int exit_code, const char *fmt, ...) +{ + va_list argp; + + va_start(argp, fmt); + Alert_va(fmt, argp); + va_end(argp); + if (exit_code) + exit(exit_code); +} /* * Displays the message on stderr with the date and pid. -- 2.8.2