* 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>
* hires.h (hires::usecs): Rename from utime. Accept an argument.

View File

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

View File

@ -37,7 +37,7 @@ static NO_COPY thread_info threads[32] = {{0, NULL}}; // increase as necessary
void
threadname_init ()
{
threadname_lock = new_muto (FALSE, "threadname_lock");
threadname_lock = new_muto ("threadname_lock");
}
void __stdcall
@ -195,7 +195,7 @@ static bool __stdcall mark_closed (const char *, int, HANDLE, const char *, BOOL
void
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. */

View File

@ -1112,7 +1112,7 @@ events_init (void)
api_fatal ("can't create title mutex, %E");
ProtectHandle (title_mutex);
mask_sync = new_muto (FALSE, "mask_sync");
mask_sync = new_muto ("mask_sync");
windows_system_directory[0] = '\0';
(void) GetSystemDirectory (windows_system_directory, sizeof (windows_system_directory) - 2);
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
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 int curr_lines;
static int max_lines;
@ -119,17 +119,23 @@ add_grp_line (const char *line)
class group_lock
{
pthread_mutex_t mutex;
bool armed;
static NO_COPY pthread_mutex_t mutex;
public:
group_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {}
void arm () {pthread_mutex_lock (&mutex); }
group_lock (bool doit)
{
if (armed = doit)
pthread_mutex_lock (&mutex);
}
~group_lock ()
{
if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)
if (armed)
pthread_mutex_unlock (&mutex);
}
};
pthread_mutex_t NO_COPY group_lock::mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
/* Cygwin internal */
/* 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
@ -145,9 +151,7 @@ read_etc_group ()
strncpy (group_name, "Administrators", sizeof (group_name));
static NO_COPY group_lock here = group_lock();
if (cygwin_finished_initializing)
here.arm ();
group_lock here (cygwin_finished_initializing);
/* if we got blocked by the mutex, then etc_group may have been processed */
if (group_state != uninitialized)

View File

@ -216,7 +216,7 @@ static NO_COPY muto *mprotect = NULL;
void
malloc_init ()
{
mprotect = new_muto (FALSE, "mprotect");
mprotect = new_muto ("mprotect");
/* Check if mallock is provided by application. If so, redirect all
calls to export_malloc/free/realloc to application provided. This may
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
{
pthread_mutex_t mutex;
bool armed;
static NO_COPY pthread_mutex_t mutex;
public:
passwd_lock (): mutex ((pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER) {}
void arm () {pthread_mutex_lock (&mutex); }
passwd_lock (bool doit)
{
if (doit)
pthread_mutex_lock (&mutex);
armed = doit;
}
~passwd_lock ()
{
if (mutex != (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER)
if (armed)
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.
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. */
@ -133,10 +140,7 @@ read_etc_passwd ()
* 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
*/
static NO_COPY passwd_lock here;
if (cygwin_finished_initializing)
here.arm ();
passwd_lock here (cygwin_finished_initializing);
/* if we got blocked by the mutex, then etc_passwd may have been processed */
if (passwd_state != uninitialized)

View File

@ -3546,7 +3546,7 @@ cwdstuff::get_hash ()
void
cwdstuff::init ()
{
lock = new_muto (false, "cwd");
lock = new_muto ("cwd");
}
/* 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)
{
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_DESCRIPTOR psd = (PSECURITY_DESCRIPTOR)
@ -252,7 +252,7 @@ sec_user (PVOID sa_buf, PSID sid2, BOOL inherit)
if (cygheap->user.sid ())
sid = cygheap->user.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)
+ 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
* 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
* allocated for each thread that executes a wait to allow multiple threads

View File

@ -29,11 +29,11 @@ muto NO_COPY muto_start;
/* Constructor */
muto *
muto::init (int inh, const char *s)
muto::init (const char *s)
{
waiters = -1;
/* 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 ();
SetLastError (oerr);

View File

@ -24,7 +24,7 @@ public:
const char *name;
/* 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 */
~muto ()
@ -42,8 +42,8 @@ public:
extern muto muto_start;
/* 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; \
__mbuf.init (__inh, __name); \
static muto __mbuf __attribute__((nocommon)) __attribute__((section(".data_cygwin_nocopy"))); \
__mbuf.init (__name); \
})

View File

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

View File

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