libsyslog: honor LIB_PTRIM when logging to stderr

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2022-08-01 11:30:54 +02:00
parent 221ae0abe0
commit 4fdbb64c51
2 changed files with 13 additions and 3 deletions

View File

@ -477,11 +477,21 @@ output:
DEC();
cnt = p - tbuf;
/* Output to stderr if requested. */
/* Output to stderr if requested, PTRIM logs only message. */
if (data->log_stat & LOG_PERROR) {
struct iovec *piov;
int piovcnt;
iov[iovcnt].iov_base = __UNCONST(CRLF + 1);
iov[iovcnt].iov_len = 1;
(void)writev(STDERR_FILENO, iov, iovcnt + 1);
if (data->log_stat & LOG_PTRIM) {
piov = &iov[iovcnt - 1];
piovcnt = 2;
} else {
piov = iov;
piovcnt = iovcnt + 1;
}
(void)writev(STDERR_FILENO, piov, piovcnt + 1);
}
/* Don't write to system log, instead use fd in log_file */

View File

@ -187,7 +187,7 @@ CODE facilitynames[] = {
#define LOG_NDELAY 0x008 /* don't delay open */
#define LOG_NOWAIT 0x010 /* don't wait for console forks: DEPRECATED */
#define LOG_PERROR 0x020 /* log to stderr as well */
#define LOG_PTRIM 0x040 /* trim tag and pid from messages to stderr */
#define LOG_PTRIM 0x040 /* trim anything syslog addded when writing to stderr */
#define LOG_NLOG 0x080 /* don't write to the system log */
#define LOG_STDOUT 0x100 /* like nlog, for debugging syslogp() API */
#define LOG_RFC3164 0x200 /* Log to remote/ipc socket in old BSD format */