[LTP] [PATCH v8 1/2] coredump01: New core_pattern specifiers test

Cyril Hrubis chrubis@suse.cz
Tue Sep 8 17:34:07 CEST 2026


Hi!
> +static void set_pattern(const char *fmt, ...)
> +{
> +	char pattern[PATTERN_MAX];
> +	char readback[PATTERN_MAX];
> +	va_list va;
> +	int len;
> +
> +	va_start(va, fmt);
> +	len = vsnprintf(pattern, sizeof(pattern), fmt, va);
> +	va_end(va);
> +
> +	if (len >= PATTERN_MAX)
> +		tst_brk(TCONF, "core_pattern does not fit into %i bytes", PATTERN_MAX - 1);
> +
> +	SAFE_FILE_PRINTF(PATH_KERN_CORE_PATTERN, "%s", pattern);

We actually have safe_file_vprintf() it's not just exposed, we can
easily expose the API with:

diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h
index 73ebd2ab8..f3b322072 100644
--- a/include/tst_safe_file_ops.h
+++ b/include/tst_safe_file_ops.h
@@ -65,6 +65,10 @@ void safe_file_read_str(const char *file, const int lineno,
        safe_file_printf(__FILE__, __LINE__, NULL, \
                         (path), (fmt), ## __VA_ARGS__)

+#define SAFE_FILE_VPRINTF(path, fmt, va) \
+       safe_file_vprintf(__FILE__, __LINE__, NULL, \
+                        (path), (fmt), va)
+
 /* Same as SAFE_FILE_PRINTF() but returns quietly if the path doesn't exist */
 #define SAFE_TRY_FILE_PRINTF(path, fmt, ...) \
        safe_try_file_printf(__FILE__, __LINE__, NULL, \
diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c
index 19da1fd97..1069a017f 100644
--- a/lib/safe_file_ops.c
+++ b/lib/safe_file_ops.c
@@ -280,7 +280,7 @@ err:
        return 1;
 }

-static void safe_file_vprintf(const char *file, const int lineno,
+void safe_file_vprintf(const char *file, const int lineno,
        void (*cleanup_fn)(void), const char *path, const char *fmt,
        va_list va)
 {



And then we can do SAFE_FILE_VPRINTF() here directly instead of the
double printf().


The rest looks fine:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list