* 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.
This commit is contained in:
Corinna Vinschen 2011-03-29 11:18:10 +00:00
parent 39735c85f2
commit da00863389
3 changed files with 32 additions and 18 deletions

View File

@ -1,3 +1,14 @@
2011-03-29 Corinna Vinschen <corinna@vinschen.de>
* 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 <corinna@vinschen.de> 2011-03-29 Corinna Vinschen <corinna@vinschen.de>
* fhandler_socket.cc (get_inet_addr): Make externally available. * fhandler_socket.cc (get_inet_addr): Make externally available.

View File

@ -115,7 +115,7 @@ struct _local_storage
char strerror_buf[sizeof ("Unknown error 4294967295")]; char strerror_buf[sizeof ("Unknown error 4294967295")];
/* sysloc.cc */ /* sysloc.cc */
char *process_ident; // note: malloced wchar_t *process_ident; // note: malloced
int process_logopt; int process_logopt;
int process_facility; int process_facility;
int process_logmask; int process_logmask;

View File

@ -28,7 +28,7 @@ details. */
#include "cygtls.h" #include "cygtls.h"
#include "tls_pbuf.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. */ /* openlog: save the passed args. Don't open the system log or /dev/log yet. */
extern "C" void extern "C" void
@ -44,13 +44,13 @@ openlog (const char *ident, int logopt, int facility)
} }
if (ident) 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) 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; return;
} }
strcpy (_my_tls.locals.process_ident, ident);
} }
_my_tls.locals.process_logopt = logopt; _my_tls.locals.process_logopt = logopt;
_my_tls.locals.process_facility = facility; _my_tls.locals.process_facility = facility;
@ -378,7 +378,7 @@ 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 ("%ls: ", _my_tls.locals.process_ident) == -1)
return; return;
} }
if (_my_tls.locals.process_logopt & LOG_PID) if (_my_tls.locals.process_logopt & LOG_PID)
@ -392,14 +392,11 @@ vsyslog (int priority, const char *message, va_list ap)
return; return;
} }
const char *msg_strings[1];
char *total_msg = pass.get_message (); char *total_msg = pass.get_message ();
int len = strlen (total_msg); int len = strlen (total_msg);
if (len != 0 && (total_msg[len - 1] == '\n')) if (len != 0 && (total_msg[len - 1] == '\n'))
total_msg[--len] = '\0'; total_msg[--len] = '\0';
msg_strings[0] = total_msg;
if (_my_tls.locals.process_logopt & LOG_PERROR) if (_my_tls.locals.process_logopt & LOG_PERROR)
{ {
write (STDERR_FILENO, total_msg, len); write (STDERR_FILENO, total_msg, len);
@ -410,19 +407,25 @@ vsyslog (int priority, const char *message, va_list ap)
if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) < 0) if ((fd = try_connect_syslogd (priority, total_msg, len + 1)) < 0)
{ {
/* If syslogd isn't present, open the event log and send the message */ /* If syslogd isn't present, open the event log and send the message */
HANDLE hEventSrc = RegisterEventSourceA (NULL, (_my_tls.locals.process_ident != NULL) ? HANDLE hEventSrc;
_my_tls.locals.process_ident : CYGWIN_LOG_NAME);
if (hEventSrc == NULL) hEventSrc = RegisterEventSourceW (NULL, _my_tls.locals.process_ident
?: CYGWIN_LOG_NAME);
if (!hEventSrc)
debug_printf ("RegisterEventSourceW, %E");
else
{ {
debug_printf ("RegisterEventSourceA failed with %E"); wchar_t *msg_strings[1];
return; tmp_pathbuf tp;
} msg_strings[0] = tp.w_get ();
if (!ReportEventA (hEventSrc, eventType, 0, 0, sys_mbstowcs (msg_strings[0], NT_MAX_PATH, total_msg);
cygheap->user.sid (), 1, 0, msg_strings, NULL)) if (!ReportEventW (hEventSrc, eventType, 0, 0, cygheap->user.sid (),
debug_printf ("ReportEventA failed with %E"); 1, 0, (const wchar_t **) msg_strings, NULL))
debug_printf ("ReportEventW, %E");
DeregisterEventSource (hEventSrc); DeregisterEventSource (hEventSrc);
} }
} }
}
extern "C" void extern "C" void
syslog (int priority, const char *message, ...) syslog (int priority, const char *message, ...)