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>2001-04-19 01:10:15 +0400
committerChristopher Faylor <me@cgf.cx>2001-04-19 01:10:15 +0400
commit0381fec68f46471d29d3b87c5361e05fcdeb2cd5 (patch)
tree718cfaf2d3d8734c48f8957892329c0e8fc2fbfc
parenta2d47fe9d983ec85075172211172af9e5ab4054f (diff)
Throughout, change fdtab references to cygheap->fdtab.
* child_info.h (cygheap_exec_info): Eliminate special fdtab stuff. * spawn.cc (spawn_guts): Ditto. * cygheap.cc (cygheap_init): Initialize fdtab, if appropriate. * cygheap.h (CYGHEAPSIZE): Include size of init_cygheap. (_cmalloc_entry): Include fdtab here. * dtable.h (dtable): Declare/define new methods. * dtable.cc (dtable::vfork_child_fixup): New method. (dtable::fixup_after_exec): Remove unneeded extra arguments. * dcrt0.cc (dll_crt0_1): Ditto. * environ.cc (getwinenv): Use case sensitive comparison. (winenv): Make a copy of environment cache to avoid realloc problems when duplicate environment variables exist in the environment. (From Egor Duda) * net.cc (cygwin_socket): Revert Apr 14 change. * include/sys/file.h: Protect against previous X_OK definition. * passwd.cc: Eliminate passwd_sem throughout. * security.cc: Ditto. * cygwin.din: Export New functions. * passwd.cc (read_etc_passwd): Make race safe. (getpwuid_r): New function. (getpwnam_r): New function.
-rw-r--r--winsup/cygwin/ChangeLog34
-rw-r--r--winsup/cygwin/child_info.h2
-rw-r--r--winsup/cygwin/cygheap.cc4
-rw-r--r--winsup/cygwin/cygheap.h5
-rw-r--r--winsup/cygwin/cygwin.din2
-rw-r--r--winsup/cygwin/dcrt0.cc17
-rw-r--r--winsup/cygwin/dir.cc1
-rw-r--r--winsup/cygwin/dtable.cc82
-rw-r--r--winsup/cygwin/dtable.h4
-rw-r--r--winsup/cygwin/environ.cc13
-rw-r--r--winsup/cygwin/fcntl.cc7
-rw-r--r--winsup/cygwin/fhandler.cc5
-rw-r--r--winsup/cygwin/fhandler_console.cc3
-rw-r--r--winsup/cygwin/fhandler_raw.cc3
-rw-r--r--winsup/cygwin/fhandler_socket.cc2
-rw-r--r--winsup/cygwin/fhandler_tape.cc3
-rw-r--r--winsup/cygwin/fhandler_tty.cc2
-rw-r--r--winsup/cygwin/fork.cc12
-rw-r--r--winsup/cygwin/grp.cc2
-rw-r--r--winsup/cygwin/include/sys/file.h1
-rw-r--r--winsup/cygwin/ioctl.cc5
-rw-r--r--winsup/cygwin/malloc_wrapper.cc2
-rw-r--r--winsup/cygwin/mmap.cc14
-rw-r--r--winsup/cygwin/net.cc47
-rw-r--r--winsup/cygwin/passwd.cc150
-rw-r--r--winsup/cygwin/path.cc1
-rw-r--r--winsup/cygwin/pipe.cc15
-rw-r--r--winsup/cygwin/poll.cc5
-rw-r--r--winsup/cygwin/security.cc12
-rw-r--r--winsup/cygwin/select.cc11
-rw-r--r--winsup/cygwin/shared.cc2
-rw-r--r--winsup/cygwin/sigproc.cc2
-rw-r--r--winsup/cygwin/spawn.cc10
-rw-r--r--winsup/cygwin/syscalls.cc101
-rw-r--r--winsup/cygwin/sysconf.cc3
-rw-r--r--winsup/cygwin/syslog.cc2
-rw-r--r--winsup/cygwin/termios.cc39
-rw-r--r--winsup/cygwin/tty.cc3
-rw-r--r--winsup/cygwin/uinfo.cc2
39 files changed, 400 insertions, 230 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index a60d3361e..97366b03b 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,3 +1,37 @@
+Wed Apr 18 16:53:54 2001 Christopher Faylor <cgf@cygnus.com>
+
+ Throughout, change fdtab references to cygheap->fdtab.
+ * child_info.h (cygheap_exec_info): Eliminate special fdtab stuff.
+ * spawn.cc (spawn_guts): Ditto.
+ * cygheap.cc (cygheap_init): Initialize fdtab, if appropriate.
+ * cygheap.h (CYGHEAPSIZE): Include size of init_cygheap.
+ (_cmalloc_entry): Include fdtab here.
+ * dtable.h (dtable): Declare/define new methods.
+ * dtable.cc (dtable::vfork_child_fixup): New method.
+ (dtable::fixup_after_exec): Remove unneeded extra arguments.
+ * dcrt0.cc (dll_crt0_1): Ditto.
+
+ * environ.cc (getwinenv): Use case sensitive comparison.
+ (winenv): Make a copy of environment cache to avoid realloc problems
+ when duplicate environment variables exist in the environment. (From
+ Egor Duda)
+
+ * net.cc (cygwin_socket): Revert Apr 14 change.
+
+ * include/sys/file.h: Protect against previous X_OK definition.
+
+Tue Apr 17 12:18:28 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * passwd.cc: Eliminate passwd_sem throughout.
+ * security.cc: Ditto.
+
+Tue Apr 17 12:18:28 2001 Robert Collins <rbtcollins@hotmail.com>
+
+ * cygwin.din: Export New functions.
+ * passwd.cc (read_etc_passwd): Make race safe.
+ (getpwuid_r): New function.
+ (getpwnam_r): New function.
+
2001-04-18 Egor Duda <deo@logos-m.ru>
* grp.cc (getgroups): Avoid crash if passwd field if /etc/group is
diff --git a/winsup/cygwin/child_info.h b/winsup/cygwin/child_info.h
index 5cef2607b..b9a466dda 100644
--- a/winsup/cygwin/child_info.h
+++ b/winsup/cygwin/child_info.h
@@ -61,8 +61,6 @@ class cygheap_exec_info
public:
uid_t uid;
char *old_title;
- fhandler_base **fds;
- size_t nfds;
int argc;
char **argv;
int envc;
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index 86ee44941..24df5a957 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -13,6 +13,8 @@
#include <fhandler.h>
#include <assert.h>
#include <stdlib.h>
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "heap.h"
#include "cygerrno.h"
@@ -66,6 +68,8 @@ cygheap_init ()
{
cygheap_protect = new_muto (FALSE, "cygheap_protect");
_csbrk (0);
+ if (!cygheap->fdtab)
+ cygheap->fdtab.init ();
}
/* Copyright (C) 1997, 2000 DJ Delorie */
diff --git a/winsup/cygwin/cygheap.h b/winsup/cygwin/cygheap.h
index b807612a5..6a8e56290 100644
--- a/winsup/cygwin/cygheap.h
+++ b/winsup/cygwin/cygheap.h
@@ -24,8 +24,6 @@ enum cygheap_types
HEAP_1_MAX = 100
};
-#define CYGHEAPSIZE ((4000 * sizeof (fhandler_union)) + (2 * 65536))
-
#define incygheap(s) (cygheap && ((char *) (s) >= (char *) cygheap) && ((char *) (s) <= ((char *) cygheap_max)))
struct _cmalloc_entry
@@ -124,8 +122,11 @@ struct init_cygheap
HANDLE shared_h;
HANDLE console_h;
cwdstuff cwd;
+ dtable fdtab;
};
+#define CYGHEAPSIZE (sizeof (init_cygheap) + (4000 * sizeof (fhandler_union)) + (2 * 65536))
+
extern init_cygheap *cygheap;
extern void *cygheap_max;
diff --git a/winsup/cygwin/cygwin.din b/winsup/cygwin/cygwin.din
index 285f7249c..468af359a 100644
--- a/winsup/cygwin/cygwin.din
+++ b/winsup/cygwin/cygwin.din
@@ -933,8 +933,10 @@ getpwduid
_getpwduid = getpwduid
getpwnam
_getpwnam = getpwnam
+getpwnam_r
getpwuid
_getpwuid = getpwuid
+getpwuid_r
getpgrp
_getpgrp = getpgrp
getgrent
diff --git a/winsup/cygwin/dcrt0.cc b/winsup/cygwin/dcrt0.cc
index ff75644bd..a56f6281c 100644
--- a/winsup/cygwin/dcrt0.cc
+++ b/winsup/cygwin/dcrt0.cc
@@ -20,16 +20,16 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
-#include "cygheap.h"
#include "heap.h"
#include "cygerrno.h"
-#include "fhandler.h"
-#include "child_info.h"
#define NEED_VFORK
-#include "perthread.h"
#include "perprocess.h"
-#include "path.h"
+#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
+#include "child_info.h"
+#include "path.h"
+#include "perthread.h"
#include "shared_info.h"
#include "cygwin_version.h"
#include "dll_init.h"
@@ -701,8 +701,7 @@ dll_crt0_1 ()
__argv = spawn_info->moreinfo->argv;
envp = spawn_info->moreinfo->envp;
envc = spawn_info->moreinfo->envc;
- fdtab.fixup_after_exec (spawn_info->parent, spawn_info->moreinfo->nfds,
- spawn_info->moreinfo->fds);
+ cygheap->fdtab.fixup_after_exec (spawn_info->parent);
signal_fixup_after_exec (child_proc_info->type == PROC_SPAWN);
CloseHandle (spawn_info->parent);
if (spawn_info->moreinfo->old_title)
@@ -716,7 +715,6 @@ dll_crt0_1 ()
cygheap->user.set_sid (NULL);
break;
}
- // fdtab.vfork_child_fixup ();
}
ProtectHandle (hMainProc);
ProtectHandle (hMainThread);
@@ -727,6 +725,7 @@ dll_crt0_1 ()
/* Initialize the cygwin subsystem if this is the first process,
or attach to shared data structures if it's already running. */
memory_init ();
+ cygheap->fdtab.vfork_child_fixup ();
(void) SetErrorMode (SEM_FAILCRITICALERRORS);
@@ -770,7 +769,7 @@ dll_crt0_1 ()
if (!old_title && GetConsoleTitle (title_buf, TITLESIZE))
old_title = title_buf;
- /* Allocate fdtab */
+ /* Allocate cygheap->fdtab */
dtable_init ();
/* Initialize uid, gid. */
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index 2f13fcdca..7c0c35e64 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -25,6 +25,7 @@ details. */
#include "perprocess.h"
#include "path.h"
#include "security.h"
+#include "dtable.h"
#include "cygheap.h"
/* Cygwin internal */
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index b67949faa..b5f9a9136 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -24,14 +24,12 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
-#include "cygheap.h"
#include "cygerrno.h"
#include "perprocess.h"
#include "fhandler.h"
#include "path.h"
#include "dtable.h"
-
-dtable fdtab;
+#include "cygheap.h"
static DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
STD_ERROR_HANDLE};
@@ -40,17 +38,17 @@ static DWORD std_consts[] = {STD_INPUT_HANDLE, STD_OUTPUT_HANDLE,
void
dtable_init (void)
{
- if (!fdtab.size)
- fdtab.extend(NOFILE_INCR);
+ if (!cygheap->fdtab.size)
+ cygheap->fdtab.extend(NOFILE_INCR);
}
void __stdcall
set_std_handle (int fd)
{
if (fd == 0)
- SetStdHandle (std_consts[fd], fdtab[fd]->get_handle ());
+ SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_handle ());
else if (fd <= 2)
- SetStdHandle (std_consts[fd], fdtab[fd]->get_output_handle ());
+ SetStdHandle (std_consts[fd], cygheap->fdtab[fd]->get_output_handle ());
}
int
@@ -99,7 +97,7 @@ stdio_init (void)
HANDLE out = GetStdHandle (STD_OUTPUT_HANDLE);
HANDLE err = GetStdHandle (STD_ERROR_HANDLE);
- fdtab.init_std_file_from_handle (0, in, GENERIC_READ, "{stdin}");
+ cygheap->fdtab.init_std_file_from_handle (0, in, GENERIC_READ, "{stdin}");
/* STD_ERROR_HANDLE has been observed to be the same as
STD_OUTPUT_HANDLE. We need separate handles (e.g. using pipes
@@ -117,19 +115,19 @@ stdio_init (void)
}
}
- fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE, "{stdout}");
- fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE, "{stderr}");
+ cygheap->fdtab.init_std_file_from_handle (1, out, GENERIC_WRITE, "{stdout}");
+ cygheap->fdtab.init_std_file_from_handle (2, err, GENERIC_WRITE, "{stderr}");
}
}
int
dtable::not_open (int fd)
{
- SetResourceLock(LOCK_FD_LIST,READ_LOCK," not_open");
+ SetResourceLock(LOCK_FD_LIST, READ_LOCK, "not_open");
int res = fd < 0 || fd >= (int)size || fds[fd] == NULL;
- ReleaseResourceLock(LOCK_FD_LIST,READ_LOCK," not open");
+ ReleaseResourceLock(LOCK_FD_LIST, READ_LOCK, "not open");
return res;
}
@@ -214,8 +212,8 @@ cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
DWORD myaccess)
{
if (fd == -1)
- fd = fdtab.find_unused_handle();
- fhandler_base *res = fdtab.build_fhandler (fd, name, handle);
+ fd = cygheap->fdtab.find_unused_handle();
+ fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle);
res->init (handle, myaccess, bin);
return fd;
}
@@ -377,18 +375,18 @@ dtable::dup2 (int oldfd, int newfd)
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
- if ((size_t) newfd >= fdtab.size || newfd < 0)
+ if ((size_t) newfd >= cygheap->fdtab.size || newfd < 0)
{
syscall_printf ("new fd out of bounds: %d", newfd);
set_errno (EBADF);
goto done;
}
- if ((size_t) newfd >= fdtab.size)
+ if ((size_t) newfd >= cygheap->fdtab.size)
{
int inc_size = NOFILE_INCR * ((newfd + NOFILE_INCR - 1) / NOFILE_INCR) -
- fdtab.size;
- fdtab.extend (inc_size);
+ cygheap->fdtab.size;
+ cygheap->fdtab.extend (inc_size);
}
if (!not_open (newfd))
@@ -468,7 +466,7 @@ dtable::select_except (int fd, select_record *s)
void
dtable::fixup_before_fork (DWORD target_proc_id)
{
- SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork");
fhandler_base *fh;
for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL)
@@ -476,28 +474,26 @@ dtable::fixup_before_fork (DWORD target_proc_id)
debug_printf ("fd %d(%s)", i, fh->get_name ());
fh->fixup_before_fork_exec (target_proc_id);
}
- ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_fork");
}
void
dtable::fixup_before_exec (DWORD target_proc_id)
{
- SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_exec");
fhandler_base *fh;
for (size_t i = 0; i < size; i++)
- if ((fh = fds[i]) != NULL && (!fh->get_close_on_exec ()))
+ if ((fh = fds[i]) != NULL && !fh->get_close_on_exec ())
{
debug_printf ("fd %d(%s)", i, fh->get_name ());
fh->fixup_before_fork_exec (target_proc_id);
}
- ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "fixup_before_exec");
}
void
-dtable::fixup_after_exec (HANDLE parent, size_t sz, fhandler_base **f)
+dtable::fixup_after_exec (HANDLE parent)
{
- size = sz;
- fds = f;
first_fd_for_open = 0;
fhandler_base *fh;
for (size_t i = 0; i < size; i++)
@@ -520,7 +516,6 @@ dtable::fixup_after_exec (HANDLE parent, size_t sz, fhandler_base **f)
void
dtable::fixup_after_fork (HANDLE parent)
{
- SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
fhandler_base *fh;
for (size_t i = 0; i < size; i++)
if ((fh = fds[i]) != NULL)
@@ -531,7 +526,6 @@ dtable::fixup_after_fork (HANDLE parent)
fh->fixup_after_fork (parent);
}
}
- ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
}
int
@@ -541,7 +535,7 @@ dtable::vfork_child_dup ()
newtable = (fhandler_base **) ccalloc (HEAP_ARGV, size, sizeof(fds[0]));
int res = 1;
- SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
for (size_t i = 0; i < size; i++)
if (not_open (i))
continue;
@@ -555,14 +549,14 @@ dtable::vfork_child_dup ()
fds_on_hold = fds;
fds = newtable;
out:
- ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "dup");
return 1;
}
void
dtable::vfork_parent_restore ()
{
- SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ SetResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
close_all_files ();
fhandler_base **deleteme = fds;
@@ -570,6 +564,30 @@ dtable::vfork_parent_restore ()
fds_on_hold = NULL;
cfree (deleteme);
- ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"dup");
+ ReleaseResourceLock(LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "restore");
+ return;
+}
+
+void
+dtable::vfork_child_fixup ()
+{
+ if (!fds_on_hold)
+ return;
+ fhandler_base **saveme = fds;
+ fds = fds_on_hold;
+
+ fhandler_base *fh;
+ for (int i = 0; i < (int) cygheap->fdtab.size; i++)
+ if ((fh = cygheap->fdtab[i]) != NULL)
+ {
+ fh->close ();
+ fh->clear_readahead ();
+ cygheap->fdtab.release (i);
+ }
+
+ fds = saveme;
+ cfree (fds_on_hold);
+ fds_on_hold = NULL;
+
return;
}
diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h
index 9ec6dfae6..b67cfbcc1 100644
--- a/winsup/cygwin/dtable.h
+++ b/winsup/cygwin/dtable.h
@@ -21,6 +21,7 @@ public:
size_t size;
dtable () : first_fd_for_open(3), cnt_need_fixup_before(0) {}
+ void init () {first_fd_for_open = 3;}
void dec_need_fixup_before ()
{ if (cnt_need_fixup_before > 0) --cnt_need_fixup_before; }
@@ -31,6 +32,7 @@ public:
int vfork_child_dup ();
void vfork_parent_restore ();
+ void vfork_child_fixup ();
fhandler_base *dup_worker (fhandler_base *oldfh);
int extend (int howmuch);
void fixup_before_exec (DWORD win_proc_id);
@@ -45,7 +47,7 @@ public:
void release (int fd);
void init_std_file_from_handle (int fd, HANDLE handle, DWORD access, const char *name);
int dup2 (int oldfd, int newfd);
- void fixup_after_exec (HANDLE, size_t, fhandler_base **);
+ void fixup_after_exec (HANDLE);
inline fhandler_base *operator [](int fd) { return fds[fd]; }
select_record *select_read (int fd, select_record *s);
select_record *select_write (int fd, select_record *s);
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index 2f8e350d8..25985e614 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -22,6 +22,7 @@ details. */
#include "fhandler.h"
#include "path.h"
#include "cygerrno.h"
+#include "dtable.h"
#include "cygheap.h"
#include "registry.h"
#include "environ.h"
@@ -105,7 +106,7 @@ getwinenv (const char *env, const char *in_posix)
return NULL;
for (int i = 0; conv_envvars[i].name != NULL; i++)
- if (strncasematch (env, conv_envvars[i].name, conv_envvars[i].namelen))
+ if (strncmp (env, conv_envvars[i].name, conv_envvars[i].namelen) == 0)
{
win_env *we = conv_envvars + i;
const char *val;
@@ -735,10 +736,14 @@ winenv (const char * const *envp, int keep_posix)
len = strcspn (*srcp, "=") + 1;
win_env *conv;
- if (!keep_posix && (conv = getwinenv (*srcp, *srcp + len)))
- *dstp = conv->native;
- else
+ if (keep_posix || !(conv = getwinenv (*srcp, *srcp + len)))
*dstp = *srcp;
+ else
+ {
+ char *p = (char *) alloca (strlen (conv->native) + 1);
+ strcpy (p, conv->native);
+ *dstp = p;
+ }
tl += strlen (*dstp) + 1;
if ((*dstp)[0] == '!' && isdrive ((*dstp) + 1) && (*dstp)[3] == '=')
{
diff --git a/winsup/cygwin/fcntl.cc b/winsup/cygwin/fcntl.cc
index 408cbc2cb..02e673692 100644
--- a/winsup/cygwin/fcntl.cc
+++ b/winsup/cygwin/fcntl.cc
@@ -15,6 +15,7 @@ details. */
#include <unistd.h>
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "cygerrno.h"
#include "thread.h"
@@ -26,7 +27,7 @@ _fcntl (int fd, int cmd,...)
va_list args;
int res;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
res = -1;
@@ -37,9 +38,9 @@ _fcntl (int fd, int cmd,...)
va_start (args, cmd);
arg = va_arg (args, void *);
if (cmd == F_DUPFD)
- res = dup2 (fd, fdtab.find_unused_handle ((int) arg));
+ res = dup2 (fd, cygheap->fdtab.find_unused_handle ((int) arg));
else
- res = fdtab[fd]->fcntl(cmd, arg);
+ res = cygheap->fdtab[fd]->fcntl(cmd, arg);
va_end (args);
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK,"_fcntl");
diff --git a/winsup/cygwin/fhandler.cc b/winsup/cygwin/fhandler.cc
index df2fd2217..330a7be1c 100644
--- a/winsup/cygwin/fhandler.cc
+++ b/winsup/cygwin/fhandler.cc
@@ -13,12 +13,13 @@ details. */
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
-#include "cygheap.h"
#include <sys/cygwin.h>
#include <signal.h>
#include "cygerrno.h"
#include "perprocess.h"
#include "fhandler.h"
+#include "dtable.h"
+#include "cygheap.h"
#include "path.h"
#include "shared_info.h"
#include "host_dependent.h"
@@ -77,7 +78,7 @@ fhandler_base::get_readahead ()
{
int chret = -1;
if (raixget < ralen)
- chret = ((unsigned char)rabuf[raixget++]) & 0xff;
+ chret = ((unsigned char) rabuf[raixget++]) & 0xff;
/* FIXME - not thread safe */
if (raixget >= ralen)
raixget = raixput = ralen = 0;
diff --git a/winsup/cygwin/fhandler_console.cc b/winsup/cygwin/fhandler_console.cc
index 75b464cc9..166c12af0 100644
--- a/winsup/cygwin/fhandler_console.cc
+++ b/winsup/cygwin/fhandler_console.cc
@@ -21,9 +21,10 @@ details. */
#include <winnls.h> // MultiByteToWideChar () and friends
#include <ctype.h>
#include <sys/cygwin.h>
-#include "cygheap.h"
#include "cygerrno.h"
#include "fhandler.h"
+#include "dtable.h"
+#include "cygheap.h"
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
diff --git a/winsup/cygwin/fhandler_raw.cc b/winsup/cygwin/fhandler_raw.cc
index 2dd58be74..9fc6dffbf 100644
--- a/winsup/cygwin/fhandler_raw.cc
+++ b/winsup/cygwin/fhandler_raw.cc
@@ -16,10 +16,11 @@
#include <cygwin/rdevio.h>
#include <sys/mtio.h>
-#include "cygheap.h"
#include "cygerrno.h"
#include "perprocess.h"
#include "fhandler.h"
+#include "dtable.h"
+#include "cygheap.h"
#include "path.h"
/* static wrapper functions to hide the effect of media changes and
diff --git a/winsup/cygwin/fhandler_socket.cc b/winsup/cygwin/fhandler_socket.cc
index 3b3ba7bac..f4428639a 100644
--- a/winsup/cygwin/fhandler_socket.cc
+++ b/winsup/cygwin/fhandler_socket.cc
@@ -21,10 +21,10 @@
#include <fcntl.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
-#include "cygheap.h"
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "sigproc.h"
#define SECRET_EVENT_NAME "cygwin.local_socket.secret.%d.%08x-%08x-%08x-%08x"
diff --git a/winsup/cygwin/fhandler_tape.cc b/winsup/cygwin/fhandler_tape.cc
index 57d782a4c..2b6e31705 100644
--- a/winsup/cygwin/fhandler_tape.cc
+++ b/winsup/cygwin/fhandler_tape.cc
@@ -16,10 +16,11 @@ details. */
#include <unistd.h>
#include <sys/mtio.h>
-#include "cygheap.h"
#include "cygerrno.h"
#include "perprocess.h"
#include "fhandler.h"
+#include "dtable.h"
+#include "cygheap.h"
#include "path.h"
/**********************************************************************/
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index 7f140a5c3..0aaf1b978 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1173,7 +1173,7 @@ fhandler_tty_master::fixup_after_exec (HANDLE)
int
fhandler_tty_master::init_console ()
{
- console = (fhandler_console *) fdtab.build_fhandler (-1, FH_CONSOLE, "/dev/ttym");
+ console = (fhandler_console *) cygheap->fdtab.build_fhandler (-1, FH_CONSOLE, "/dev/ttym");
if (console == NULL)
return -1;
diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index de85c1d96..646dbee58 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -274,7 +274,7 @@ fork_child (HANDLE& hParent, dll *&first_dll, bool& load_dlls)
MALLOC_CHECK;
pinfo_fixup_after_fork ();
- fdtab.fixup_after_fork (hParent);
+ cygheap->fdtab.fixup_after_fork (hParent);
signal_fixup_after_fork ();
MALLOC_CHECK;
@@ -377,7 +377,7 @@ fork_parent (void *stack_here, HANDLE& hParent, dll *&first_dll,
parent after CreateProcess and before copying the datastructures
to the child. So we have to start the child in suspend state,
unfortunately, to avoid a race condition. */
- if (fdtab.need_fixup_before ())
+ if (cygheap->fdtab.need_fixup_before ())
c_flags |= CREATE_SUSPENDED;
/* Create an inheritable handle to pass to the child process. This will
@@ -490,9 +490,9 @@ out:
/* Fixup the parent datastructure if needed and resume the child's
main thread. */
- if (fdtab.need_fixup_before ())
+ if (cygheap->fdtab.need_fixup_before ())
{
- fdtab.fixup_before_fork (pi.dwProcessId);
+ cygheap->fdtab.fixup_before_fork (pi.dwProcessId);
ResumeThread (pi.hThread);
}
@@ -708,10 +708,10 @@ vfork ()
for (pp = (char **)vf->frame, esp = vf->vfork_esp;
esp <= vf->vfork_ebp + 1; pp++, esp++)
*pp = *esp;
- return fdtab.vfork_child_dup () ? 0 : -1;
+ return cygheap->fdtab.vfork_child_dup () ? 0 : -1;
}
- fdtab.vfork_parent_restore ();
+ cygheap->fdtab.vfork_parent_restore ();
vf = get_vfork_val ();
if (vf->pid < 0)
diff --git a/winsup/cygwin/grp.cc b/winsup/cygwin/grp.cc
index d3431a37f..ed6091fea 100644
--- a/winsup/cygwin/grp.cc
+++ b/winsup/cygwin/grp.cc
@@ -19,6 +19,8 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "cygerrno.h"
#include "security.h"
diff --git a/winsup/cygwin/include/sys/file.h b/winsup/cygwin/include/sys/file.h
index dacf33429..9a63695df 100644
--- a/winsup/cygwin/include/sys/file.h
+++ b/winsup/cygwin/include/sys/file.h
@@ -28,6 +28,7 @@
#if defined (__CYGWIN__) || defined (__INSIDE_CYGWIN__)
# define X_OK _X_OK /* Check for execute permission. */
#else
+# undef X_OK
extern const unsigned _cygwin_X_OK;
# define X_OK _cygwin_X_OK
#endif
diff --git a/winsup/cygwin/ioctl.cc b/winsup/cygwin/ioctl.cc
index 50bed772b..93870444d 100644
--- a/winsup/cygwin/ioctl.cc
+++ b/winsup/cygwin/ioctl.cc
@@ -17,19 +17,20 @@ details. */
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include <sys/termios.h>
extern "C" int
ioctl (int fd, int cmd, void *buf)
{
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
debug_printf ("fd %d, cmd %x\n", fd, cmd);
- fhandler_base *fh = fdtab[fd];
+ fhandler_base *fh = cygheap->fdtab[fd];
if (fh->is_tty () && fh->get_device () != FH_PTYM)
switch (cmd)
{
diff --git a/winsup/cygwin/malloc_wrapper.cc b/winsup/cygwin/malloc_wrapper.cc
index ad117eb8f..fd1653a3e 100644
--- a/winsup/cygwin/malloc_wrapper.cc
+++ b/winsup/cygwin/malloc_wrapper.cc
@@ -14,6 +14,8 @@ details. */
#include "winsup.h"
#include <stdlib.h>
#include <assert.h>
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "heap.h"
#include "sync.h"
diff --git a/winsup/cygwin/mmap.cc b/winsup/cygwin/mmap.cc
index b13056b0c..97ee24c0c 100644
--- a/winsup/cygwin/mmap.cc
+++ b/winsup/cygwin/mmap.cc
@@ -61,8 +61,8 @@ class mmap_record
base_address_ (b),
map_map_ (NULL)
{
- if (fd >= 0 && !fdtab.not_open (fd))
- devtype_ = fdtab[fd]->get_device ();
+ if (fd >= 0 && !cygheap->fdtab.not_open (fd))
+ devtype_ = cygheap->fdtab[fd]->get_device ();
}
/* Default Copy constructor/operator=/destructor are ok */
@@ -231,7 +231,7 @@ mmap_record::alloc_fh ()
the call to fork(). This requires creating a fhandler
of the correct type to be sure to call the method of the
correct class. */
- return fdtab.build_fhandler (-1, get_device (), "", 0);
+ return cygheap->fdtab.build_fhandler (-1, get_device (), "", 0);
}
void
@@ -355,7 +355,7 @@ map::get_list_by_fd (int fd)
#else /* so we use the name hash value to identify the file unless
it's not an anonymous mapping. */
if ((fd == -1 && lists[i]->fd == -1)
- || (fd != -1 && lists[i]->hash == fdtab[fd]->get_namehash ()))
+ || (fd != -1 && lists[i]->hash == cygheap->fdtab[fd]->get_namehash ()))
#endif
return lists[i];
return 0;
@@ -366,7 +366,7 @@ map::add_list (list *l, int fd)
{
l->fd = fd;
if (fd != -1)
- l->hash = fdtab[fd]->get_namehash ();
+ l->hash = cygheap->fdtab[fd]->get_namehash ();
if (nlists == maxlists)
{
maxlists += 5;
@@ -471,14 +471,14 @@ mmap (caddr_t addr, size_t len, int prot, int flags, int fd, off_t off)
if (fd != -1)
{
/* Ensure that fd is open */
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
syscall_printf ("-1 = mmap(): EBADF");
ReleaseResourceLock(LOCK_MMAP_LIST,READ_LOCK|WRITE_LOCK," mmap");
return MAP_FAILED;
}
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (fh->get_device () == FH_DISK)
{
DWORD fsiz = GetFileSize (fh->get_handle (), NULL);
diff --git a/winsup/cygwin/net.cc b/winsup/cygwin/net.cc
index 536505701..990df2451 100644
--- a/winsup/cygwin/net.cc
+++ b/winsup/cygwin/net.cc
@@ -24,12 +24,12 @@ details. */
#include <fcntl.h>
#define USE_SYS_TYPES_FD_SET
#include <winsock2.h>
-#include "cygheap.h"
#include "cygerrno.h"
#include "perprocess.h"
#include "fhandler.h"
#include "path.h"
#include "dtable.h"
+#include "cygheap.h"
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
@@ -327,10 +327,10 @@ fdsock (int fd, const char *name, SOCKET soc)
{
if (wsadata.wVersion < 512) /* < Winsock 2.0 */
soc = set_socket_inheritance (soc);
- fhandler_socket *fh = (fhandler_socket *) fdtab.build_fhandler (fd, FH_SOCKET, name);
+ fhandler_socket *fh = (fhandler_socket *) cygheap->fdtab.build_fhandler (fd, FH_SOCKET, name);
fh->set_io_handle ((HANDLE) soc);
fh->set_flags (O_RDWR);
- fdtab.inc_need_fixup_before ();
+ cygheap->fdtab.inc_need_fixup_before ();
return fh;
}
@@ -343,7 +343,7 @@ cygwin_socket (int af, int type, int protocol)
SOCKET soc;
- int fd = fdtab.find_unused_handle ();
+ int fd = cygheap->fdtab.find_unused_handle ();
if (fd < 0)
set_errno (EMFILE);
@@ -363,12 +363,7 @@ cygwin_socket (int af, int type, int protocol)
if (af == AF_INET)
name = (type == SOCK_STREAM ? "/dev/tcp" : "/dev/udp");
else
- {
- name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket");
- /* Set LINGER with 0 timeout for hard close */
- struct linger tmp = {1, 0}; /* On, 0 delay */
- (void) setsockopt (soc, SOL_SOCKET, SO_LINGER, (char *)&tmp, sizeof(tmp));
- }
+ name = (type == SOCK_STREAM ? "/dev/streamsocket" : "/dev/dgsocket");
fdsock (fd, name, soc)->set_addr_family (af);
res = fd;
@@ -435,7 +430,7 @@ cygwin_sendto (int fd,
const struct sockaddr *to,
int tolen)
{
- fhandler_socket *h = (fhandler_socket *) fdtab[fd];
+ fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
sockaddr_in sin;
sigframe thisframe (mainthread);
@@ -461,7 +456,7 @@ cygwin_recvfrom (int fd,
struct sockaddr *from,
int *fromlen)
{
- fhandler_socket *h = (fhandler_socket *) fdtab[fd];
+ fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
sigframe thisframe (mainthread);
debug_printf ("recvfrom %d", h->get_socket ());
@@ -480,13 +475,13 @@ cygwin_recvfrom (int fd,
fhandler_socket *
get (int fd)
{
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EINVAL);
return 0;
}
- return fdtab[fd]->is_socket ();
+ return cygheap->fdtab[fd]->is_socket ();
}
/* exported as setsockopt: standards? */
@@ -823,7 +818,7 @@ cygwin_accept (int fd, struct sockaddr *peer, int *len)
SetResourceLock (LOCK_FD_LIST, WRITE_LOCK|READ_LOCK, "accept");
- int res_fd = fdtab.find_unused_handle ();
+ int res_fd = cygheap->fdtab.find_unused_handle ();
if (res_fd == -1)
{
/* FIXME: what is correct errno? */
@@ -1021,7 +1016,7 @@ cygwin_hstrerror (int err)
extern "C" void
cygwin_herror (const char *s)
{
- if (fdtab.not_open (2))
+ if (cygheap->fdtab.not_open (2))
return;
if (s)
@@ -1053,7 +1048,7 @@ cygwin_herror (const char *s)
extern "C" int
cygwin_getpeername (int fd, struct sockaddr *name, int *len)
{
- fhandler_socket *h = (fhandler_socket *) fdtab[fd];
+ fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
debug_printf ("getpeername %d", h->get_socket ());
int res = getpeername (h->get_socket (), name, len);
@@ -1068,7 +1063,7 @@ cygwin_getpeername (int fd, struct sockaddr *name, int *len)
extern "C" int
cygwin_recv (int fd, void *buf, int len, unsigned int flags)
{
- fhandler_socket *h = (fhandler_socket *) fdtab[fd];
+ fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
sigframe thisframe (mainthread);
int res = recv (h->get_socket (), (char *) buf, len, flags);
@@ -1093,7 +1088,7 @@ cygwin_recv (int fd, void *buf, int len, unsigned int flags)
extern "C" int
cygwin_send (int fd, const void *buf, int len, unsigned int flags)
{
- fhandler_socket *h = (fhandler_socket *) fdtab[fd];
+ fhandler_socket *h = (fhandler_socket *) cygheap->fdtab[fd];
sigframe thisframe (mainthread);
int res = send (h->get_socket (), (const char *) buf, len, flags);
@@ -1728,13 +1723,13 @@ cygwin_rcmd (char **ahost, unsigned short inport, char *locuser,
SOCKET fd2s;
sigframe thisframe (mainthread);
- int res_fd = fdtab.find_unused_handle ();
+ int res_fd = cygheap->fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
if (fd2p)
{
- *fd2p = fdtab.find_unused_handle (res_fd + 1);
+ *fd2p = cygheap->fdtab.find_unused_handle (res_fd + 1);
if (*fd2p == -1)
goto done;
}
@@ -1763,7 +1758,7 @@ cygwin_rresvport (int *port)
int res = -1;
sigframe thisframe (mainthread);
- int res_fd = fdtab.find_unused_handle ();
+ int res_fd = cygheap->fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
res = rresvport (port);
@@ -1789,12 +1784,12 @@ cygwin_rexec (char **ahost, unsigned short inport, char *locuser,
SOCKET fd2s;
sigframe thisframe (mainthread);
- int res_fd = fdtab.find_unused_handle ();
+ int res_fd = cygheap->fdtab.find_unused_handle ();
if (res_fd == -1)
goto done;
if (fd2p)
{
- *fd2p = fdtab.find_unused_handle (res_fd + 1);
+ *fd2p = cygheap->fdtab.find_unused_handle (res_fd + 1);
if (*fd2p == -1)
goto done;
}
@@ -1826,13 +1821,13 @@ socketpair (int, int type, int, int *sb)
SetResourceLock (LOCK_FD_LIST, WRITE_LOCK|READ_LOCK, "socketpair");
- sb[0] = fdtab.find_unused_handle ();
+ sb[0] = cygheap->fdtab.find_unused_handle ();
if (sb[0] == -1)
{
set_errno (EMFILE);
goto done;
}
- sb[1] = fdtab.find_unused_handle (sb[0] + 1);
+ sb[1] = cygheap->fdtab.find_unused_handle (sb[0] + 1);
if (sb[1] == -1)
{
set_errno (EMFILE);
diff --git a/winsup/cygwin/passwd.cc b/winsup/cygwin/passwd.cc
index 21c3e786d..6164b0930 100644
--- a/winsup/cygwin/passwd.cc
+++ b/winsup/cygwin/passwd.cc
@@ -35,6 +35,7 @@ static int max_lines = 0;
and read in the password file if it isn't set. */
enum pwd_state {
uninitialized = 0,
+ initializing,
emulated,
loaded
};
@@ -120,34 +121,54 @@ add_pwd_line (char *line)
void
read_etc_passwd ()
{
- extern int passwd_sem;
char linebuf[1024];
- ++passwd_sem;
- FILE *f = fopen ("/etc/passwd", "rt");
- --passwd_sem;
+ /* A mutex is ok for speed here - pthreads will use critical sections not mutex's
+ * for non-shared mutexs in the future. Also, this function will at most be called
+ * once from each thread, after that the passwd_state test will succeed
+ */
+ static pthread_mutex_t etc_passwd_mutex = (pthread_mutex_t) PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_lock (&etc_passwd_mutex);
+
+ /* if we got blocked by the mutex, then etc_passwd may have been processed */
+ if (passwd_state != uninitialized)
+ {
+ pthread_mutex_unlock(&etc_passwd_mutex);
+ return;
+ }
- if (f)
+ if (passwd_state != initializing)
{
- while (fgets (linebuf, sizeof (linebuf), f) != NULL)
+ passwd_state = initializing;
+
+ FILE *f = fopen ("/etc/passwd", "rt");
+
+ if (f)
{
- if (strlen (linebuf))
- add_pwd_line (linebuf);
+ while (fgets (linebuf, sizeof (linebuf), f) != NULL)
+ {
+ if (strlen (linebuf))
+ add_pwd_line (linebuf);
+ }
+
+ fclose (f);
+ passwd_state = loaded;
+ }
+ else
+ {
+ debug_printf ("Emulating /etc/passwd");
+ snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", cygheap->user.name (),
+ DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
+ add_pwd_line (linebuf);
+ passwd_state = emulated;
}
- fclose (f);
- passwd_state = loaded;
- }
- else
- {
- debug_printf ("Emulating /etc/passwd");
- snprintf (linebuf, sizeof (linebuf), "%s::%u:%u::%s:/bin/sh", cygheap->user.name (),
- DEFAULT_UID, DEFAULT_GID, getenv ("HOME") ?: "/");
- add_pwd_line (linebuf);
- passwd_state = emulated;
}
+
+ pthread_mutex_unlock (&etc_passwd_mutex);
}
/* Cygwin internal */
+/* If this ever becomes non-reentrant, update all the getpw*_r functions */
static struct passwd *
search_for (uid_t uid, const char *name)
{
@@ -182,25 +203,98 @@ search_for (uid_t uid, const char *name)
extern "C" struct passwd *
getpwuid (uid_t uid)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
return search_for (uid, 0);
}
+extern "C" int
+getpwuid_r (uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
+{
+ *result = NULL;
+
+ if (!pwd || !buffer)
+ return ERANGE;
+
+ if (passwd_state <= initializing)
+ read_etc_passwd ();
+
+ struct passwd *temppw = search_for (uid, 0);
+
+ if (!temppw)
+ return 0;
+
+ /* check needed buffer size. */
+ size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) + strlen (temppw->pw_shell);
+ if (needsize > bufsize)
+ return ERANGE;
+
+ /* make a copy of temppw */
+ *result = pwd;
+ pwd->pw_uid = temppw->pw_uid;
+ pwd->pw_gid = temppw->pw_gid;
+ pwd->pw_name = buffer;
+ pwd->pw_dir = buffer + strlen (temppw->pw_name);
+ pwd->pw_shell = buffer + strlen (temppw->pw_name) + strlen (temppw->pw_dir);
+ strcpy (pwd->pw_name, temppw->pw_name);
+ strcpy (pwd->pw_dir, temppw->pw_dir);
+ strcpy (pwd->pw_shell, temppw->pw_shell);
+ return 0;
+}
+
extern "C" struct passwd *
getpwnam (const char *name)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
return search_for (0, name);
}
+
+/* the max size buffer we can expect to
+ * use is returned via sysconf with _SC_GETPW_R_SIZE_MAX.
+ * This may need updating! - Rob Collins April 2001.
+ */
+extern "C" int
+getpwnam_r (const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
+{
+ *result = NULL;
+
+ if (!pwd || !buffer || !nam)
+ return ERANGE;
+
+ if (passwd_state <= initializing)
+ read_etc_passwd ();
+
+ struct passwd *temppw = search_for (0, nam);
+
+ if (!temppw)
+ return 0;
+
+ /* check needed buffer size. */
+ size_t needsize = strlen (temppw->pw_name) + strlen (temppw->pw_dir) + strlen (temppw->pw_shell);
+ if (needsize > bufsize)
+ return ERANGE;
+
+ /* make a copy of temppw */
+ *result = pwd;
+ pwd->pw_uid = temppw->pw_uid;
+ pwd->pw_gid = temppw->pw_gid;
+ pwd->pw_name = buffer;
+ pwd->pw_dir = buffer + strlen (temppw->pw_name);
+ pwd->pw_shell = buffer + strlen (temppw->pw_name) + strlen (temppw->pw_dir);
+ strcpy (pwd->pw_name, temppw->pw_name);
+ strcpy (pwd->pw_dir, temppw->pw_dir);
+ strcpy (pwd->pw_shell, temppw->pw_shell);
+ return 0;
+}
+
extern "C" struct passwd *
getpwent (void)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
if (pw_pos < curr_lines)
@@ -212,7 +306,7 @@ getpwent (void)
extern "C" struct passwd *
getpwduid (uid_t)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
return NULL;
@@ -221,7 +315,7 @@ getpwduid (uid_t)
extern "C" void
setpwent (void)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
pw_pos = 0;
@@ -230,7 +324,7 @@ setpwent (void)
extern "C" void
endpwent (void)
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
pw_pos = 0;
@@ -239,7 +333,7 @@ endpwent (void)
extern "C" int
setpassent ()
{
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
return 0;
@@ -255,17 +349,17 @@ getpass (const char * prompt)
#endif
struct termios ti, newti;
- if (passwd_state == uninitialized)
+ if (passwd_state <= initializing)
read_etc_passwd ();
- if (fdtab.not_open (0))
+ if (cygheap->fdtab.not_open (0))
{
set_errno (EBADF);
pass[0] = '\0';
}
else
{
- fhandler_base *fhstdin = fdtab[0];
+ fhandler_base *fhstdin = cygheap->fdtab[0];
fhstdin->tcgetattr (&ti);
newti = ti;
newti.c_lflag &= ~ECHO;
diff --git a/winsup/cygwin/path.cc b/winsup/cygwin/path.cc
index fc8eae623..872594b05 100644
--- a/winsup/cygwin/path.cc
+++ b/winsup/cygwin/path.cc
@@ -70,6 +70,7 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
+#include "dtable.h"
#include "cygheap.h"
#include "shared_info.h"
#include "registry.h"
diff --git a/winsup/cygwin/pipe.cc b/winsup/cygwin/pipe.cc
index 4a6e49345..37aaaa856 100644
--- a/winsup/cygwin/pipe.cc
+++ b/winsup/cygwin/pipe.cc
@@ -15,6 +15,7 @@ details. */
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "thread.h"
#include "security.h"
@@ -28,16 +29,16 @@ make_pipe (int fildes[2], unsigned int psize, int mode)
SECURITY_ATTRIBUTES *sa = (mode & O_NOINHERIT) ? &sec_none_nih : &sec_none;
int res = -1;
- if ((fdr = fdtab.find_unused_handle ()) < 0)
+ if ((fdr = cygheap->fdtab.find_unused_handle ()) < 0)
set_errno (ENMFILE);
- else if ((fdw = fdtab.find_unused_handle (fdr + 1)) < 0)
+ else if ((fdw = cygheap->fdtab.find_unused_handle (fdr + 1)) < 0)
set_errno (ENMFILE);
else if (!CreatePipe (&r, &w, sa, psize))
__seterrno ();
else
{
- fhandler_base *fhr = fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
- fhandler_base *fhw = fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
+ fhandler_base *fhr = cygheap->fdtab.build_fhandler (fdr, FH_PIPER, "/dev/piper");
+ fhandler_base *fhw = cygheap->fdtab.build_fhandler (fdw, FH_PIPEW, "/dev/pipew");
int binmode = mode & O_TEXT ? 0 : 1;
fhr->init (r, GENERIC_READ, binmode);
@@ -72,7 +73,7 @@ _pipe (int filedes[2], unsigned int psize, int mode)
int res = make_pipe (filedes, psize, mode);
/* This type of pipe is not interruptible so set the appropriate flag. */
if (!res)
- fdtab[filedes[0]]->set_r_no_interrupt (1);
+ cygheap->fdtab[filedes[0]]->set_r_no_interrupt (1);
return res;
}
@@ -82,7 +83,7 @@ dup (int fd)
int res;
SetResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
- res = dup2 (fd, fdtab.find_unused_handle ());
+ res = dup2 (fd, cygheap->fdtab.find_unused_handle ());
ReleaseResourceLock(LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," dup");
@@ -92,5 +93,5 @@ dup (int fd)
int
dup2 (int oldfd, int newfd)
{
- return fdtab.dup2 (oldfd, newfd);
+ return cygheap->fdtab.dup2 (oldfd, newfd);
}
diff --git a/winsup/cygwin/poll.cc b/winsup/cygwin/poll.cc
index f3c9ef6d7..4a216ad63 100644
--- a/winsup/cygwin/poll.cc
+++ b/winsup/cygwin/poll.cc
@@ -14,6 +14,7 @@
#include <errno.h>
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "cygerrno.h"
#include "sigproc.h"
@@ -49,7 +50,7 @@ poll (struct pollfd *fds, unsigned int nfds, int timeout)
memset (except_fds, 0, fds_size);
for (unsigned int i = 0; i < nfds; ++i)
- if (!fdtab.not_open (fds[i].fd))
+ if (!cygheap->fdtab.not_open (fds[i].fd))
{
FD_SET (fds[i].fd, open_fds);
if (fds[i].events & POLLIN)
@@ -67,7 +68,7 @@ poll (struct pollfd *fds, unsigned int nfds, int timeout)
{
if (!FD_ISSET (fds[i].fd, open_fds))
fds[i].revents = POLLNVAL;
- else if (fdtab.not_open(fds[i].fd))
+ else if (cygheap->fdtab.not_open(fds[i].fd))
fds[i].revents = POLLHUP;
else if (ret < 0)
fds[i].revents = POLLERR;
diff --git a/winsup/cygwin/security.cc b/winsup/cygwin/security.cc
index def5685f6..d780103f8 100644
--- a/winsup/cygwin/security.cc
+++ b/winsup/cygwin/security.cc
@@ -185,7 +185,6 @@ get_world_sid ()
return world_sid;
}
-int passwd_sem = 0;
int group_sem = 0;
static int
@@ -207,10 +206,6 @@ get_id_from_sid (PSID psid, BOOL search_grp, int *type)
if (!search_grp)
{
- if (passwd_sem > 0)
- return 0;
- ++passwd_sem;
-
struct passwd *pw;
while ((pw = getpwent ()) != NULL)
{
@@ -221,7 +216,6 @@ get_id_from_sid (PSID psid, BOOL search_grp, int *type)
}
}
endpwent ();
- --passwd_sem;
if (id >= 0)
{
if (type)
@@ -330,7 +324,7 @@ is_grp_member (uid_t uid, gid_t gid)
extern int getgroups (int, gid_t *, gid_t, const char *);
BOOL grp_member = TRUE;
- if (!group_sem && !passwd_sem)
+ if (!group_sem)
{
struct passwd *pw = getpwuid (uid);
gid_t grps[NGROUPS_MAX];
@@ -1745,13 +1739,13 @@ extern "C"
int
facl (int fd, int cmd, int nentries, aclent_t *aclbufp)
{
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("-1 = facl (%d)", fd);
set_errno (EBADF);
return -1;
}
- const char *path = fdtab[fd]->get_name ();
+ const char *path = cygheap->fdtab[fd]->get_name ();
if (path == NULL)
{
syscall_printf ("-1 = facl (%d) (no name)", fd);
diff --git a/winsup/cygwin/select.cc b/winsup/cygwin/select.cc
index db59e5834..c23073918 100644
--- a/winsup/cygwin/select.cc
+++ b/winsup/cygwin/select.cc
@@ -36,6 +36,7 @@ details. */
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "sync.h"
#include "sigproc.h"
#include "perthread.h"
@@ -92,7 +93,7 @@ fhandler_##what::ready_for_read (int fd, DWORD howlong, int ignra) \
me.fd = fd; \
(void) select_read (&me); \
while (!peek_##what (&me, ignra) && howlong == INFINITE) \
- if (fd >= 0 && fdtab.not_open (fd)) \
+ if (fd >= 0 && cygheap->fdtab.not_open (fd)) \
break; \
else if (WaitForSingleObject (signal_arrived, 10) == WAIT_OBJECT_0) \
break; \
@@ -101,7 +102,7 @@ fhandler_##what::ready_for_read (int fd, DWORD howlong, int ignra) \
#define set_handle_or_return_if_not_open(h, s) \
h = (s)->fh->get_handle (); \
- if (fdtab.not_open ((s)->fd)) \
+ if (cygheap->fdtab.not_open ((s)->fd)) \
{ \
(s)->saw_error = TRUE; \
set_errno (EBADF); \
@@ -211,11 +212,11 @@ select_stuff::test_and_set (int i, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds)
{
select_record *s = NULL;
- if (UNIX_FD_ISSET (i, readfds) && (s = fdtab.select_read (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, readfds) && (s = cygheap->fdtab.select_read (i, s)) == NULL)
return 0; /* error */
- if (UNIX_FD_ISSET (i, writefds) && (s = fdtab.select_write (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, writefds) && (s = cygheap->fdtab.select_write (i, s)) == NULL)
return 0; /* error */
- if (UNIX_FD_ISSET (i, exceptfds) && (s = fdtab.select_except (i, s)) == NULL)
+ if (UNIX_FD_ISSET (i, exceptfds) && (s = cygheap->fdtab.select_except (i, s)) == NULL)
return 0; /* error */
if (s == NULL)
return 1; /* nothing to do */
diff --git a/winsup/cygwin/shared.cc b/winsup/cygwin/shared.cc
index 2a72806b4..1d8cf411b 100644
--- a/winsup/cygwin/shared.cc
+++ b/winsup/cygwin/shared.cc
@@ -17,6 +17,8 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "heap.h"
#include "shared_info.h"
diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 9a8f602e1..58c861f98 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -21,6 +21,8 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "child_info.h"
#include "perthread.h"
diff --git a/winsup/cygwin/spawn.cc b/winsup/cygwin/spawn.cc
index 3fb5abe1b..5ac823c8d 100644
--- a/winsup/cygwin/spawn.cc
+++ b/winsup/cygwin/spawn.cc
@@ -151,7 +151,7 @@ out:
static HANDLE
handle (int n, int direction)
{
- fhandler_base *fh = fdtab[n];
+ fhandler_base *fh = cygheap->fdtab[n];
if (!fh)
return INVALID_HANDLE_VALUE;
@@ -340,8 +340,6 @@ spawn_guts (HANDLE hToken, const char * prog_arg, const char *const *argv,
ciresrv.moreinfo = (cygheap_exec_info *) ccalloc (HEAP_1_EXEC, 1, sizeof (cygheap_exec_info));
ciresrv.moreinfo->old_title = NULL;
- ciresrv.moreinfo->fds = fdtab;
- ciresrv.moreinfo->nfds = fdtab.size;
/* CreateProcess takes one long string that is the command line (sigh).
We need to quote any argument that has whitespace or embedded "'s. */
@@ -563,7 +561,7 @@ skip_arg_parsing:
parent after CreateProcess and before copying the datastructures
to the child. So we have to start the child in suspend state,
unfortunately, to avoid a race condition. */
- if (fdtab.need_fixup_before ())
+ if (cygheap->fdtab.need_fixup_before ())
flags |= CREATE_SUSPENDED;
@@ -690,9 +688,9 @@ skip_arg_parsing:
/* Fixup the parent datastructure if needed and resume the child's
main thread. */
- if (fdtab.need_fixup_before ())
+ if (cygheap->fdtab.need_fixup_before ())
{
- fdtab.fixup_before_exec (pi.dwProcessId);
+ cygheap->fdtab.fixup_before_exec (pi.dwProcessId);
if (mode == _P_OVERLAY)
ResumeThread (pi.hThread);
}
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index 5a9b24c0f..25dc93c16 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -48,17 +48,17 @@ SYSTEM_INFO system_info;
void __stdcall
close_all_files (void)
{
- SetResourceLock (LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
+ SetResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "close_all_files");
fhandler_base *fh;
- for (int i = 0; i < (int) fdtab.size; i++)
- if ((fh = fdtab[i]) != NULL)
+ for (int i = 0; i < (int) cygheap->fdtab.size; i++)
+ if ((fh = cygheap->fdtab[i]) != NULL)
{
fh->close ();
- fdtab.release (i);
+ cygheap->fdtab.release (i);
}
- ReleaseResourceLock (LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
+ ReleaseResourceLock (LOCK_FD_LIST, WRITE_LOCK | READ_LOCK, "close_all_files");
cygwin_shared->delqueue.process_queue ();
}
@@ -237,14 +237,14 @@ _read (int fd, void *ptr, size_t len)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
// set_sig_errno (0);
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
DWORD wait = (fh->get_flags () & (O_NONBLOCK | OLD_O_NDELAY)) ? 0 : INFINITE;
/* Could block, so let user know we at least got here. */
@@ -289,7 +289,7 @@ _write (int fd, const void *ptr, size_t len)
int res = -1;
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto done;
@@ -302,9 +302,10 @@ _write (int fd, const void *ptr, size_t len)
syscall_printf ("write (%d, %p, %d)", fd, ptr, len);
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
res = fh->bg_check (SIGTTOU);
+syscall_printf ("write fh %p, name '%s' bg_check %d, bg_eof %d", fh, fh->get_name(), res, bg_eof);
if (res > bg_eof)
{
myself->process_state |= PID_TTYOU;
@@ -433,15 +434,15 @@ _open (const char *unix_path, int flags, ...)
mode = va_arg (ap, mode_t);
va_end (ap);
- fd = fdtab.find_unused_handle ();
+ fd = cygheap->fdtab.find_unused_handle ();
if (fd < 0)
set_errno (ENMFILE);
- else if ((fh = fdtab.build_fhandler (fd, unix_path, NULL)) == NULL)
+ else if ((fh = cygheap->fdtab.build_fhandler (fd, unix_path, NULL)) == NULL)
res = -1; // errno already set
else if (!fh->open (unix_path, flags, (mode & 0777) & ~cygheap->umask))
{
- fdtab.release (fd);
+ cygheap->fdtab.release (fd);
res = -1;
}
else if ((res = fd) <= 2)
@@ -464,14 +465,14 @@ _lseek (int fd, off_t pos, int dir)
set_errno (EINVAL);
res = -1;
}
- else if (fdtab.not_open (fd))
+ else if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
res = -1;
}
else
{
- res = fdtab[fd]->lseek (pos, dir);
+ res = cygheap->fdtab[fd]->lseek (pos, dir);
}
syscall_printf ("%d = lseek (%d, %d, %d)", res, fd, pos, dir);
@@ -487,7 +488,7 @@ _close (int fd)
syscall_printf ("close (%d)", fd);
MALLOC_CHECK;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
debug_printf ("handle %d not open", fd);
set_errno (EBADF);
@@ -496,8 +497,8 @@ _close (int fd)
else
{
SetResourceLock (LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
- res = fdtab[fd]->close ();
- fdtab.release (fd);
+ res = cygheap->fdtab[fd]->close ();
+ cygheap->fdtab.release (fd);
ReleaseResourceLock (LOCK_FD_LIST,WRITE_LOCK|READ_LOCK," close");
}
@@ -512,13 +513,13 @@ isatty (int fd)
int res;
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("0 = isatty (%d)", fd);
return 0;
}
- res = fdtab[fd]->is_tty ();
+ res = cygheap->fdtab[fd]->is_tty ();
syscall_printf ("%d = isatty (%d)", res, fd);
return res;
}
@@ -755,14 +756,14 @@ extern "C" int
fchown (int fd, uid_t uid, gid_t gid)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("-1 = fchown (%d,...)", fd);
set_errno (EBADF);
return -1;
}
- const char *path = fdtab[fd]->get_name ();
+ const char *path = cygheap->fdtab[fd]->get_name ();
if (path == NULL)
{
@@ -867,14 +868,14 @@ extern "C" int
fchmod (int fd, mode_t mode)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("-1 = fchmod (%d, 0%o)", fd, mode);
set_errno (EBADF);
return -1;
}
- const char *path = fdtab[fd]->get_name ();
+ const char *path = cygheap->fdtab[fd]->get_name ();
if (path == NULL)
{
@@ -924,7 +925,7 @@ _fstat (int fd, struct stat *buf)
int r;
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("-1 = fstat (%d, %p)", fd, buf);
set_errno (EBADF);
@@ -933,7 +934,7 @@ _fstat (int fd, struct stat *buf)
else
{
memset (buf, 0, sizeof (struct stat));
- r = fdtab[fd]->fstat (buf);
+ r = cygheap->fdtab[fd]->fstat (buf);
syscall_printf ("%d = fstat (%d, %x)", r, fd, buf);
}
@@ -945,14 +946,14 @@ extern "C" int
fsync (int fd)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf ("-1 = fsync (%d)", fd);
set_errno (EBADF);
return -1;
}
- HANDLE h = fdtab[fd]->get_handle ();
+ HANDLE h = cygheap->fdtab[fd]->get_handle ();
if (FlushFileBuffers (h) == 0)
{
@@ -1379,7 +1380,7 @@ system (const char *cmdstring)
extern "C" int
setdtablesize (int size)
{
- if (size <= (int)fdtab.size || fdtab.extend (size - fdtab.size))
+ if (size <= (int)cygheap->fdtab.size || cygheap->fdtab.extend (size - cygheap->fdtab.size))
return 0;
return -1;
@@ -1388,7 +1389,7 @@ setdtablesize (int size)
extern "C" int
getdtablesize ()
{
- return fdtab.size;
+ return cygheap->fdtab.size;
}
extern "C" size_t
@@ -1468,11 +1469,11 @@ fpathconf (int fd, int v)
}
case _PC_POSIX_PERMISSIONS:
case _PC_POSIX_SECURITY:
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
set_errno (EBADF);
else
{
- fhandler_base *fh = fdtab[fd];
+ fhandler_base *fh = cygheap->fdtab[fd];
if (fh->get_device () == FH_DISK)
return check_posix_perm (fh->get_win32_name (), v);
set_errno (EINVAL);
@@ -1530,11 +1531,11 @@ pathconf (const char *file, int v)
extern "C" char *
ttyname (int fd)
{
- if (fdtab.not_open (fd) || !fdtab[fd]->is_tty ())
+ if (cygheap->fdtab.not_open (fd) || !cygheap->fdtab[fd]->is_tty ())
{
return 0;
}
- return (char *) (fdtab[fd]->ttyname ());
+ return (char *) (cygheap->fdtab[fd]->ttyname ());
}
extern "C" char *
@@ -1561,13 +1562,13 @@ _cygwin_istext_for_stdio (int fd)
return 0; /* we do it for old apps, due to getc/putc macros */
}
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
syscall_printf (" _cifs: fd not open\n");
return 0;
}
- fhandler_base *p = fdtab[fd];
+ fhandler_base *p = cygheap->fdtab[fd];
if (p->get_device () != FH_DISK)
{
@@ -1609,13 +1610,13 @@ setmode_helper (FILE *f)
extern "C" int
getmode (int fd)
{
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
- return fdtab[fd]->get_flags () & (O_BINARY | O_TEXT);
+ return cygheap->fdtab[fd]->get_flags () & (O_BINARY | O_TEXT);
}
/* Set a file descriptor into text or binary mode, returning the
@@ -1624,7 +1625,7 @@ getmode (int fd)
extern "C" int
setmode (int fd, int mode)
{
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
@@ -1635,7 +1636,7 @@ setmode (int fd, int mode)
return -1;
}
- fhandler_base *p = fdtab[fd];
+ fhandler_base *p = cygheap->fdtab[fd];
/* Note that we have no way to indicate the case that writes are
binary but not reads, or vice-versa. These cases can arise when
@@ -1680,21 +1681,21 @@ ftruncate (int fd, off_t length)
sigframe thisframe (mainthread);
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
}
else
{
- HANDLE h = fdtab[fd]->get_handle ();
+ HANDLE h = cygheap->fdtab[fd]->get_handle ();
off_t prev_loc;
if (h)
{
/* remember curr file pointer location */
- prev_loc = fdtab[fd]->lseek (0, SEEK_CUR);
+ prev_loc = cygheap->fdtab[fd]->lseek (0, SEEK_CUR);
- fdtab[fd]->lseek (length, SEEK_SET);
+ cygheap->fdtab[fd]->lseek (length, SEEK_SET);
if (!SetEndOfFile (h))
{
__seterrno ();
@@ -1703,7 +1704,7 @@ ftruncate (int fd, off_t length)
res = 0;
/* restore original file pointer location */
- fdtab[fd]->lseek (prev_loc, 0);
+ cygheap->fdtab[fd]->lseek (prev_loc, 0);
}
}
syscall_printf ("%d = ftruncate (%d, %d)", res, fd, length);
@@ -1741,13 +1742,13 @@ get_osfhandle (int fd)
{
long res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
}
else
{
- res = (long) fdtab[fd]->get_handle ();
+ res = (long) cygheap->fdtab[fd]->get_handle ();
}
syscall_printf ("%d = get_osfhandle (%d)", res, fd);
@@ -1799,12 +1800,12 @@ extern "C" int
fstatfs (int fd, struct statfs *sfs)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return -1;
}
- fhandler_disk_file *f = (fhandler_disk_file *) fdtab[fd];
+ fhandler_disk_file *f = (fhandler_disk_file *) cygheap->fdtab[fd];
return statfs (f->get_name (), sfs);
}
@@ -1885,12 +1886,12 @@ extern "C" char *
ptsname (int fd)
{
sigframe thisframe (mainthread);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
return 0;
}
- return (char *) (fdtab[fd]->ptsname ());
+ return (char *) (cygheap->fdtab[fd]->ptsname ());
}
/* FIXME: what is this? */
diff --git a/winsup/cygwin/sysconf.cc b/winsup/cygwin/sysconf.cc
index 1a9424d03..0377a9747 100644
--- a/winsup/cygwin/sysconf.cc
+++ b/winsup/cygwin/sysconf.cc
@@ -16,6 +16,7 @@ details. */
#include <ntdef.h>
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "cygerrno.h"
#include "ntdll.h"
@@ -34,7 +35,7 @@ sysconf (int in)
/* FIXME: this returns the current limit which can increase
if and when dtable::find_unused_handle is called. Perhaps
we should return NOFILE or OPEN_MAX instead? */
- return fdtab.size;
+ return cygheap->fdtab.size;
case _SC_PAGESIZE:
return getpagesize ();
case _SC_CLK_TCK:
diff --git a/winsup/cygwin/syslog.cc b/winsup/cygwin/syslog.cc
index 4e6c5b5a2..e728dfeb3 100644
--- a/winsup/cygwin/syslog.cc
+++ b/winsup/cygwin/syslog.cc
@@ -363,7 +363,7 @@ syslog (int priority, const char *message, ...)
interleaved, we must lock the first byte of the file
This works on Win32 even if we created the file above.
*/
- HANDLE fHandle = fdtab[fileno (fp)]->get_handle ();
+ HANDLE fHandle = cygheap->fdtab[fileno (fp)]->get_handle ();
if (LockFile (fHandle, 0, 0, 1, 0) == FALSE)
{
debug_printf ("failed to lock file %s", get_win95_event_log_path());
diff --git a/winsup/cygwin/termios.cc b/winsup/cygwin/termios.cc
index b1fd12aa8..63c483bf0 100644
--- a/winsup/cygwin/termios.cc
+++ b/winsup/cygwin/termios.cc
@@ -17,6 +17,7 @@ details. */
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include <cygwin/version.h>
#include "perprocess.h"
#include <sys/termios.h>
@@ -27,14 +28,14 @@ tcsendbreak (int fd, int duration)
{
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
@@ -57,14 +58,14 @@ tcdrain (int fd)
termios_printf ("tcdrain");
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
@@ -85,14 +86,14 @@ tcflush (int fd, int queue)
{
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
@@ -113,14 +114,14 @@ tcflow (int fd, int action)
{
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
@@ -142,14 +143,14 @@ tcsetattr (int fd, int a, const struct termios *t)
int res = -1;
t = __tonew_termios (t);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
{
set_errno (EBADF);
goto out;
}
fhandler_base *fh;
- fh = fdtab[fd];
+ fh = cygheap->fdtab[fd];
if (!fh->is_tty ())
set_errno (ENOTTY);
@@ -174,13 +175,13 @@ tcgetattr (int fd, struct termios *in_t)
int res = -1;
struct termios *t = __makenew_termios (in_t);
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
set_errno (EBADF);
- else if (!fdtab[fd]->is_tty ())
+ else if (!cygheap->fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
{
- if ((res = fdtab[fd]->tcgetattr (t)) == 0)
+ if ((res = cygheap->fdtab[fd]->tcgetattr (t)) == 0)
(void) __toapp_termios (in_t, t);
}
@@ -200,12 +201,12 @@ tcgetpgrp (int fd)
{
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
set_errno (EBADF);
- else if (!fdtab[fd]->is_tty ())
+ else if (!cygheap->fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
- res = fdtab[fd]->tcgetpgrp ();
+ res = cygheap->fdtab[fd]->tcgetpgrp ();
termios_printf ("%d = tcgetpgrp (%d)", res, fd);
return res;
@@ -217,12 +218,12 @@ tcsetpgrp (int fd, pid_t pgid)
{
int res = -1;
- if (fdtab.not_open (fd))
+ if (cygheap->fdtab.not_open (fd))
set_errno (EBADF);
- else if (!fdtab[fd]->is_tty ())
+ else if (!cygheap->fdtab[fd]->is_tty ())
set_errno (ENOTTY);
else
- res = fdtab[fd]->tcsetpgrp (pgid);
+ res = cygheap->fdtab[fd]->tcsetpgrp (pgid);
termios_printf ("%d = tcsetpgrp (%d, %x)", res, fd, pgid);
return res;
diff --git a/winsup/cygwin/tty.cc b/winsup/cygwin/tty.cc
index b71e32acb..dbadb68f8 100644
--- a/winsup/cygwin/tty.cc
+++ b/winsup/cygwin/tty.cc
@@ -18,6 +18,7 @@ details. */
#include "cygerrno.h"
#include "fhandler.h"
#include "dtable.h"
+#include "cygheap.h"
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
@@ -68,7 +69,7 @@ tty_init (void)
void __stdcall
create_tty_master (int ttynum)
{
- tty_master = (fhandler_tty_master *) fdtab.build_fhandler (-1, FH_TTYM,
+ tty_master = (fhandler_tty_master *) cygheap->fdtab.build_fhandler (-1, FH_TTYM,
"/dev/ttym", ttynum);
if (tty_master->init (ttynum))
api_fatal ("Can't create master tty");
diff --git a/winsup/cygwin/uinfo.cc b/winsup/cygwin/uinfo.cc
index 2a1bdbc0a..6bf5debba 100644
--- a/winsup/cygwin/uinfo.cc
+++ b/winsup/cygwin/uinfo.cc
@@ -20,6 +20,8 @@ details. */
#include "sync.h"
#include "sigproc.h"
#include "pinfo.h"
+#include "fhandler.h"
+#include "dtable.h"
#include "cygheap.h"
#include "registry.h"
#include "security.h"