aboutsummaryrefslogtreecommitdiff
path: root/winsup/cygwin
diff options
context:
space:
mode:
authorCorinna Vinschen <corinna@vinschen.de>2001-08-07 08:56:22 +0000
committerCorinna Vinschen <corinna@vinschen.de>2001-08-07 08:56:22 +0000
commitf5e8e2be4a184e8d7f653af19fb62fb576c28d39 (patch)
tree3c7903a54be6c84bd85f7a0c6c8cc5ea46b423c4 /winsup/cygwin
parent300624d4f35236a18ad3416ecc7f13a58de82780 (diff)
downloadnewlib-f5e8e2be4a184e8d7f653af19fb62fb576c28d39.zip
newlib-f5e8e2be4a184e8d7f653af19fb62fb576c28d39.tar.gz
newlib-f5e8e2be4a184e8d7f653af19fb62fb576c28d39.tar.bz2
* grp.cc (class grp_check): New class. Make `group_state'
a member of class grp_check. (read_etc_group): Free former allocated memory on reread. * passwd.cc (class pwd_check): New class Make `passwd_state' a member of class pwd_check. (read_etc_passwd): Free former allocated memory on reread.
Diffstat (limited to 'winsup/cygwin')
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/grp.cc53
-rw-r--r--winsup/cygwin/passwd.cc51
3 files changed, 111 insertions, 2 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 473c8f5..e2f504f 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,12 @@
+Tue Aug 7 10:54:00 2001 Corinna Vinschen <corinna@vinschen.de>
+
+ * grp.cc (class grp_check): New class. Make `group_state'
+ a member of class grp_check.
+ (read_etc_group): Free former allocated memory on reread.
+ * passwd.cc (class pwd_check): New class Make `passwd_state'
+ a member of class pwd_check.
+ (read_etc_passwd): Free former allocated memory on reread.
+
Tue Aug 7 01:13:58 2001 Christopher Faylor <cgf@cygnus.com>
* fhandler_console.cc (get_tty_stuff): Don't initialize shared memory
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc
index 3e0ab3e..600302c 100644
--- a/winsup/cygwin/grp.cc
+++ b/winsup/cygwin/grp.cc
@@ -23,6 +23,7 @@ details. */
#include "security.h"
#include "fhandler.h"
#include "dtable.h"
+#include "path.h"
#include "cygheap.h"
#include "cygerrno.h"
@@ -51,7 +52,47 @@ enum grp_state {
emulated,
loaded
};
-static grp_state group_state = uninitialized;
+class grp_check {
+ grp_state state;
+ FILETIME last_modified;
+ char grp_w32[MAX_PATH];
+
+public:
+ grp_check () : state (uninitialized)
+ {
+ last_modified.dwLowDateTime = last_modified.dwHighDateTime = 0;
+ grp_w32[0] = '\0';
+ }
+ operator grp_state ()
+ {
+ HANDLE h;
+ WIN32_FIND_DATA data;
+
+ if (!grp_w32[0]) /* First call. */
+ {
+ path_conv g ("/etc/group", PC_SYM_FOLLOW | PC_FULL);
+ if (!g.error)
+ strcpy (grp_w32, g.get_win32 ());
+ }
+
+ if ((h = FindFirstFile (grp_w32, &data)) != INVALID_HANDLE_VALUE)
+ {
+ if (CompareFileTime (&data.ftLastWriteTime, &last_modified) > 0)
+ {
+ state = uninitialized;
+ last_modified = data.ftLastWriteTime;
+ }
+ FindClose (h);
+ }
+ return state;
+ }
+ void operator = (grp_state nstate)
+ {
+ state = nstate;
+ }
+};
+
+static grp_check group_state;
static int
parse_grp (struct group &grp, const char *line)
@@ -153,6 +194,16 @@ read_etc_group ()
if (group_state != initializing)
{
group_state = initializing;
+ if (max_lines) /* When rereading, free allocated memory first. */
+ {
+ for (int i = 0; i < curr_lines; ++i)
+ {
+ free (group_buf[i].gr_name);
+ free (group_buf[i].gr_mem);
+ }
+ free (group_buf);
+ curr_lines = max_lines = 0;
+ }
FILE *f = fopen (etc_group, "rt");
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index f29eb20..a1a5c33 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -17,6 +17,7 @@ details. */
#include "security.h"
#include "fhandler.h"
#include "dtable.h"
+#include "path.h"
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
@@ -40,7 +41,48 @@ enum pwd_state {
emulated,
loaded
};
-static pwd_state passwd_state = uninitialized;
+class pwd_check {
+ pwd_state state;
+ FILETIME last_modified;
+ char pwd_w32[MAX_PATH];
+
+public:
+ pwd_check () : state (uninitialized)
+ {
+ last_modified.dwLowDateTime = last_modified.dwHighDateTime = 0;
+ pwd_w32[0] = '\0';
+ }
+ operator pwd_state ()
+ {
+ HANDLE h;
+ WIN32_FIND_DATA data;
+
+ if (!pwd_w32[0]) /* First call. */
+ {
+ path_conv p ("/etc/passwd", PC_SYM_FOLLOW | PC_FULL);
+ if (!p.error)
+ strcpy (pwd_w32, p.get_win32 ());
+ }
+
+ if ((h = FindFirstFile (pwd_w32, &data)) != INVALID_HANDLE_VALUE)
+ {
+ if (CompareFileTime (&data.ftLastWriteTime, &last_modified) > 0)
+ {
+ state = uninitialized;
+ last_modified = data.ftLastWriteTime;
+ }
+ FindClose (h);
+ }
+ return state;
+ }
+ void operator = (pwd_state nstate)
+ {
+ state = nstate;
+ }
+};
+
+static pwd_check passwd_state;
+
/* Position in the passwd cache */
#ifdef _MT_SAFE
@@ -140,6 +182,13 @@ read_etc_passwd ()
if (passwd_state != initializing)
{
passwd_state = initializing;
+ if (max_lines) /* When rereading, free allocated memory first. */
+ {
+ for (int i = 0; i < curr_lines; ++i)
+ free (passwd_buf[i].pw_name);
+ free (passwd_buf);
+ curr_lines = max_lines = 0;
+ }
FILE *f = fopen ("/etc/passwd", "rt");