+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.
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 ();
void
threadname_init ()
{
- threadname_lock = new_muto (FALSE, "threadname_lock");
+ threadname_lock = new_muto ("threadname_lock");
}
void __stdcall
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. */
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');
/* 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;
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
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)
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
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. */
* 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)
void
cwdstuff::init ()
{
- lock = new_muto (false, "cwd");
+ lock = new_muto ("cwd");
}
/* Get initial cwd. Should only be called once in a
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)
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))
/* 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
/* 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);
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 ()
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); \
})
SetThreadPriority (GetCurrentThread (), THREAD_PRIORITY_TIME_CRITICAL);
if (!QueryPerformanceCounter (&primed_pc))
{
+ SetThreadPriority (GetCurrentThread (), priority);
inited = -1;
return;
}
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
#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 ());