Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2003-01-24 06:53:46 +0300
committerChristopher Faylor <me@cgf.cx>2003-01-24 06:53:46 +0300
commitac4133746eeaad61b2bb2f71bd8861615b052427 (patch)
tree40d48ebf8a73cbd5ec8a206ab0a953033942d303
parent09a88426740b765a99759d29da0e2a5f98c7281b (diff)
* pwdrp.h (pwdgrp::refresh): Lock entire test prior to reading.
* grp.cc (pwdgrp::parse_group): Eliminate arg and use class member instead. Use next_str and next_int to parse arguments. * passwd.cc (pwdgrp::parse_passwd): Ditto. (grab_string): Eliminate. (grab_int): Ditto. * pwdgrp.h (pwdgrp::parse): Eliminate input arg. (pwdgrp::parse_passwd): Reflect above change. (pwdgrp::parse_group): Reflect above change. (pwdgrp::next_str): New function. (pwdgrp::next_int): Ditto. (pwdgrp::gets): Eliminate. * uinfo.cc (pwdgrp::next_str): New function. (pwdgrp::next_int): Ditto. (pwdgrp::add_line): Subsume gets. (pwdgrp::gets): Eliminate. (pwdgrp::load): Just call add_line to parse input buffer.
-rw-r--r--winsup/cygwin/ChangeLog40
-rw-r--r--winsup/cygwin/Makefile.in2
-rw-r--r--winsup/cygwin/configure.in1
-rw-r--r--winsup/cygwin/grp.cc64
-rw-r--r--winsup/cygwin/passwd.cc55
-rw-r--r--winsup/cygwin/path.cc3
-rw-r--r--winsup/cygwin/pwdgrp.h42
-rw-r--r--winsup/cygwin/uinfo.cc66
8 files changed, 133 insertions, 140 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4e8f06232..db2537c7f 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,23 +1,8 @@
-2003-01-22 Thomas Pfaff <tpfaff@gmx.net>
-
- * include/pthread.h (PTHREAD_MUTEX_RECURSIVE): Revert changes from
- 2003-01-09 mutex patch.
- (PTHREAD_MUTEX_ERRORCHECK): Ditto.
+2003-01-23 Christopher Faylor <cgf@redhat.com>
-2003-01-22 Corinna Vinschen <corinna@vinschen.de>
+ * pwdrp.h (pwdgrp::refresh): Lock entire test prior to reading.
- * cygrun.c: Move from here to ../testsuite.
- * Makefile.in: Remove cygrun.exe dependencies.
-
-2003-01-21 Jason Tishler <jason@tishler.net>
-
- * cygwin.din: Export nanosleep().
- * signal.cc (nanosleep): New function.
- (sleep): Move old functionality to nanosleep(). Call nanosleep().
- (usleep): Remove old functionality. Call nanosleep().
- * include/cygwin/version.h: Bump API minor number.
-
-2003-01-21 Christopher Faylor <cgf@redhat.com>
+2003-01-23 Christopher Faylor <cgf@redhat.com>
* grp.cc (pwdgrp::parse_group): Eliminate arg and use class member
instead. Use next_str and next_int to parse arguments.
@@ -36,6 +21,25 @@
(pwdgrp::gets): Eliminate.
(pwdgrp::load): Just call add_line to parse input buffer.
+2003-01-22 Thomas Pfaff <tpfaff@gmx.net>
+
+ * include/pthread.h (PTHREAD_MUTEX_RECURSIVE): Revert changes from
+ 2003-01-09 mutex patch.
+ (PTHREAD_MUTEX_ERRORCHECK): Ditto.
+
+2003-01-22 Corinna Vinschen <corinna@vinschen.de>
+
+ * cygrun.c: Move from here to ../testsuite.
+ * Makefile.in: Remove cygrun.exe dependencies.
+
+2003-01-21 Jason Tishler <jason@tishler.net>
+
+ * cygwin.din: Export nanosleep().
+ * signal.cc (nanosleep): New function.
+ (sleep): Move old functionality to nanosleep(). Call nanosleep().
+ (usleep): Remove old functionality. Call nanosleep().
+ * include/cygwin/version.h: Bump API minor number.
+
2003-01-21 Christopher Faylor <cgf@redhat.com>
* grp.cc: Call gr.refresh() rather than doing isunitialized tests
diff --git a/winsup/cygwin/Makefile.in b/winsup/cygwin/Makefile.in
index 854dadd29..31203217f 100644
--- a/winsup/cygwin/Makefile.in
+++ b/winsup/cygwin/Makefile.in
@@ -1,5 +1,5 @@
# Makefile.in for Cygwin.
-# Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+# Copyright 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 Red Hat, Inc.
#
# This file is part of Cygwin.
#
diff --git a/winsup/cygwin/configure.in b/winsup/cygwin/configure.in
index 3934992a7..84e86b643 100644
--- a/winsup/cygwin/configure.in
+++ b/winsup/cygwin/configure.in
@@ -254,4 +254,3 @@ AC_SUBST(DEF_DLL_ENTRY)
AC_SUBST(ALLOCA)
AC_SUBST(CONFIG_DIR)
AC_OUTPUT(Makefile cygwin.def:cygwin.din)
-
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc
index 529fdbe26..9cce888a3 100644
--- a/winsup/cygwin/grp.cc
+++ b/winsup/cygwin/grp.cc
@@ -34,50 +34,40 @@ static pwdgrp gr (group_buf);
static char * NO_COPY null_ptr;
bool
-pwdgrp::parse_group (char *line)
+pwdgrp::parse_group ()
{
- char *dp = strchr (line, ':');
-
- if (!dp)
- return false;
+ char *dp;
# define grp (*group_buf)[curr_lines]
- *dp++ = '\0';
- grp.gr_name = line;
+ memset (&grp, 0, sizeof (grp));
+ grp.gr_name = next_str ();
+ if (!grp.gr_name)
+ return false;
- grp.gr_passwd = dp;
- dp = strchr (grp.gr_passwd, ':');
- if (dp)
+ grp.gr_passwd = next_str ();
+ int n = next_int ();
+ if (n >= 0)
{
- *dp++ = '\0';
- grp.gr_gid = strtoul (line = dp, &dp, 10);
- if (dp != line && *dp == ':')
+ grp.gr_gid = n;
+ dp = next_str ();
+ if (!dp)
{
- grp.gr_mem = &null_ptr;
- if (*++dp)
- {
- int i = 0;
- char *cp;
-
- for (cp = dp; (cp = strchr (cp, ',')) != NULL; ++cp)
- ++i;
- char **namearray = (char **) calloc (i + 2, sizeof (char *));
- if (namearray)
- {
- i = 0;
- for (cp = dp; (cp = strchr (dp, ',')) != NULL; dp = cp + 1)
- {
- *cp = '\0';
- namearray[i++] = dp;
- }
- namearray[i++] = dp;
- namearray[i] = NULL;
- grp.gr_mem = namearray;
- }
- }
- curr_lines++;
- return true;
+ static char empty[] = "";
+ dp = empty;
+ }
+ int i = 0;
+ for (char *cp = dp; (cp = strchr (cp, ',')) != NULL; cp++)
+ i++;
+ char **namearray = (char **) calloc (i + 2, sizeof (char *));
+ if (namearray)
+ {
+ for (i = 0; (dp = next_str (',')); i++)
+ namearray[i] = dp;
+ namearray[i] = NULL;
+ grp.gr_mem = namearray;
}
+ curr_lines++;
+ return true;
}
return false;
# undef grp
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index 81ba9edab..0b85f95bf 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -33,52 +33,31 @@ static pwdgrp pr (passwd_buf);
/* Position in the passwd cache */
#define pw_pos _reent_winsup ()->_pw_pos
-/* Remove a : terminated string from the buffer, and increment the pointer */
-static char *
-grab_string (char **p)
-{
- char *src = *p;
- char *res = src;
-
- while (*src && *src != ':')
- src++;
-
- if (*src == ':')
- {
- *src = 0;
- src++;
- }
- *p = src;
- return res;
-}
-
-/* same, for ints */
-static unsigned int
-grab_int (char **p)
-{
- char *src = *p;
- unsigned int val = strtoul (src, p, 10);
- *p = (*p == src || **p != ':') ? almost_null : *p + 1;
- return val;
-}
-
/* Parse /etc/passwd line into passwd structure. */
bool
-pwdgrp::parse_passwd (char *buf)
+pwdgrp::parse_passwd ()
{
+ int n;
# define res (*passwd_buf)[curr_lines]
/* Allocate enough room for the passwd struct and all the strings
in it in one go */
- res.pw_name = grab_string (&buf);
- res.pw_passwd = grab_string (&buf);
- res.pw_uid = grab_int (&buf);
- res.pw_gid = grab_int (&buf);
- if (!*buf)
+ memset (&res, 0, sizeof (res));
+ res.pw_name = next_str ();
+ res.pw_passwd = next_str ();
+
+ n = next_int ();
+ if (n < 0)
+ return false;
+ res.pw_uid = n;
+
+ n = next_int ();
+ if (n < 0)
return false;
+ res.pw_gid = n;
res.pw_comment = 0;
- res.pw_gecos = grab_string (&buf);
- res.pw_dir = grab_string (&buf);
- res.pw_shell = grab_string (&buf);
+ res.pw_gecos = next_str ();
+ res.pw_dir = next_str ();
+ res.pw_shell = next_str ();
curr_lines++;
return true;
# undef res
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index 9a2418fe3..1d754be33 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -3813,7 +3813,8 @@ etc::dir_changed (int n)
{
path_conv pwd ("/etc");
changed_h = FindFirstChangeNotification (pwd, FALSE,
- FILE_NOTIFY_CHANGE_LAST_WRITE);
+ FILE_NOTIFY_CHANGE_LAST_WRITE
+ | FILE_NOTIFY_CHANGE_FILE_NAME);
#ifdef DEBUGGING
if (changed_h == INVALID_HANDLE_VALUE)
system_printf ("Can't open /etc for checking, %E", (char *) pwd,
diff --git a/winsup/cygwin/pwdgrp.h b/winsup/cygwin/pwdgrp.h
index eb0a974d1..ede380866 100644
--- a/winsup/cygwin/pwdgrp.h
+++ b/winsup/cygwin/pwdgrp.h
@@ -21,6 +21,7 @@ extern struct __group32 *internal_getgrnam (const char *, bool = FALSE);
extern struct __group32 *internal_getgrent (int);
int internal_getgroups (int, __gid32_t *, cygsid * = NULL);
+#include "sync.h"
class pwdgrp
{
unsigned pwdgrp_buf_elem_size;
@@ -31,51 +32,48 @@ class pwdgrp
void **pwdgrp_buf;
};
void (pwdgrp::*read) ();
- bool (pwdgrp::*parse) (char *);
+ bool (pwdgrp::*parse) ();
int etc_ix;
path_conv pc;
- char *buf;
+ char *buf, *lptr;
int max_lines;
bool initialized;
- CRITICAL_SECTION lock;
+ muto *pglock;
- char *gets (char*&);
+ bool parse_passwd ();
+ bool parse_group ();
+ void read_passwd ();
+ void read_group ();
+ char *add_line (char *);
+ char *pwdgrp::next_str (char = 0);
+ int pwdgrp::next_int (char = 0);
public:
int curr_lines;
- bool parse_passwd (char *);
- bool parse_group (char *);
- void read_passwd ();
- void read_group ();
-
- void add_line (char *);
+ bool load (const char *);
void refresh (bool check = true)
{
- if (initialized && check && etc::file_changed (etc_ix))
- initialized = false;
- if (!initialized)
- {
- EnterCriticalSection (&lock);
- if (!initialized)
- (this->*read) ();
- LeaveCriticalSection (&lock);
- }
+ if (!check && initialized)
+ return;
+ pglock->acquire ();
+ if (!initialized || (check && etc::file_changed (etc_ix)))
+ (this->*read) ();
+ pglock->release ();
}
- bool load (const char *);
pwdgrp (passwd *&pbuf) :
pwdgrp_buf_elem_size (sizeof (*pbuf)), passwd_buf (&pbuf)
{
read = &pwdgrp::read_passwd;
parse = &pwdgrp::parse_passwd;
- InitializeCriticalSection (&lock);
+ new_muto (pglock);
}
pwdgrp (__group32 *&gbuf) :
pwdgrp_buf_elem_size (sizeof (*gbuf)), group_buf (&gbuf)
{
read = &pwdgrp::read_group;
parse = &pwdgrp::parse_group;
- InitializeCriticalSection (&lock);
+ new_muto (pglock);
}
};
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 0c154ea69..b52cc0989 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -391,34 +391,58 @@ cygheap_user::env_name (const char *name, size_t namelen)
}
char *
-pwdgrp::gets (char*& eptr)
+pwdgrp::next_str (char c)
{
- char *lptr;
- if (!eptr)
+ if (!lptr)
+ return NULL;
+ char search[] = ":\n\0\0";
+ search[2] = c;
+ char *res = lptr;
+ char *p = strpbrk (lptr, search);
+ if (!p)
lptr = NULL;
else
{
- lptr = eptr;
- eptr = strchr (lptr, '\n');
- if (eptr)
- {
- if (eptr > lptr && *(eptr - 1) == '\r')
- *(eptr - 1) = 0;
- *eptr++ = '\0';
- }
+ lptr = (*p == '\n') ? NULL : p + 1;
+ *p = '\0';
}
- return lptr;
+ return res;
}
-void
-pwdgrp::add_line (char *line)
+int
+pwdgrp::next_int (char c)
+{
+ char *p = next_str (c);
+ if (!p)
+ return -1;
+ char *cp;
+ unsigned n = strtoul (p, &cp, 10);
+ if (p == cp)
+ return -1;
+ return n;
+}
+
+char *
+pwdgrp::add_line (char *eptr)
{
- if (curr_lines >= max_lines)
+ if (eptr)
{
- max_lines += 10;
- *pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
+ lptr = eptr;
+ eptr = strchr (lptr, '\n');
+ if (eptr)
+ {
+ if (eptr > lptr && eptr[-1] == '\r')
+ eptr[-1] = '\n';
+ eptr++;
+ }
+ if (curr_lines >= max_lines)
+ {
+ max_lines += 10;
+ *pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
+ }
+ (void) (this->*parse) ();
}
- (void) (this->*parse) (line);
+ return eptr;
}
bool
@@ -459,11 +483,9 @@ pwdgrp::load (const char *posix_fname)
CloseHandle (fh);
buf[read_bytes] = '\0';
char *eptr = buf;
- eptr = buf;
- char *line;
curr_lines = 0;
- while ((line = gets (eptr)) != NULL)
- add_line (line);
+ while ((eptr = add_line (eptr)))
+ continue;
debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
res = true;
}