]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
cf_util: Add cf_log_perr_by_child
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 3 Apr 2023 22:19:55 +0000 (16:19 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 3 Apr 2023 22:19:55 +0000 (16:19 -0600)
src/lib/server/cf_util.c
src/lib/server/cf_util.h

index b398a7a51b835e555f2248599f3dc3330a5aad2e..020440f1dfa8a83a47947a2dd6684fd375607989 100644 (file)
@@ -1991,19 +1991,19 @@ void _cf_log(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line
  * @param[in] ci       #CONF_ITEM to print file/lineno for.
  * @param[in] f_rules  Additional optional formatting controls.
  * @param[in] fmt      of the message.
- * @param[in] ...      Message args.
+ * @param[in] ap       Message args.
  */
-void _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
-                 fr_log_perror_format_t const *f_rules, char const *fmt, ...)
+void _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
+                  fr_log_perror_format_t const *f_rules, char const *fmt, va_list ap)
 {
-       va_list                 ap;
+       va_list aq;
 
        if ((type == L_DBG) && !DEBUG_ENABLED) return;
 
        if (!ci || !ci->filename) {
-               va_start(ap, fmt);
-               fr_vlog_perror(LOG_DST, type, file, line, f_rules, fmt, ap);
-               va_end(ap);
+               va_copy(aq, ap);
+               fr_vlog_perror(LOG_DST, type, file, line, f_rules, fmt, aq);
+               va_end(aq);
                return;
        }
 
@@ -2062,14 +2062,38 @@ void _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int
                        our_f_rules.subsq_prefix = prefix;
                }
 
-               va_start(ap, fmt);
-               fr_vlog_perror(LOG_DST, type, file, line, &our_f_rules, fmt, ap);
-               va_end(ap);
+               va_copy(aq, ap);
+               fr_vlog_perror(LOG_DST, type, file, line, &our_f_rules, fmt, aq);
+               va_end(aq);
 
                talloc_free(pool);
        }
 }
 
+/** Log an error message relating to a #CONF_ITEM
+ *
+ * Drains the fr_strerror() stack emitting one or more error messages.
+ *
+ * @param[in] type     of log message.
+ * @param[in] file     src file the log message was generated in.
+ * @param[in] line     number the log message was generated on.
+ * @param[in] ci       #CONF_ITEM to print file/lineno for.
+ * @param[in] f_rules  Additional optional formatting controls.
+ * @param[in] fmt      of the message.
+ * @param[in] ...      Message args.
+ */
+void _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
+                 fr_log_perror_format_t const *f_rules, char const *fmt, ...)
+{
+       va_list ap;
+
+       if ((type == L_DBG) && !DEBUG_ENABLED) return;
+
+       va_start(ap, fmt);
+       _cf_vlog_perr(type, ci, file, line, f_rules, fmt, ap);
+       va_end(ap);
+}
+
 /** Log a debug message relating to a #CONF_ITEM
  *
  * Always emits a filename/lineno prefix if available
@@ -2139,6 +2163,37 @@ void _cf_log_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const
        va_end(ap);
 }
 
+
+/** Log an error message in the context of a child pair of the specified parent
+ *
+ * @param[in] parent   containing the pair.
+ * @param[in] child    name to use as a logging context.
+ * @param[in] type     of log message.
+ * @param[in] file     src file the log message was generated in.
+ * @param[in] line     number the log message was generated on.
+ * @param[in] fmt      of the message.
+ * @param[in] ...      Message args.
+ */
+void _cf_log_perr_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child,
+                          char const *file, int line, fr_log_perror_format_t const *f_rules,
+                          char const *fmt, ...)
+{
+       va_list         ap;
+       CONF_PAIR const *cp;
+
+       cp = cf_pair_find(parent, child);
+       if (cp) {
+               va_start(ap, fmt);
+               _cf_vlog_perr(type, CF_TO_ITEM(cp), file, line, f_rules, fmt, ap);
+               va_end(ap);
+               return;
+       }
+
+       va_start(ap, fmt);
+       _cf_vlog_perr(type, CF_TO_ITEM(parent), file, line, f_rules, fmt, ap);
+       va_end(ap);
+}
+
 /** Print out debugging information about a CONFIG_ITEM
  *
  * @param[in] ci       being debugged.
index d668fd3a411760c4633f0aa285bcbfeaab8b9d82..08353effb33416bd767f3e559f61df0c023bf1c2 100644 (file)
@@ -271,8 +271,12 @@ void               _cf_log(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int lin
 
 #define                cf_log_perr(_cf, _fmt, ...) _cf_log_perr(L_ERR, CF_TO_ITEM(_cf),  __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
 #define                cf_log_pwarn(_cf, _fmt, ...) _cf_log_perr(L_WARN, CF_TO_ITEM(_cf),  __FILE__, __LINE__, NULL, _fmt, ## __VA_ARGS__)
+
+void           _cf_vlog_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
+                             fr_log_perror_format_t const *f_rules, char const *fmt, va_list ap)
+               CC_HINT(format (printf, 6, 0));
 void           _cf_log_perr(fr_log_type_t type, CONF_ITEM const *ci, char const *file, int line,
-                            fr_log_perror_format_t const *f_rules, char const *fmt, ...)
+                             fr_log_perror_format_t const *f_rules, char const *fmt, ...)
                CC_HINT(format (printf, 6, 7));
 
 #define                cf_log_debug_prefix(_cf, _fmt, ...) _cf_log_with_filename(L_DBG, CF_TO_ITEM(_cf),  __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
@@ -287,6 +291,15 @@ void               _cf_log_with_filename(fr_log_type_t type, CONF_ITEM const *ci, char const
  */
 #define                cf_log_err_by_child(_parent, _child, _fmt, ...) _cf_log_by_child(L_ERR, _parent, _child, __FILE__, __LINE__, _fmt, ## __VA_ARGS__)
 
+/** Log an error message against a specified child, draining the thread local error stack
+ *
+ * @param[in] _parent  CONF_SECTION.
+ * @param[in] _child   string identifier.
+ * @param[in] _fmt     of message.
+ * @param[in] ...      arguments.
+ */
+#define                cf_log_perr_by_child(_parent, _child, _f_rules, _fmt, ...) _cf_log_perr_by_child(L_ERR, _parent, _child, __FILE__, __LINE__, _f_rules, _fmt, ## __VA_ARGS__)
+
 /** Log a warning message against a specified child
  *
  * @param[in] _parent  CONF_SECTION.
@@ -316,6 +329,10 @@ void               _cf_log_with_filename(fr_log_type_t type, CONF_ITEM const *ci, char const
 void           _cf_log_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child,
                                   char const *file, int line, char const *fmt, ...) CC_HINT(format (printf, 6, 7));
 
+void           _cf_log_perr_by_child(fr_log_type_t type, CONF_SECTION const *parent, char const *child,
+                                     char const *file, int line, fr_log_perror_format_t const *f_rules,
+                                     char const *fmt, ...) CC_HINT(format (printf, 7, 8));
+
 #define                cf_debug(_cf) _cf_debug(CF_TO_ITEM(_cf))
 void           _cf_debug(CONF_ITEM const *ci);
 #ifdef __cplusplus