From 86c40fb162ecb7b6de0fb34bb6af8f8121e124ba Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Wed, 16 Mar 2011 12:20:17 +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 | 38 +++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog index 52d0993..c717960 100644 --- a/winsup/cygwin/ChangeLog +++ b/winsup/cygwin/ChangeLog @@ -1,3 +1,14 @@ +2011-03-16 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-14 Corinna Vinschen * uinfo.cc (cygheap_user::env_domain): Use LookupAccountSidW and 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 b27f0e7..741cbeb 100644 --- a/winsup/cygwin/syslog.cc +++ b/winsup/cygwin/syslog.cc @@ -24,8 +24,9 @@ details. */ #include "dtable.h" #include "cygheap.h" #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 @@ -41,13 +42,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; @@ -357,7 +358,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) @@ -371,14 +372,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); @@ -389,17 +387,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