From 053d1808171dd08927554243c2bf665e1121bf48 Mon Sep 17 00:00:00 2001 From: Dan Travison Date: Fri, 20 Oct 2017 09:03:59 -0700 Subject: [PATCH] Add exports for syslog APIs in 'libpsl-native'. (#5149) --- src/libpsl-native/src/CMakeLists.txt | 3 ++- src/libpsl-native/src/nativesyslog.cpp | 35 ++++++++++++++++++++++++++ src/libpsl-native/src/nativesyslog.h | 11 ++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 src/libpsl-native/src/nativesyslog.cpp create mode 100644 src/libpsl-native/src/nativesyslog.h diff --git a/src/libpsl-native/src/CMakeLists.txt b/src/libpsl-native/src/CMakeLists.txt index 28cb4a7611..bb2e88e462 100644 --- a/src/libpsl-native/src/CMakeLists.txt +++ b/src/libpsl-native/src/CMakeLists.txt @@ -21,6 +21,7 @@ add_library(psl-native SHARED createhardlink.cpp createsymlink.cpp followsymlink.cpp - createprocess.cpp) + createprocess.cpp + nativesyslog.cpp) target_include_directories(psl-native PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/libpsl-native/src/nativesyslog.cpp b/src/libpsl-native/src/nativesyslog.cpp new file mode 100644 index 0000000000..1445c59a14 --- /dev/null +++ b/src/libpsl-native/src/nativesyslog.cpp @@ -0,0 +1,35 @@ +//! @file nativesyslog.cpp +//! @brief Provides wrappers around the syslog apis to support exporting +//! for PInvoke calls by powershell. +//! These functions are intended only for PowerShell internal use. +#include +#include + +//! @brief Native_SysLog is a wrapper around the syslog api. +//! It explicitly passes the message as a parameter to a %s format +//! string since the message may have arbitray characters that can +//! be misinterpreted as format specifiers. +//! +//! @retval none. +extern "C" void Native_SysLog(int32_t priority, const char* message) +{ + syslog(priority, "%s", message); +} + +//! @brief Native_OpenLog is a wrapper around the openlog, syslog api. +//! it allows passing an ident and facility but uses an explicit +//! option value for consistent logging across powershell instances. +//! +//! @retval none. +extern "C" void Native_OpenLog(const char* ident, int facility) +{ + openlog(ident, LOG_NDELAY | LOG_PID, facility); +} + +//! @brief Native_OpenLog is a wrapper around the closelog, syslog api. +//! +//! @retval none. +extern "C" void Native_CloseLog() +{ + closelog(); +} diff --git a/src/libpsl-native/src/nativesyslog.h b/src/libpsl-native/src/nativesyslog.h new file mode 100644 index 0000000000..71b222fa4d --- /dev/null +++ b/src/libpsl-native/src/nativesyslog.h @@ -0,0 +1,11 @@ +#pragma once + +#include "pal.h" + +PAL_BEGIN_EXTERNC + +void Native_OpenLog(const char* ident, int facility); +void Native_SysLog(int32_t priority, const char* message); +void Native_CloseLog(); + +PAL_END_EXTERNC