* 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>
* include/pthread.h (PTHREAD_MUTEX_RECURSIVE): Revert changes from
@ -17,25 +40,6 @@
(usleep): Remove old functionality. Call nanosleep().
* 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>
* grp.cc: Call gr.refresh() rather than doing isunitialized tests

View File

@ -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.
#

View File

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

View File

@ -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

View File

@ -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

View File

@ -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,

View File

@ -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);
}
};

View File

@ -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 = (*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;
eptr = strchr (lptr, '\n');
if (eptr)
{
if (eptr > lptr && *(eptr - 1) == '\r')
*(eptr - 1) = 0;
*eptr++ = '\0';
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) ();
}
return lptr;
}
void
pwdgrp::add_line (char *line)
{
if (curr_lines >= max_lines)
{
max_lines += 10;
*pwdgrp_buf = realloc (*pwdgrp_buf, max_lines * pwdgrp_buf_elem_size);
}
(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;
}