4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-01-18 20:39:33 +08:00

* 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.
This commit is contained in:
Christopher Faylor 2003-01-24 03:53:46 +00:00
parent 09a8842674
commit ac4133746e
8 changed files with 134 additions and 141 deletions

View File

@ -1,3 +1,26 @@
2003-01-23 Christopher Faylor <cgf@redhat.com>
* pwdrp.h (pwdgrp::refresh): Lock entire test prior to reading.
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.
* 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.
2003-01-22 Thomas Pfaff <tpfaff@gmx.net> 2003-01-22 Thomas Pfaff <tpfaff@gmx.net>
* include/pthread.h (PTHREAD_MUTEX_RECURSIVE): Revert changes from * include/pthread.h (PTHREAD_MUTEX_RECURSIVE): Revert changes from
@ -17,25 +40,6 @@
(usleep): Remove old functionality. Call nanosleep(). (usleep): Remove old functionality. Call nanosleep().
* include/cygwin/version.h: Bump API minor number. * include/cygwin/version.h: Bump API minor number.
2003-01-21 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.
* 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.
2003-01-21 Christopher Faylor <cgf@redhat.com> 2003-01-21 Christopher Faylor <cgf@redhat.com>
* grp.cc: Call gr.refresh() rather than doing isunitialized tests * grp.cc: Call gr.refresh() rather than doing isunitialized tests

View File

@ -1,5 +1,5 @@
# Makefile.in for Cygwin. # 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. # This file is part of Cygwin.
# #

View File

@ -254,4 +254,3 @@ AC_SUBST(DEF_DLL_ENTRY)
AC_SUBST(ALLOCA) AC_SUBST(ALLOCA)
AC_SUBST(CONFIG_DIR) AC_SUBST(CONFIG_DIR)
AC_OUTPUT(Makefile cygwin.def:cygwin.din) AC_OUTPUT(Makefile cygwin.def:cygwin.din)

View File

@ -34,51 +34,41 @@ static pwdgrp gr (group_buf);
static char * NO_COPY null_ptr; static char * NO_COPY null_ptr;
bool bool
pwdgrp::parse_group (char *line) pwdgrp::parse_group ()
{ {
char *dp = strchr (line, ':'); char *dp;
if (!dp)
return false;
# define grp (*group_buf)[curr_lines] # define grp (*group_buf)[curr_lines]
*dp++ = '\0'; memset (&grp, 0, sizeof (grp));
grp.gr_name = line; grp.gr_name = next_str ();
if (!grp.gr_name)
return false;
grp.gr_passwd = dp; grp.gr_passwd = next_str ();
dp = strchr (grp.gr_passwd, ':'); int n = next_int ();
if (dp) if (n >= 0)
{ {
*dp++ = '\0'; grp.gr_gid = n;
grp.gr_gid = strtoul (line = dp, &dp, 10); dp = next_str ();
if (dp != line && *dp == ':') if (!dp)
{
grp.gr_mem = &null_ptr;
if (*++dp)
{ {
static char empty[] = "";
dp = empty;
}
int i = 0; int i = 0;
char *cp; for (char *cp = dp; (cp = strchr (cp, ',')) != NULL; cp++)
i++;
for (cp = dp; (cp = strchr (cp, ',')) != NULL; ++cp)
++i;
char **namearray = (char **) calloc (i + 2, sizeof (char *)); char **namearray = (char **) calloc (i + 2, sizeof (char *));
if (namearray) if (namearray)
{ {
i = 0; for (i = 0; (dp = next_str (',')); i++)
for (cp = dp; (cp = strchr (dp, ',')) != NULL; dp = cp + 1) namearray[i] = dp;
{
*cp = '\0';
namearray[i++] = dp;
}
namearray[i++] = dp;
namearray[i] = NULL; namearray[i] = NULL;
grp.gr_mem = namearray; grp.gr_mem = namearray;
} }
}
curr_lines++; curr_lines++;
return true; return true;
} }
}
return false; return false;
# undef grp # undef grp
} }

View File

@ -33,52 +33,31 @@ static pwdgrp pr (passwd_buf);
/* Position in the passwd cache */ /* Position in the passwd cache */
#define pw_pos _reent_winsup ()->_pw_pos #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. */ /* Parse /etc/passwd line into passwd structure. */
bool bool
pwdgrp::parse_passwd (char *buf) pwdgrp::parse_passwd ()
{ {
int n;
# define res (*passwd_buf)[curr_lines] # define res (*passwd_buf)[curr_lines]
/* Allocate enough room for the passwd struct and all the strings /* Allocate enough room for the passwd struct and all the strings
in it in one go */ in it in one go */
res.pw_name = grab_string (&buf); memset (&res, 0, sizeof (res));
res.pw_passwd = grab_string (&buf); res.pw_name = next_str ();
res.pw_uid = grab_int (&buf); res.pw_passwd = next_str ();
res.pw_gid = grab_int (&buf);
if (!*buf) n = next_int ();
if (n < 0)
return false; return false;
res.pw_uid = n;
n = next_int ();
if (n < 0)
return false;
res.pw_gid = n;
res.pw_comment = 0; res.pw_comment = 0;
res.pw_gecos = grab_string (&buf); res.pw_gecos = next_str ();
res.pw_dir = grab_string (&buf); res.pw_dir = next_str ();
res.pw_shell = grab_string (&buf); res.pw_shell = next_str ();
curr_lines++; curr_lines++;
return true; return true;
# undef res # undef res

View File

@ -3813,7 +3813,8 @@ etc::dir_changed (int n)
{ {
path_conv pwd ("/etc"); path_conv pwd ("/etc");
changed_h = FindFirstChangeNotification (pwd, FALSE, changed_h = FindFirstChangeNotification (pwd, FALSE,
FILE_NOTIFY_CHANGE_LAST_WRITE); FILE_NOTIFY_CHANGE_LAST_WRITE
| FILE_NOTIFY_CHANGE_FILE_NAME);
#ifdef DEBUGGING #ifdef DEBUGGING
if (changed_h == INVALID_HANDLE_VALUE) if (changed_h == INVALID_HANDLE_VALUE)
system_printf ("Can't open /etc for checking, %E", (char *) pwd, system_printf ("Can't open /etc for checking, %E", (char *) pwd,

View File

@ -21,6 +21,7 @@ extern struct __group32 *internal_getgrnam (const char *, bool = FALSE);
extern struct __group32 *internal_getgrent (int); extern struct __group32 *internal_getgrent (int);
int internal_getgroups (int, __gid32_t *, cygsid * = NULL); int internal_getgroups (int, __gid32_t *, cygsid * = NULL);
#include "sync.h"
class pwdgrp class pwdgrp
{ {
unsigned pwdgrp_buf_elem_size; unsigned pwdgrp_buf_elem_size;
@ -31,51 +32,48 @@ class pwdgrp
void **pwdgrp_buf; void **pwdgrp_buf;
}; };
void (pwdgrp::*read) (); void (pwdgrp::*read) ();
bool (pwdgrp::*parse) (char *); bool (pwdgrp::*parse) ();
int etc_ix; int etc_ix;
path_conv pc; path_conv pc;
char *buf; char *buf, *lptr;
int max_lines; int max_lines;
bool initialized; 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: public:
int curr_lines; int curr_lines;
bool parse_passwd (char *); bool load (const char *);
bool parse_group (char *);
void read_passwd ();
void read_group ();
void add_line (char *);
void refresh (bool check = true) void refresh (bool check = true)
{ {
if (initialized && check && etc::file_changed (etc_ix)) if (!check && initialized)
initialized = false; return;
if (!initialized) pglock->acquire ();
{ if (!initialized || (check && etc::file_changed (etc_ix)))
EnterCriticalSection (&lock);
if (!initialized)
(this->*read) (); (this->*read) ();
LeaveCriticalSection (&lock); pglock->release ();
}
} }
bool load (const char *);
pwdgrp (passwd *&pbuf) : pwdgrp (passwd *&pbuf) :
pwdgrp_buf_elem_size (sizeof (*pbuf)), passwd_buf (&pbuf) pwdgrp_buf_elem_size (sizeof (*pbuf)), passwd_buf (&pbuf)
{ {
read = &pwdgrp::read_passwd; read = &pwdgrp::read_passwd;
parse = &pwdgrp::parse_passwd; parse = &pwdgrp::parse_passwd;
InitializeCriticalSection (&lock); new_muto (pglock);
} }
pwdgrp (__group32 *&gbuf) : pwdgrp (__group32 *&gbuf) :
pwdgrp_buf_elem_size (sizeof (*gbuf)), group_buf (&gbuf) pwdgrp_buf_elem_size (sizeof (*gbuf)), group_buf (&gbuf)
{ {
read = &pwdgrp::read_group; read = &pwdgrp::read_group;
parse = &pwdgrp::parse_group; parse = &pwdgrp::parse_group;
InitializeCriticalSection (&lock); new_muto (pglock);
} }
}; };

View File

@ -391,34 +391,58 @@ cygheap_user::env_name (const char *name, size_t namelen)
} }
char * char *
pwdgrp::gets (char*& eptr) pwdgrp::next_str (char c)
{ {
char *lptr; if (!lptr)
if (!eptr) return NULL;
char search[] = ":\n\0\0";
search[2] = c;
char *res = lptr;
char *p = strpbrk (lptr, search);
if (!p)
lptr = NULL; lptr = NULL;
else else
{
lptr = (*p == '\n') ? NULL : p + 1;
*p = '\0';
}
return res;
}
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 (eptr)
{ {
lptr = eptr; lptr = eptr;
eptr = strchr (lptr, '\n'); eptr = strchr (lptr, '\n');
if (eptr) if (eptr)
{ {
if (eptr > lptr && *(eptr - 1) == '\r') if (eptr > lptr && eptr[-1] == '\r')
*(eptr - 1) = 0; eptr[-1] = '\n';
*eptr++ = '\0'; eptr++;
} }
}
return lptr;
}
void
pwdgrp::add_line (char *line)
{
if (curr_lines >= max_lines) if (curr_lines >= max_lines)
{ {
max_lines += 10; max_lines += 10;
*pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size); *pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
} }
(void) (this->*parse) (line); (void) (this->*parse) ();
}
return eptr;
} }
bool bool
@ -459,11 +483,9 @@ pwdgrp::load (const char *posix_fname)
CloseHandle (fh); CloseHandle (fh);
buf[read_bytes] = '\0'; buf[read_bytes] = '\0';
char *eptr = buf; char *eptr = buf;
eptr = buf;
char *line;
curr_lines = 0; curr_lines = 0;
while ((line = gets (eptr)) != NULL) while ((eptr = add_line (eptr)))
add_line (line); continue;
debug_printf ("%s curr_lines %d", posix_fname, curr_lines); debug_printf ("%s curr_lines %d", posix_fname, curr_lines);
res = true; res = true;
} }