From 23c408d49d3e64b6705f5d81874317a63099dbae Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 18 Feb 2023 13:45:00 +0000 Subject: [PATCH] Move the logeventf wrappers into their own source file. Separating them from logging.c allows them to be shared between the real logging.c and the new stub no-logging.c. --- CMakeLists.txt | 5 +++-- logging.c | 20 -------------------- unix/CMakeLists.txt | 4 ++-- utils/logeventf.c | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 37 insertions(+), 24 deletions(-) create mode 100644 utils/logeventf.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e62d0a6..7da0cbc3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ add_subdirectory(utils) add_subdirectory(stubs) add_library(logging OBJECT - logging.c) + logging.c utils/logeventf.c) add_library(eventloop STATIC callback.c timing.c) @@ -34,7 +34,8 @@ add_library(crypto STATIC add_subdirectory(crypto) add_library(network STATIC - errsock.c logging.c x11disp.c + errsock.c x11disp.c + $ proxy/proxy.c proxy/http.c proxy/socks4.c diff --git a/logging.c b/logging.c index e065f1a4..147feb9a 100644 --- a/logging.c +++ b/logging.c @@ -253,26 +253,6 @@ void logevent(LogContext *ctx, const char *event) } } -void logevent_and_free(LogContext *ctx, char *event) -{ - logevent(ctx, event); - sfree(event); -} - -void logeventvf(LogContext *ctx, const char *fmt, va_list ap) -{ - logevent_and_free(ctx, dupvprintf(fmt, ap)); -} - -void logeventf(LogContext *ctx, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - logeventvf(ctx, fmt, ap); - va_end(ap); -} - /* * Log an SSH packet. * If n_blanks != 0, blank or omit some parts. diff --git a/unix/CMakeLists.txt b/unix/CMakeLists.txt index 2ea1416c..37c39144 100644 --- a/unix/CMakeLists.txt +++ b/unix/CMakeLists.txt @@ -52,10 +52,10 @@ add_sources_from_current_dir(agent add_executable(fuzzterm ${CMAKE_SOURCE_DIR}/test/fuzzterm.c - ${CMAKE_SOURCE_DIR}/logging.c ${CMAKE_SOURCE_DIR}/stubs/no-print.c unicode.c - no-gtk.c) + no-gtk.c + $) be_list(fuzzterm FuZZterm) add_dependencies(fuzzterm generated_licence_h) target_link_libraries(fuzzterm diff --git a/utils/logeventf.c b/utils/logeventf.c new file mode 100644 index 00000000..ba162612 --- /dev/null +++ b/utils/logeventf.c @@ -0,0 +1,32 @@ +/* + * Helpful wrapper functions around the raw logevent(). + * + * This source file lives in 'utils' because it's conceptually a + * convenience utility rather than core functionality. But it can't + * live in the utils _library_, because then it might refer to + * logevent() in an earlier library after Unix ld had already finished + * searching that library, and cause a link failure. So it must live + * alongside logging.c. + */ + +#include "putty.h" + +void logevent_and_free(LogContext *ctx, char *event) +{ + logevent(ctx, event); + sfree(event); +} + +void logeventvf(LogContext *ctx, const char *fmt, va_list ap) +{ + logevent_and_free(ctx, dupvprintf(fmt, ap)); +} + +void logeventf(LogContext *ctx, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + logeventvf(ctx, fmt, ap); + va_end(ap); +}