* 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.
This commit is contained in:
Corinna Vinschen 2005-10-11 16:28:08 +00:00
parent 143bf87846
commit bf2d5da310
2 changed files with 37 additions and 15 deletions

View File

@ -1,3 +1,11 @@
2005-10-11 Corinna Vinschen <corinna@vinschen.de>
* 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 <cgf@timesys.com> 2005-10-11 Christopher Faylor <cgf@timesys.com>
* (symlink_info::set_error): Change to return bool if input error * (symlink_info::set_error): Change to return bool if input error

View File

@ -17,6 +17,7 @@ details. */
#include <stdarg.h> #include <stdarg.h>
#include <unistd.h> #include <unistd.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/uio.h>
#include "cygerrno.h" #include "cygerrno.h"
#include "security.h" #include "security.h"
#include "path.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); extern "C" int cygwin_connect (int, const struct sockaddr *, int);
static 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 (); try_connect_guard.init ("try_connect_guard")->acquire ();
if (!syslogd_inited) if (!syslogd_inited)
@ -225,10 +226,19 @@ try_connect_syslogd (const char *msg, int len)
syslogd_inited = true; syslogd_inited = true;
} }
out: out:
int ret = -1; ssize_t ret = -1;
if (syslogd_sock >= 0) 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 /* If write fails and LOG_CONS is set, return failure to vsyslog so
it falls back to the usual logging method for this OS. */ it falls back to the usual logging method for this OS. */
if (ret >= 0 || !(_my_tls.locals.process_logopt & LOG_CONS)) if (ret >= 0 || !(_my_tls.locals.process_logopt & LOG_CONS))
@ -260,6 +270,10 @@ vsyslog (int priority, const char *message, va_list ap)
return; 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 */ /* Translate %m in the message to error text */
char *errtext = strerror (get_errno ()); char *errtext = strerror (get_errno ());
int errlen = strlen (errtext); int errlen = strlen (errtext);
@ -334,12 +348,12 @@ vsyslog (int priority, const char *message, va_list ap)
/* Deal with ident_string */ /* Deal with ident_string */
if (_my_tls.locals.process_ident != NULL) 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; return;
} }
if (_my_tls.locals.process_logopt & LOG_PID) if (_my_tls.locals.process_logopt & LOG_PID)
{ {
if (pass.print ("PID %u : ", getpid ()) == -1) if (pass.print ("PID %u: ", getpid ()) == -1)
return; return;
} }
@ -350,31 +364,31 @@ vsyslog (int priority, const char *message, va_list ap)
switch (LOG_PRI (priority)) switch (LOG_PRI (priority))
{ {
case LOG_EMERG: case LOG_EMERG:
pass.print ("%s : ", "LOG_EMERG"); pass.print ("%s: ", "LOG_EMERG");
break; break;
case LOG_ALERT: case LOG_ALERT:
pass.print ("%s : ", "LOG_ALERT"); pass.print ("%s: ", "LOG_ALERT");
break; break;
case LOG_CRIT: case LOG_CRIT:
pass.print ("%s : ", "LOG_CRIT"); pass.print ("%s: ", "LOG_CRIT");
break; break;
case LOG_ERR: case LOG_ERR:
pass.print ("%s : ", "LOG_ERR"); pass.print ("%s: ", "LOG_ERR");
break; break;
case LOG_WARNING: case LOG_WARNING:
pass.print ("%s : ", "LOG_WARNING"); pass.print ("%s: ", "LOG_WARNING");
break; break;
case LOG_NOTICE: case LOG_NOTICE:
pass.print ("%s : ", "LOG_NOTICE"); pass.print ("%s: ", "LOG_NOTICE");
break; break;
case LOG_INFO: case LOG_INFO:
pass.print ("%s : ", "LOG_INFO"); pass.print ("%s: ", "LOG_INFO");
break; break;
case LOG_DEBUG: case LOG_DEBUG:
pass.print ("%s : ", "LOG_DEBUG"); pass.print ("%s: ", "LOG_DEBUG");
break; break;
default: default:
pass.print ("%s : ", "LOG_ERR"); pass.print ("%s: ", "LOG_ERR");
break; break;
} }
} }
@ -396,7 +410,7 @@ vsyslog (int priority, const char *message, va_list ap)
write (STDERR_FILENO, total_msg, len + 1); write (STDERR_FILENO, total_msg, len + 1);
int fd; 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 ()) else if (wincap.has_eventlog ())
{ {