From bf2d5da310363866f1459553f535cbdb8e7857aa Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 11 Oct 2005 16:28:08 +0000 Subject: [PATCH] * syslog.cc (try_connect_syslogd): Add priority parameter. Use writev to add the priority to the message in a syslog conformant way. (vsyslog): If facility isn't set in the priority, use default facility as given in call to openlog. Fix agressive use of spaces in syslog output. Call try_connect_syslogd with priority parameter. --- winsup/cygwin/ChangeLog | 8 ++++++++ winsup/cygwin/syslog.cc | 44 +++++++++++++++++++++++++++-------------- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 6eef4f0e9..f72fdd813 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,11 @@ +2005-10-11 Corinna Vinschen + + * syslog.cc (try_connect_syslogd): Add priority parameter. Use writev + to add the priority to the message in a syslog conformant way. + (vsyslog): If facility isn't set in the priority, use default facility + as given in call to openlog. Fix agressive use of spaces in syslog + output. Call try_connect_syslogd with priority parameter. + 2005-10-11 Christopher Faylor * (symlink_info::set_error): Change to return bool if input error diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc index 38c8ecc31..1a56f0758 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -17,6 +17,7 @@ details. */ #include #include #include +#include #include "cygerrno.h" #include "security.h" #include "path.h" @@ -189,7 +190,7 @@ extern "C" int cygwin_socket (int, int, int); extern "C" int cygwin_connect (int, const struct sockaddr *, int); static int -try_connect_syslogd (const char *msg, int len) +try_connect_syslogd (int priority, const char *msg, int len) { try_connect_guard.init ("try_connect_guard")->acquire (); if (!syslogd_inited) @@ -225,10 +226,19 @@ try_connect_syslogd (const char *msg, int len) syslogd_inited = true; } out: - int ret = -1; + ssize_t ret = -1; if (syslogd_sock >= 0) { - ret = write (syslogd_sock, msg, len); + char pribuf[16]; + sprintf (pribuf, "<%d>", priority); + struct iovec iv[2] = + { + { pribuf, strlen (pribuf) }, + { (char *) msg, len } + }; + + + ret = writev (syslogd_sock, iv, 2); /* If write fails and LOG_CONS is set, return failure to vsyslog so it falls back to the usual logging method for this OS. */ if (ret >= 0 || !(_my_tls.locals.process_logopt & LOG_CONS)) @@ -260,6 +270,10 @@ vsyslog (int priority, const char *message, va_list ap) return; } + /* Add default facility if not in the given priority. */ + if (!(priority & LOG_FACMASK)) + priority |= _my_tls.locals.process_facility; + /* Translate %m in the message to error text */ char *errtext = strerror (get_errno ()); int errlen = strlen (errtext); @@ -334,12 +348,12 @@ vsyslog (int priority, const char *message, va_list ap) /* Deal with ident_string */ if (_my_tls.locals.process_ident != NULL) { - if (pass.print ("%s : ", _my_tls.locals.process_ident) == -1) + if (pass.print ("%s: ", _my_tls.locals.process_ident) == -1) return; } if (_my_tls.locals.process_logopt & LOG_PID) { - if (pass.print ("PID %u : ", getpid ()) == -1) + if (pass.print ("PID %u: ", getpid ()) == -1) return; } @@ -350,31 +364,31 @@ vsyslog (int priority, const char *message, va_list ap) switch (LOG_PRI (priority)) { case LOG_EMERG: - pass.print ("%s : ", "LOG_EMERG"); + pass.print ("%s: ", "LOG_EMERG"); break; case LOG_ALERT: - pass.print ("%s : ", "LOG_ALERT"); + pass.print ("%s: ", "LOG_ALERT"); break; case LOG_CRIT: - pass.print ("%s : ", "LOG_CRIT"); + pass.print ("%s: ", "LOG_CRIT"); break; case LOG_ERR: - pass.print ("%s : ", "LOG_ERR"); + pass.print ("%s: ", "LOG_ERR"); break; case LOG_WARNING: - pass.print ("%s : ", "LOG_WARNING"); + pass.print ("%s: ", "LOG_WARNING"); break; case LOG_NOTICE: - pass.print ("%s : ", "LOG_NOTICE"); + pass.print ("%s: ", "LOG_NOTICE"); break; case LOG_INFO: - pass.print ("%s : ", "LOG_INFO"); + pass.print ("%s: ", "LOG_INFO"); break; case LOG_DEBUG: - pass.print ("%s : ", "LOG_DEBUG"); + pass.print ("%s: ", "LOG_DEBUG"); break; default: - pass.print ("%s : ", "LOG_ERR"); + pass.print ("%s: ", "LOG_ERR"); break; } } @@ -396,7 +410,7 @@ vsyslog (int priority, const char *message, va_list ap) write (STDERR_FILENO, total_msg, len + 1); int fd; - if ((fd = try_connect_syslogd (total_msg, len + 1)) >= 0) + if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) >= 0) ; else if (wincap.has_eventlog ()) {