From fbcf10c86d70cb3d4bc6f159a5165b596c9cd850 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 3 Dec 2024 01:45:54 +0200 Subject: [PATCH] LibC: Implement closelog and make syslog print to stddbg --- userspace/libraries/LibC/printf_impl.cpp | 1 + userspace/libraries/LibC/syslog.cpp | 26 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/userspace/libraries/LibC/printf_impl.cpp b/userspace/libraries/LibC/printf_impl.cpp index 58153ed5..cf9e8283 100644 --- a/userspace/libraries/LibC/printf_impl.cpp +++ b/userspace/libraries/LibC/printf_impl.cpp @@ -580,6 +580,7 @@ extern "C" int printf_impl(const char* format, va_list arguments, int (*putc_fun case 'm': { // NOTE: this is a glibc extension + // NOTE: syslog() requires %m to be handled if (options.alternate_form) string = strerrorname_np(errno); else diff --git a/userspace/libraries/LibC/syslog.cpp b/userspace/libraries/LibC/syslog.cpp index 696867ed..136d820c 100644 --- a/userspace/libraries/LibC/syslog.cpp +++ b/userspace/libraries/LibC/syslog.cpp @@ -1,12 +1,30 @@ #include + +#include +#include #include -void openlog(const char*, int, int) +static const char* s_ident = nullptr; + +void openlog(const char* ident, int option, int facility) { - ASSERT_NOT_REACHED(); + (void)option; + (void)facility; + s_ident = ident; } -void syslog(int, const char*, ...) +void syslog(int priority, const char* format, ...) { - ASSERT_NOT_REACHED(); + (void)priority; + if (s_ident) + fprintf(stddbg, "%s", s_ident); + va_list args; + va_start(args, format); + vfprintf(stddbg, format, args); + va_end(args); +} + +void closelog() +{ + s_ident = nullptr; }