Skip to content

Commit 053d180

Browse files
dantraMSFTdaxian-dbw
authored andcommitted
Add exports for syslog APIs in 'libpsl-native'. (#5149)
1 parent 1c469aa commit 053d180

3 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/libpsl-native/src/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ add_library(psl-native SHARED
2121
createhardlink.cpp
2222
createsymlink.cpp
2323
followsymlink.cpp
24-
createprocess.cpp)
24+
createprocess.cpp
25+
nativesyslog.cpp)
2526

2627
target_include_directories(psl-native PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//! @file nativesyslog.cpp
2+
//! @brief Provides wrappers around the syslog apis to support exporting
3+
//! for PInvoke calls by powershell.
4+
//! These functions are intended only for PowerShell internal use.
5+
#include <syslog.h>
6+
#include <nativesyslog.h>
7+
8+
//! @brief Native_SysLog is a wrapper around the syslog api.
9+
//! It explicitly passes the message as a parameter to a %s format
10+
//! string since the message may have arbitray characters that can
11+
//! be misinterpreted as format specifiers.
12+
//!
13+
//! @retval none.
14+
extern "C" void Native_SysLog(int32_t priority, const char* message)
15+
{
16+
syslog(priority, "%s", message);
17+
}
18+
19+
//! @brief Native_OpenLog is a wrapper around the openlog, syslog api.
20+
//! it allows passing an ident and facility but uses an explicit
21+
//! option value for consistent logging across powershell instances.
22+
//!
23+
//! @retval none.
24+
extern "C" void Native_OpenLog(const char* ident, int facility)
25+
{
26+
openlog(ident, LOG_NDELAY | LOG_PID, facility);
27+
}
28+
29+
//! @brief Native_OpenLog is a wrapper around the closelog, syslog api.
30+
//!
31+
//! @retval none.
32+
extern "C" void Native_CloseLog()
33+
{
34+
closelog();
35+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include "pal.h"
4+
5+
PAL_BEGIN_EXTERNC
6+
7+
void Native_OpenLog(const char* ident, int facility);
8+
void Native_SysLog(int32_t priority, const char* message);
9+
void Native_CloseLog();
10+
11+
PAL_END_EXTERNC

0 commit comments

Comments
 (0)