* times.cc (hires::prime): Restore thread priority on failure condition.

* uinfo.cc (uinfo_init): Use more robust method for determining if process was
invoked from a non-cygwin process.
* sync.h (muto::init): Eliminate "inheritance" parameter.
(new_muto): Reflect removal of parameter.
* sync.cc (muto::init): Ditto.
* cygheap.cc (cygheap_init): Ditto.
* debug.cc (threadname_init): Ditto.
* exceptions.cc (events_init): Ditto.
* malloc.cc (malloc_init): Ditto.
* path.cc (cwdstuff::init): Ditto.
* sigproc.cc (sigproc_init): Ditto.
* grp.cc (group_lock): Use different method for locking with static member.
(read_etc_group): REALLY ensure that read lock mutex is released.
* passwd.cc (passwd_lock): Use different method for locking with static member.
(read_etc_passwd): REALLY ensure that read lock mutex is released.
* shared.cc (sec_user): Correct reversed inheritance test.
This commit is contained in:
Christopher Faylor 2002-02-17 04:59:55 +00:00
parent 9490dffa7b
commit 2bd22312df
14 changed files with 67 additions and 33 deletions

View File

@ -1,3 +1,28 @@
2002-02-16 Christopher Faylor <cgf@redhat.com>
* times.cc (hires::prime): Restore thread priority on failure
condition.
* uinfo.cc (uinfo_init): Use more robust method for determining if
process was invoked from a non-cygwin process.
* sync.h (muto::init): Eliminate "inheritance" parameter.
(new_muto): Reflect removal of parameter.
* sync.cc (muto::init): Ditto.
* cygheap.cc (cygheap_init): Ditto.
* debug.cc (threadname_init): Ditto.
* exceptions.cc (events_init): Ditto.
* malloc.cc (malloc_init): Ditto.
* path.cc (cwdstuff::init): Ditto.
* sigproc.cc (sigproc_init): Ditto.
* grp.cc (group_lock): Use different method for locking with static member.
(read_etc_group): REALLY ensure that read lock mutex is released.
* passwd.cc (passwd_lock): Use different method for locking with static member.
(read_etc_passwd): REALLY ensure that read lock mutex is released.
* shared.cc (sec_user): Correct reversed inheritance test.
2002-02-15 Christopher Faylor <cgf@redhat.com> 2002-02-15 Christopher Faylor <cgf@redhat.com>
* hires.h (hires::usecs): Rename from utime. Accept an argument. * hires.h (hires::usecs): Rename from utime. Accept an argument.

View File

@ -197,7 +197,7 @@ _csbrk (int sbs)
extern "C" void __stdcall extern "C" void __stdcall
cygheap_init () cygheap_init ()
{ {
cygheap_protect = new_muto (FALSE, "cygheap_protect"); cygheap_protect = new_muto ("cygheap_protect");
_csbrk (0); _csbrk (0);
if (!cygheap->fdtab) if (!cygheap->fdtab)
cygheap->fdtab.init (); cygheap->fdtab.init ();

View File

@ -37,7 +37,7 @@ static NO_COPY thread_info threads[32] = {{0, NULL}}; // increase as necessary
void void
threadname_init () threadname_init ()
{ {
threadname_lock = new_muto (FALSE, "threadname_lock"); threadname_lock = new_muto ("threadname_lock");
} }
void __stdcall void __stdcall
@ -195,7 +195,7 @@ static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL
void void
debug_init () debug_init ()
{ {
debug_lock = new_muto (FALSE, "debug_lock"); debug_lock = new_muto ("debug_lock");
} }
/* Find a registered handle in the linked list of handles. */ /* Find a registered handle in the linked list of handles. */

View File

@ -1112,7 +1112,7 @@ events_init (void)
api_fatal ("can't create title mutex, %E"); api_fatal ("can't create title mutex, %E");
ProtectHandle (title_mutex); ProtectHandle (title_mutex);
mask_sync = new_muto (FALSE, "mask_sync"); mask_sync = new_muto ("mask_sync");
windows_system_directory[0] = '\0'; windows_system_directory[0] = '\0';
(void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2); (void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2);
char *end = strchr (windows_system_directory, '\0'); char *end = strchr (windows_system_directory, '\0');

View File

@ -31,7 +31,7 @@ details. */
/* Read /etc/group only once for better performance. This is done /* Read /etc/group only once for better performance. This is done
on the first call that needs information from it. */ on the first call that needs information from it. */
static NO_COPY const char *etc_group = "/etc/group"; static const char *etc_group NO_COPY = "/etc/group";
static struct __group16 *group_buf; /* group contents in memory */ static struct __group16 *group_buf; /* group contents in memory */
static int curr_lines; static int curr_lines;
static int max_lines; static int max_lines;
@ -119,17 +119,23 @@ add_grp_line (const char *line)
class group_lock class group_lock
{ {
pthread_mutex_t mutex; bool armed;
static NO_COPY pthread_mutex_t mutex;
public: public:
group_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} group_lock (bool doit)
void arm () {pthread_mutex_lock (&mutex); } {
if (armed = doit)
pthread_mutex_lock (&mutex);
}
~group_lock () ~group_lock ()
{ {
if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) if (armed)
pthread_mutex_unlock (&mutex); pthread_mutex_unlock (&mutex);
} }
}; };
pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
/* Cygwin internal */ /* Cygwin internal */
/* Read in /etc/group and save contents in the group cache */ /* Read in /etc/group and save contents in the group cache */
/* This sets group_in_memory_p to 1 so functions in this file can /* This sets group_in_memory_p to 1 so functions in this file can
@ -145,9 +151,7 @@ read_etc_group ()
strncpy (group_name, "Administrators", sizeof (group_name)); strncpy (group_name, "Administrators", sizeof (group_name));
static NO_COPY group_lock here = group_lock(); group_lock here (cygwin_finished_initializing);
if (cygwin_finished_initializing)
here.arm ();
/* if we got blocked by the mutex, then etc_group may have been processed */ /* if we got blocked by the mutex, then etc_group may have been processed */
if (group_state != uninitialized) if (group_state != uninitialized)

View File

@ -216,7 +216,7 @@ static NO_COPY muto *mprotect = NULL;
void void
malloc_init () malloc_init ()
{ {
mprotect = new_muto (FALSE, "mprotect"); mprotect = new_muto ("mprotect");
/* Check if mallock is provided by application. If so, redirect all /* Check if mallock is provided by application. If so, redirect all
calls to export_malloc/free/realloc to application provided. This may calls to export_malloc/free/realloc to application provided. This may
happen if some other dll calls cygwin's malloc, but main code provides happen if some other dll calls cygwin's malloc, but main code provides

View File

@ -111,17 +111,24 @@ add_pwd_line (char *line)
class passwd_lock class passwd_lock
{ {
pthread_mutex_t mutex; bool armed;
static NO_COPY pthread_mutex_t mutex;
public: public:
passwd_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {} passwd_lock (bool doit)
void arm () {pthread_mutex_lock (&mutex); } {
if (doit)
pthread_mutex_lock (&mutex);
armed = doit;
}
~passwd_lock () ~passwd_lock ()
{ {
if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) if (armed)
pthread_mutex_unlock (&mutex); pthread_mutex_unlock (&mutex);
} }
}; };
pthread_mutex_t NO_COPY passwd_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
/* Read in /etc/passwd and save contents in the password cache. /* Read in /etc/passwd and save contents in the password cache.
This sets passwd_state to loaded or emulated so functions in this file can This sets passwd_state to loaded or emulated so functions in this file can
tell that /etc/passwd has been read in or will be emulated. */ tell that /etc/passwd has been read in or will be emulated. */
@ -133,10 +140,7 @@ read_etc_passwd ()
* for non-shared mutexs in the future. Also, this function will at most be called * for non-shared mutexs in the future. Also, this function will at most be called
* once from each thread, after that the passwd_state test will succeed * once from each thread, after that the passwd_state test will succeed
*/ */
static NO_COPY passwd_lock here; passwd_lock here (cygwin_finished_initializing);
if (cygwin_finished_initializing)
here.arm ();
/* if we got blocked by the mutex, then etc_passwd may have been processed */ /* if we got blocked by the mutex, then etc_passwd may have been processed */
if (passwd_state != uninitialized) if (passwd_state != uninitialized)

View File

@ -3546,7 +3546,7 @@ cwdstuff::get_hash ()
void void
cwdstuff::init () cwdstuff::init ()
{ {
lock = new_muto (false, "cwd"); lock = new_muto ("cwd");
} }
/* Get initial cwd. Should only be called once in a /* Get initial cwd. Should only be called once in a

View File

@ -240,7 +240,7 @@ PSECURITY_ATTRIBUTES __stdcall
sec_user (PVOID sa_buf, PSID sid2, BOOL inherit) sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
{ {
if (!sa_buf) if (!sa_buf)
return inherit ? &sec_none_nih : &sec_none; return inherit ? &sec_none : &sec_none_nih;
PSECURITY_ATTRIBUTES psa = (PSECURITY_ATTRIBUTES) sa_buf; PSECURITY_ATTRIBUTES psa = (PSECURITY_ATTRIBUTES) sa_buf;
PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR) PSECURITY_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR)
@ -252,7 +252,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
if (cygheap->user.sid ()) if (cygheap->user.sid ())
sid = cygheap->user.sid (); sid = cygheap->user.sid ();
else if (!lookup_name (getlogin (), cygheap->user.logsrv (), sid)) else if (!lookup_name (getlogin (), cygheap->user.logsrv (), sid))
return inherit ? &sec_none_nih : &sec_none; return inherit ? &sec_none : &sec_none_nih;
size_t acl_len = sizeof (ACL) size_t acl_len = sizeof (ACL)
+ 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD)) + 4 * (sizeof (ACCESS_ALLOWED_ACE) - sizeof (DWORD))

View File

@ -587,7 +587,7 @@ sigproc_init ()
/* sync_proc_subproc is used by proc_subproc. It serialises /* sync_proc_subproc is used by proc_subproc. It serialises
* access to the children and zombie arrays. * access to the children and zombie arrays.
*/ */
sync_proc_subproc = new_muto (FALSE, "sync_proc_subproc"); sync_proc_subproc = new_muto ("sync_proc_subproc");
/* Initialize waitq structure for main thread. A waitq structure is /* Initialize waitq structure for main thread. A waitq structure is
* allocated for each thread that executes a wait to allow multiple threads * allocated for each thread that executes a wait to allow multiple threads

View File

@ -29,11 +29,11 @@ muto NO_COPY muto_start;
/* Constructor */ /* Constructor */
muto * muto *
muto::init (int inh, const char *s) muto::init (const char *s)
{ {
waiters = -1; waiters = -1;
/* Create event which is used in the fallback case when blocking is necessary */ /* Create event which is used in the fallback case when blocking is necessary */
if (!(bruteforce = CreateEvent (inh ? &sec_all_nih : &sec_none_nih, FALSE, FALSE, NULL))) if (!(bruteforce = CreateEvent (&sec_none_nih, FALSE, FALSE, NULL)))
{ {
DWORD oerr = GetLastError (); DWORD oerr = GetLastError ();
SetLastError (oerr); SetLastError (oerr);

View File

@ -24,7 +24,7 @@ public:
const char *name; const char *name;
/* The real constructor. */ /* The real constructor. */
muto *init(int inh, const char *name) __attribute__ ((regparm (3))); muto *init(const char *name) __attribute__ ((regparm (3)));
#if 0 /* FIXME: See comment in sync.cc */ #if 0 /* FIXME: See comment in sync.cc */
~muto () ~muto ()
@ -42,8 +42,8 @@ public:
extern muto muto_start; extern muto muto_start;
/* Use a statically allocated buffer as the storage for a muto */ /* Use a statically allocated buffer as the storage for a muto */
#define new_muto(__inh, __name) \ #define new_muto(__name) \
({ \ ({ \
static muto __mbuf NO_COPY; \ static muto __mbuf __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \
__mbuf.init (__inh, __name); \ __mbuf.init (__name); \
}) })

View File

@ -573,6 +573,7 @@ hires::prime ()
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL); SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
if (!QueryPerformanceCounter (&primed_pc)) if (!QueryPerformanceCounter (&primed_pc))
{ {
SetThreadPriority (GetCurrentThread (), priority);
inited = -1; inited = -1;
return; return;
} }

View File

@ -257,7 +257,7 @@ uinfo_init ()
myself->uid = p->pw_uid; myself->uid = p->pw_uid;
/* Set primary group only if process has been started from a /* Set primary group only if process has been started from a
non cygwin process. */ non cygwin process. */
if (myself->ppid == 1) if (!myself->ppid_handle)
myself->gid = p->pw_gid; myself->gid = p->pw_gid;
} }
else else
@ -277,7 +277,7 @@ getlogin (void)
#ifdef _MT_SAFE #ifdef _MT_SAFE
char *this_username=_reent_winsup ()->_username; char *this_username=_reent_winsup ()->_username;
#else #else
static NO_COPY char this_username[UNLEN + 1]; static char this_username[UNLEN + 1] NO_COPY;
#endif #endif
return strcpy (this_username, cygheap->user.name ()); return strcpy (this_username, cygheap->user.name ());