From da0086338992af1ca0cb8dfdab3199a36473611b Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Tue, 29 Mar 2011 11:18:10 +0000 Subject: * cygtls.h (struct _local_storage): Redefine process_ident as wchar_t pointer. * syslog.cc (CYGWIN_LOG_NAME): Convert to wide char constant. (openlog): Convert incoming ident string to wide char. Fix formatting. (vsyslog): Print ident string as wide char string. Convert message string to wide char and call UNICODE Win32 Event functions to make sure to use correct codeset. * tlsoffset.h: Regenerate. --- winsup/cygwin/ChangeLog | 11 +++++++++++ winsup/cygwin/cygtls.h | 2 +- winsup/cygwin/syslog.cc | 37 ++++++++++++++++++++----------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index de21767..bb9489a 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,5 +1,16 @@ 2011-03-29 Corinna Vinschen + * cygtls.h (struct _local_storage): Redefine process_ident as wchar_t + pointer. + * syslog.cc (CYGWIN_LOG_NAME): Convert to wide char constant. + (openlog): Convert incoming ident string to wide char. Fix formatting. + (vsyslog): Print ident string as wide char string. Convert message + string to wide char and call UNICODE Win32 Event functions to make sure + to use correct codeset. + * tlsoffset.h: Regenerate. + +2011-03-29 Corinna Vinschen + * fhandler_socket.cc (get_inet_addr): Make externally available. * autoload.cc (GetUdpTable): Define. * syslog.cc (connect_syslogd): Use get_inet_addr rather than _stat64 diff --git a/winsup/cygwin/cygtls.h b/winsup/cygwin/cygtls.h index 408bcc2..230a7e3 100644 --- a/winsup/cygwin/cygtls.h +++ b/winsup/cygwin/cygtls.h @@ -115,7 +115,7 @@ struct _local_storage char strerror_buf[sizeof ("Unknown error 4294967295")]; /* sysloc.cc */ - char *process_ident; // note: malloced + wchar_t *process_ident; // note: malloced int process_logopt; int process_facility; int process_logmask; diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc index 1aafbd3..d812105 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -28,7 +28,7 @@ details. */ #include "cygtls.h" #include "tls_pbuf.h" -#define CYGWIN_LOG_NAME "Cygwin" +#define CYGWIN_LOG_NAME L"Cygwin" /* openlog: save the passed args. Don't open the system log or /dev/log yet. */ extern "C" void @@ -44,13 +44,13 @@ openlog (const char *ident, int logopt, int facility) } if (ident) { - _my_tls.locals.process_ident = (char *) malloc (strlen (ident) + 1); + sys_mbstowcs_alloc (&_my_tls.locals.process_ident, HEAP_NOTHEAP, ident); if (!_my_tls.locals.process_ident) { - debug_printf ("failed to allocate memory for _my_tls.locals.process_ident"); + debug_printf ("failed to allocate memory for " + "_my_tls.locals.process_ident"); return; } - strcpy (_my_tls.locals.process_ident, ident); } _my_tls.locals.process_logopt = logopt; _my_tls.locals.process_facility = facility; @@ -378,7 +378,7 @@ 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 ("%ls: ", _my_tls.locals.process_ident) == -1) return; } if (_my_tls.locals.process_logopt & LOG_PID) @@ -392,14 +392,11 @@ vsyslog (int priority, const char *message, va_list ap) return; } - const char *msg_strings[1]; char *total_msg = pass.get_message (); int len = strlen (total_msg); if (len != 0 && (total_msg[len - 1] == '\n')) total_msg[--len] = '\0'; - msg_strings[0] = total_msg; - if (_my_tls.locals.process_logopt & LOG_PERROR) { write (STDERR_FILENO, total_msg, len); @@ -410,17 +407,23 @@ vsyslog (int priority, const char *message, va_list ap) if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) < 0) { /* If syslogd isn't present, open the event log and send the message */ - HANDLE hEventSrc = RegisterEventSourceA (NULL, (_my_tls.locals.process_ident != NULL) ? - _my_tls.locals.process_ident : CYGWIN_LOG_NAME); - if (hEventSrc == NULL) + HANDLE hEventSrc; + + hEventSrc = RegisterEventSourceW (NULL, _my_tls.locals.process_ident + ?: CYGWIN_LOG_NAME); + if (!hEventSrc) + debug_printf ("RegisterEventSourceW, %E"); + else { - debug_printf ("RegisterEventSourceA failed with %E"); - return; + wchar_t *msg_strings[1]; + tmp_pathbuf tp; + msg_strings[0] = tp.w_get (); + sys_mbstowcs (msg_strings[0], NT_MAX_PATH, total_msg); + if (!ReportEventW (hEventSrc, eventType, 0, 0, cygheap->user.sid (), + 1, 0, (const wchar_t **) msg_strings, NULL)) + debug_printf ("ReportEventW, %E"); + DeregisterEventSource (hEventSrc); } - if (!ReportEventA (hEventSrc, eventType, 0, 0, - cygheap->user.sid (), 1, 0, msg_strings, NULL)) - debug_printf ("ReportEventA failed with %E"); - DeregisterEventSource (hEventSrc); } } -- cgit v1.1