Andrzej Kurek | e1f26b8 | 2018-02-19 03:57:07 -0500 | [diff] [blame^] | 1 | /** \brief Syslog to stderr wrapper for Unix-like systems |
| 2 | * |
| 3 | * By dynamically linking this module into an executable, any message sent to the system logs |
| 4 | * via the POSIX or Linux API is instead redirected to standard error. |
| 5 | * |
| 6 | * Compile this program with `cc -fPID -shared -o syslog2stderr.so syslog2stderr.c -ldl` |
| 7 | * and load it dynamically when running `myprogram` with |
| 8 | * `LD_PRELOAD=/path/to/syslog2stderr.so myprogram`. |
| 9 | * On macOS, replace `LD_PRELOAD` by `DYLD_PRELOAD`. |
| 10 | */ |
| 11 | /** |
| 12 | * Copyright (C) 2017-2018, ARM Limited, All Rights Reserved |
| 13 | * SPDX-License-Identifier: Apache-2.0 |
| 14 | * |
| 15 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 16 | * not use this file except in compliance with the License. |
| 17 | * You may obtain a copy of the License at |
| 18 | * |
| 19 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 20 | * |
| 21 | * Unless required by applicable law or agreed to in writing, software |
| 22 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 23 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 24 | * See the License for the specific language governing permissions and |
| 25 | * limitations under the License. |
| 26 | * |
| 27 | * This file is part of mbed TLS (https://tls.mbed.org) |
| 28 | */ |
Andrzej Kurek | 4226dec | 2018-01-23 05:51:11 -0500 | [diff] [blame] | 29 | #include <dlfcn.h> |
| 30 | #include <stdarg.h> |
| 31 | #include <stdio.h> |
| 32 | #include <stdlib.h> |
| 33 | #include <string.h> |
| 34 | #include <syslog.h> |
| 35 | |
| 36 | |
| 37 | void openlog( const char *ident, int option, int facility ) |
| 38 | { |
| 39 | (void) ident; |
| 40 | (void) option; |
| 41 | (void) facility; |
| 42 | } |
| 43 | |
| 44 | /* POSIX API */ |
| 45 | void syslog( int priority, const char *format, ... ) |
| 46 | { |
| 47 | va_list args; |
| 48 | va_start( args, format ); |
| 49 | vfprintf( stderr, format, args ); |
| 50 | va_end( args ); |
| 51 | } |
| 52 | |
| 53 | /* Linux ABI |
| 54 | * http://refspecs.linux-foundation.org/LSB_4.1.0/LSB-Core-generic/LSB-Core-generic/libc---syslog-chk-1.html |
| 55 | */ |
| 56 | void __syslog_chk( int priority, int flag, const char *format, ... ) |
| 57 | { |
| 58 | va_list args; |
| 59 | (int) flag; |
| 60 | va_start( args, format ); |
| 61 | vfprintf( stderr, format, args ); |
| 62 | fputc( '\n', stderr ); |
| 63 | va_end( args ); |
| 64 | } |
| 65 | |
| 66 | void closelog( void ) |
| 67 | { |
| 68 | /* no-op */ |
| 69 | } |