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-21 09:58:11 +0300
committerChristopher Faylor <me@cgf.cx>2003-01-21 09:58:11 +0300
commit57394495e21e9ffe7da9251b26e9cac14d59f708 (patch)
treeebdce6564a0ae6803550dccd5dc555f1e2546b6a /winsup/cygwin/grp.cc
parent984864e9ce2d7bf3f6a6148f2fe4180da8dc5dc9 (diff)
* grp.cc: Call gr.refresh() rather than doing isunitialized tests throughout.
(gr): Use constructor (sigh). (pwdgrp::parse_group): Rename from parse_grp. (pwdgrp::read_group): Rename from read_etc_group. Just call gr.load with a single argument. * passwd.cc: Call pr.refresh() rather than doing isunitialized tests throughout. (pr): Use constructor (sigh). (pwdgrp::parse_passwd): Rename from "parse_pwd". (pwdgrp::read_passwd): Rename from read_etc_passwd. Just call pr.load with a single argument. * pwdgrp.h (pwdgrp_state): Eliminate. (pwdgrp): Reflect above renamings. (pwdgrp::etc_ix): Rename from pwd_ix. (pwdgrp::read): New element. (pwdgrp::lock): New element. (pwdgrp::refresh): New function. (pwdgrp::load): Eliminate variations which take buffer arguments. (pwdgrp::pwdgrp): New constructors. Initialize mutex here. * uinfo.cc (pwdgrp::load): Accommodate pwd_ix -> etc_ix renaming. (pwdgrp::load): Set initialized state to true rather than setting state to loaded.
Diffstat (limited to 'winsup/cygwin/grp.cc')
-rw-r--r--winsup/cygwin/grp.cc102
1 files changed, 36 insertions, 66 deletions
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc
index dc1330429..529fdbe26 100644
--- a/winsup/cygwin/grp.cc
+++ b/winsup/cygwin/grp.cc
@@ -29,19 +29,19 @@ details. */
/* Position in the group cache */
#define grp_pos _reent_winsup ()->_grp_pos
-static pwdgrp gr;
static __group32 *group_buf;
+static pwdgrp gr (group_buf);
static char * NO_COPY null_ptr;
bool
-pwdgrp::parse_grp (char *line)
+pwdgrp::parse_group (char *line)
{
char *dp = strchr (line, ':');
if (!dp)
return false;
-# define grp (* group_buf)[curr_lines]
+# define grp (*group_buf)[curr_lines]
*dp++ = '\0';
grp.gr_name = line;
@@ -83,68 +83,43 @@ pwdgrp::parse_grp (char *line)
# undef grp
}
-class group_lock
-{
- bool armed;
- static NO_COPY pthread_mutex_t mutex;
-public:
- group_lock (bool doit)
- {
- if (armed = doit)
- pthread_mutex_lock (&mutex);
- }
- ~group_lock ()
- {
- 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
tell that /etc/group has been read in */
-static void
-read_etc_group ()
+void
+pwdgrp::read_group ()
{
- group_lock here (cygwin_finished_initializing);
+ for (int i = 0; i < gr.curr_lines; i++)
+ if ((*group_buf)[i].gr_mem != &null_ptr)
+ free ((*group_buf)[i].gr_mem);
- /* if we got blocked by the mutex, then etc_group may have been processed */
- if (gr.isinitializing ())
+ if (!gr.load ("/etc/group"))
+ debug_printf ("gr.load failed");
+
+ /* Complete /etc/group in memory if needed */
+ if (!internal_getgrgid (myself->gid))
{
- for (int i = 0; i < gr.curr_lines; i++)
- if ((group_buf + i)->gr_mem != &null_ptr)
- free ((group_buf + i)->gr_mem);
-
- if (!gr.load ("/etc/group", group_buf))
- debug_printf ("gr.load failed");
-
- /* Complete /etc/group in memory if needed */
- if (!internal_getgrgid (myself->gid))
- {
- static char linebuf [200];
- char group_name [UNLEN + 1] = "mkgroup";
- char strbuf[128] = "";
-
- if (wincap.has_security ())
- {
- struct __group32 *gr;
-
- cygheap->user.groups.pgsid.string (strbuf);
- if ((gr = internal_getgrsid (cygheap->user.groups.pgsid)))
- strlcpy (group_name, gr->gr_name, sizeof (group_name));
- }
- snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:%s",
- group_name, strbuf, myself->gid, cygheap->user.name ());
- debug_printf ("Completing /etc/group: %s", linebuf);
- gr.add_line (linebuf);
- }
- static char NO_COPY pretty_ls[] = "????????::-1:";
+ static char linebuf [200];
+ char group_name [UNLEN + 1] = "mkgroup";
+ char strbuf[128] = "";
+
if (wincap.has_security ())
- gr.add_line (pretty_ls);
+ {
+ struct __group32 *gr;
+
+ cygheap->user.groups.pgsid.string (strbuf);
+ if ((gr = internal_getgrsid (cygheap->user.groups.pgsid)))
+ strlcpy (group_name, gr->gr_name, sizeof (group_name));
+ }
+ snprintf (linebuf, sizeof (linebuf), "%s:%s:%lu:%s",
+ group_name, strbuf, myself->gid, cygheap->user.name ());
+ debug_printf ("Completing /etc/group: %s", linebuf);
+ gr.add_line (linebuf);
}
+ static char NO_COPY pretty_ls[] = "????????::-1:";
+ if (wincap.has_security ())
+ gr.add_line (pretty_ls);
return;
}
@@ -153,8 +128,7 @@ internal_getgrsid (cygsid &sid)
{
char sid_string[128];
- if (gr.isuninitialized ())
- read_etc_group ();
+ gr.refresh ();
if (sid.string (sid_string))
for (int i = 0; i < gr.curr_lines; i++)
@@ -166,8 +140,7 @@ internal_getgrsid (cygsid &sid)
struct __group32 *
internal_getgrgid (__gid32_t gid, bool check)
{
- if (gr.isuninitialized () || (check && gr.isinitializing ()))
- read_etc_group ();
+ gr.refresh (check);
for (int i = 0; i < gr.curr_lines; i++)
if (group_buf[i].gr_gid == gid)
@@ -178,8 +151,7 @@ internal_getgrgid (__gid32_t gid, bool check)
struct __group32 *
internal_getgrnam (const char *name, bool check)
{
- if (gr.isuninitialized () || (check && gr.isinitializing ()))
- read_etc_group ();
+ gr.refresh (check);
for (int i = 0; i < gr.curr_lines; i++)
if (strcasematch (group_buf[i].gr_name, name))
@@ -242,8 +214,7 @@ endgrent ()
extern "C" struct __group32 *
getgrent32 ()
{
- if (gr.isinitializing ())
- read_etc_group ();
+ gr.refresh ();
if (grp_pos < gr.curr_lines)
return group_buf + grp_pos++;
@@ -269,8 +240,7 @@ setgrent ()
struct __group32 *
internal_getgrent (int pos)
{
- if (gr.isuninitialized ())
- read_etc_group ();
+ gr.refresh ();
if (pos < gr.curr_lines)
return group_buf + pos;