4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-21 16:26:12 +08:00

* cygtls.cc (_cygtls::init_thread): Drop setting locals.process_logmask.

* cygtls.cc (_cygtls::remove): Always free mallocated TLS storage on
	thread exit.  Drop freeing locals.process_ident.
	* cygtls.h (struct _local_storage): Remove syslog-related members.
	* syslog.cc (syslog_globals): New static storage for global syslog
	settings.  Use throughout instead of _my_tls.locals.
	(openlog): Set new syslog_globals.process_ident value more carefully.
	* tlsoffsets.h: Regenerate.
This commit is contained in:
Corinna Vinschen 2011-04-21 08:10:28 +00:00
parent 2656876fb3
commit a0307f9914
5 changed files with 103 additions and 92 deletions

View File

@ -1,3 +1,14 @@
2011-04-21 Corinna Vinschen <corinna@vinschen.de>
* cygtls.cc (_cygtls::init_thread): Drop setting locals.process_logmask.
* cygtls.cc (_cygtls::remove): Always free mallocated TLS storage on
thread exit. Drop freeing locals.process_ident.
* cygtls.h (struct _local_storage): Remove syslog-related members.
* syslog.cc (syslog_globals): New static storage for global syslog
settings. Use throughout instead of _my_tls.locals.
(openlog): Set new syslog_globals.process_ident value more carefully.
* tlsoffsets.h: Regenerate.
2011-04-21 Thomas Stalder <cygwinml@gmail.com> 2011-04-21 Thomas Stalder <cygwinml@gmail.com>
* include/sys/poll.h: Include signal.h to get definition of sigset_t. * include/sys/poll.h: Include signal.h to get definition of sigset_t.

View File

@ -93,7 +93,6 @@ _cygtls::init_thread (void *x, DWORD (*func) (void *, void *))
local_clib.__sglue._niobs = 3; local_clib.__sglue._niobs = 3;
local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0]; local_clib.__sglue._iobs = &_GLOBAL_REENT->__sf[0];
} }
locals.process_logmask = LOG_UPTO (LOG_DEBUG);
} }
thread_id = GetCurrentThreadId (); thread_id = GetCurrentThreadId ();
@ -146,25 +145,23 @@ _cygtls::remove (DWORD wait)
return; return;
debug_printf ("wait %p", wait); debug_printf ("wait %p", wait);
if (locals.select.sockevt)
CloseHandle (locals.select.sockevt);
if (wait)
{
/* FIXME: Need some sort of atthreadexit function to allow things like
select to control this themselves. */
if (locals.select.sockevt)
{
locals.select.sockevt = NULL;
free_local (select.ser_num);
free_local (select.w4);
}
free_local (process_ident);
free_local (ntoa_buf);
free_local (protoent_buf);
free_local (servent_buf);
free_local (hostent_buf);
}
/* FIXME: Need some sort of atthreadexit function to allow things like
select to control this themselves. */
/* Close handle and free memory used by select. */
if (locals.select.sockevt)
{
CloseHandle (locals.select.sockevt);
locals.select.sockevt = NULL;
free_local (select.ser_num);
free_local (select.w4);
}
/* Free memory used by network functions. */
free_local (ntoa_buf);
free_local (protoent_buf);
free_local (servent_buf);
free_local (hostent_buf);
/* Free temporary TLS path buffers. */ /* Free temporary TLS path buffers. */
locals.pathbufs.destroy (); locals.pathbufs.destroy ();

View File

@ -114,12 +114,6 @@ struct _local_storage
/* strerror */ /* strerror */
char strerror_buf[sizeof ("Unknown error 4294967295")]; char strerror_buf[sizeof ("Unknown error 4294967295")];
/* sysloc.cc */
wchar_t *process_ident; // note: malloced
int process_logopt;
int process_facility;
int process_logmask;
/* times.cc */ /* times.cc */
char timezone_buf[20]; char timezone_buf[20];
struct tm _localtime_buf; struct tm _localtime_buf;

View File

@ -30,30 +30,39 @@ details. */
#define CYGWIN_LOG_NAME L"Cygwin" #define CYGWIN_LOG_NAME L"Cygwin"
static struct
{
wchar_t *process_ident;
int process_logopt;
int process_facility;
int process_logmask;
} syslog_globals = { NULL, 0, 0, LOG_UPTO (LOG_DEBUG) };
/* 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
openlog (const char *ident, int logopt, int facility) openlog (const char *ident, int logopt, int facility)
{ {
wchar_t *new_ident = NULL;
debug_printf ("openlog called with (%s, %d, %d)", debug_printf ("openlog called with (%s, %d, %d)",
ident ? ident : "<NULL>", logopt, facility); ident ? ident : "<NULL>", logopt, facility);
if (_my_tls.locals.process_ident != NULL)
{
free (_my_tls.locals.process_ident);
_my_tls.locals.process_ident = NULL;
}
if (ident) if (ident)
{ {
sys_mbstowcs_alloc (&_my_tls.locals.process_ident, HEAP_NOTHEAP, ident); sys_mbstowcs_alloc (&new_ident, HEAP_NOTHEAP, ident);
if (!_my_tls.locals.process_ident) if (!new_ident)
{
debug_printf ("failed to allocate memory for " debug_printf ("failed to allocate memory for "
"_my_tls.locals.process_ident"); "syslog_globals.process_ident");
return; else
{
wchar_t *old_ident = syslog_globals.process_ident;
syslog_globals.process_ident = new_ident;
if (old_ident)
free (old_ident);
} }
} }
_my_tls.locals.process_logopt = logopt; syslog_globals.process_logopt = logopt;
_my_tls.locals.process_facility = facility; syslog_globals.process_facility = facility;
} }
/* setlogmask: set the log priority mask and return previous mask. /* setlogmask: set the log priority mask and return previous mask.
@ -62,10 +71,10 @@ int
setlogmask (int maskpri) setlogmask (int maskpri)
{ {
if (maskpri == 0) if (maskpri == 0)
return _my_tls.locals.process_logmask; return syslog_globals.process_logmask;
int old_mask = _my_tls.locals.process_logmask; int old_mask = syslog_globals.process_logmask;
_my_tls.locals.process_logmask = maskpri; syslog_globals.process_logmask = maskpri;
return old_mask; return old_mask;
} }
@ -269,7 +278,7 @@ try_connect_syslogd (int priority, const char *msg, int len)
} }
/* 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 || !(syslog_globals.process_logopt & LOG_CONS))
ret = syslogd_sock; ret = syslogd_sock;
} }
try_connect_guard.release (); try_connect_guard.release ();
@ -289,20 +298,20 @@ vsyslog (int priority, const char *message, va_list ap)
{ {
debug_printf ("%x %s", priority, message); debug_printf ("%x %s", priority, message);
/* If the priority fails the current mask, reject */ /* If the priority fails the current mask, reject */
if ((LOG_MASK (LOG_PRI (priority)) & _my_tls.locals.process_logmask) == 0) if ((LOG_MASK (LOG_PRI (priority)) & syslog_globals.process_logmask) == 0)
{ {
debug_printf ("failing message %x due to priority mask %x", debug_printf ("failing message %x due to priority mask %x",
priority, _my_tls.locals.process_logmask); priority, syslog_globals.process_logmask);
return; return;
} }
/* Set default facility to LOG_USER if not yet set via openlog. */ /* Set default facility to LOG_USER if not yet set via openlog. */
if (!_my_tls.locals.process_facility) if (!syslog_globals.process_facility)
_my_tls.locals.process_facility = LOG_USER; syslog_globals.process_facility = LOG_USER;
/* Add default facility if not in the given priority. */ /* Add default facility if not in the given priority. */
if (!(priority & LOG_FACMASK)) if (!(priority & LOG_FACMASK))
priority |= _my_tls.locals.process_facility; priority |= syslog_globals.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 ());
@ -376,12 +385,12 @@ vsyslog (int priority, const char *message, va_list ap)
pass.set_message ((char *) alloca (n)); pass.set_message ((char *) alloca (n));
/* Deal with ident_string */ /* Deal with ident_string */
if (_my_tls.locals.process_ident != NULL) if (syslog_globals.process_ident != NULL)
{ {
if (pass.print ("%ls: ", _my_tls.locals.process_ident) == -1) if (pass.print ("%ls: ", syslog_globals.process_ident) == -1)
return; return;
} }
if (_my_tls.locals.process_logopt & LOG_PID) if (syslog_globals.process_logopt & LOG_PID)
{ {
if (pass.print ("PID %u: ", getpid ()) == -1) if (pass.print ("PID %u: ", getpid ()) == -1)
return; return;
@ -397,7 +406,7 @@ vsyslog (int priority, const char *message, va_list ap)
if (len != 0 && (total_msg[len - 1] == '\n')) if (len != 0 && (total_msg[len - 1] == '\n'))
total_msg[--len] = '\0'; total_msg[--len] = '\0';
if (_my_tls.locals.process_logopt & LOG_PERROR) if (syslog_globals.process_logopt & LOG_PERROR)
{ {
write (STDERR_FILENO, total_msg, len); write (STDERR_FILENO, total_msg, len);
write (STDERR_FILENO, "\n", 1); write (STDERR_FILENO, "\n", 1);
@ -409,7 +418,7 @@ vsyslog (int priority, const char *message, va_list ap)
/* 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; HANDLE hEventSrc;
hEventSrc = RegisterEventSourceW (NULL, _my_tls.locals.process_ident hEventSrc = RegisterEventSourceW (NULL, syslog_globals.process_ident
?: CYGWIN_LOG_NAME); ?: CYGWIN_LOG_NAME);
if (!hEventSrc) if (!hEventSrc)
debug_printf ("RegisterEventSourceW, %E"); debug_printf ("RegisterEventSourceW, %E");

View File

@ -1,6 +1,6 @@
//;# autogenerated: Do not edit. //;# autogenerated: Do not edit.
//; $tls::sizeof__cygtls = 4304; //; $tls::sizeof__cygtls = 4288;
//; $tls::func = -12700; //; $tls::func = -12700;
//; $tls::pfunc = 0; //; $tls::pfunc = 0;
//; $tls::saved_errno = -12696; //; $tls::saved_errno = -12696;
@ -37,26 +37,26 @@
//; $tls::p__dontuse = 412; //; $tls::p__dontuse = 412;
//; $tls::locals = -11200; //; $tls::locals = -11200;
//; $tls::plocals = 1500; //; $tls::plocals = 1500;
//; $tls::_ctinfo = -9480; //; $tls::_ctinfo = -9496;
//; $tls::p_ctinfo = 3220; //; $tls::p_ctinfo = 3204;
//; $tls::andreas = -9476; //; $tls::andreas = -9492;
//; $tls::pandreas = 3224; //; $tls::pandreas = 3208;
//; $tls::wq = -9472; //; $tls::wq = -9488;
//; $tls::pwq = 3228; //; $tls::pwq = 3212;
//; $tls::sig = -9444; //; $tls::sig = -9460;
//; $tls::psig = 3256; //; $tls::psig = 3240;
//; $tls::incyg = -9440; //; $tls::incyg = -9456;
//; $tls::pincyg = 3260; //; $tls::pincyg = 3244;
//; $tls::spinning = -9436; //; $tls::spinning = -9452;
//; $tls::pspinning = 3264; //; $tls::pspinning = 3248;
//; $tls::stacklock = -9432; //; $tls::stacklock = -9448;
//; $tls::pstacklock = 3268; //; $tls::pstacklock = 3252;
//; $tls::stackptr = -9428; //; $tls::stackptr = -9444;
//; $tls::pstackptr = 3272; //; $tls::pstackptr = 3256;
//; $tls::stack = -9424; //; $tls::stack = -9440;
//; $tls::pstack = 3276; //; $tls::pstack = 3260;
//; $tls::initialized = -8400; //; $tls::initialized = -8416;
//; $tls::pinitialized = 4300; //; $tls::pinitialized = 4284;
//; __DATA__ //; __DATA__
#define tls_func (-12700) #define tls_func (-12700)
@ -95,23 +95,23 @@
#define tls_p__dontuse (412) #define tls_p__dontuse (412)
#define tls_locals (-11200) #define tls_locals (-11200)
#define tls_plocals (1500) #define tls_plocals (1500)
#define tls__ctinfo (-9480) #define tls__ctinfo (-9496)
#define tls_p_ctinfo (3220) #define tls_p_ctinfo (3204)
#define tls_andreas (-9476) #define tls_andreas (-9492)
#define tls_pandreas (3224) #define tls_pandreas (3208)
#define tls_wq (-9472) #define tls_wq (-9488)
#define tls_pwq (3228) #define tls_pwq (3212)
#define tls_sig (-9444) #define tls_sig (-9460)
#define tls_psig (3256) #define tls_psig (3240)
#define tls_incyg (-9440) #define tls_incyg (-9456)
#define tls_pincyg (3260) #define tls_pincyg (3244)
#define tls_spinning (-9436) #define tls_spinning (-9452)
#define tls_pspinning (3264) #define tls_pspinning (3248)
#define tls_stacklock (-9432) #define tls_stacklock (-9448)
#define tls_pstacklock (3268) #define tls_pstacklock (3252)
#define tls_stackptr (-9428) #define tls_stackptr (-9444)
#define tls_pstackptr (3272) #define tls_pstackptr (3256)
#define tls_stack (-9424) #define tls_stack (-9440)
#define tls_pstack (3276) #define tls_pstack (3260)
#define tls_initialized (-8400) #define tls_initialized (-8416)
#define tls_pinitialized (4300) #define tls_pinitialized (4284)