]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: errors: ha_alert() and ha_warning() uses warn_exec_path()
authorWilliam Lallemand <wlallemand@haproxy.com>
Thu, 9 Nov 2023 10:24:26 +0000 (11:24 +0100)
committerWilliam Lallemand <wlallemand@haproxy.com>
Thu, 9 Nov 2023 13:39:11 +0000 (14:39 +0100)
Move the code to display the haproxy version and path during starting
mode, which is called by the first ha_alert() or ha_warning().

src/errors.c

index 5913cb1d509d909e14d3c93d9ecdb4837da7401d..bd157a82e7284d306b4d144631030a1d329d7e36 100644 (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);