MINOR: errors: ha_alert() and ha_warning() uses warn_exec_path()

Move the code to display the haproxy version and path during starting
mode, which is called by the first ha_alert() or ha_warning().
This commit is contained in:
William Lallemand 2023-11-09 11:24:26 +01:00
parent 78021ee9ef
commit b959b752f9

View File

@ -420,6 +420,22 @@ static void print_message_args(int use_usermsgs_ctx, const char *label, const ch
va_end(argp);
}
/*
* Display a notice with the happroxy version and executable path when the
* first message is emitted in starting mode.
*/
static void warn_exec_path()
{
if (!(warned & WARN_EXEC_PATH) && (global.mode & MODE_STARTING)) {
const char *path = get_exec_path();
warned |= WARN_EXEC_PATH;
print_message_args(0, "NOTICE", "haproxy version is %s\n", haproxy_version);
if (path)
print_message_args(0, "NOTICE", "path to executable is %s\n", path);
}
}
/*
* Displays the message on stderr with the pid. Overrides the quiet
* mode during startup.
@ -430,14 +446,7 @@ void ha_alert(const char *fmt, ...)
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE) ||
!(global.mode & MODE_STARTING)) {
if (!(warned & WARN_EXEC_PATH) && (global.mode & MODE_STARTING)) {
const char *path = get_exec_path();
warned |= WARN_EXEC_PATH;
print_message_args(0, "NOTICE", "haproxy version is %s\n", haproxy_version);
if (path)
print_message_args(0, "NOTICE", "path to executable is %s\n", path);
}
warn_exec_path();
va_start(argp, fmt);
print_message(1, "ALERT", fmt, argp);
va_end(argp);
@ -456,14 +465,7 @@ void ha_warning(const char *fmt, ...)
if (!(global.mode & MODE_QUIET) || (global.mode & MODE_VERBOSE) ||
!(global.mode & MODE_STARTING)) {
if (!(warned & WARN_EXEC_PATH) && (global.mode & MODE_STARTING)) {
const char *path = get_exec_path();
warned |= WARN_EXEC_PATH;
print_message_args(0, "NOTICE", "haproxy version is %s\n", haproxy_version);
if (path)
print_message_args(0, "NOTICE", "path to executable is %s\n", path);
}
warn_exec_path();
va_start(argp, fmt);
print_message(1, "WARNING", fmt, argp);
va_end(argp);