summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2001-10-03 03:49:26 +0000
committerChristopher Faylor <me@cgf.cx>2001-10-03 03:49:26 +0000
commitebd645e7e65aa46fc5e95fda0b47590f4331fc17 (patch)
tree79d88a4c0fe3308a8f58d67aa5b588a37b0aeb7b
parentb519ee2a4e53a65756b9e4f6be4c7bb123d21812 (diff)
downloadcygnal-ebd645e7e65aa46fc5e95fda0b47590f4331fc17.tar.gz
cygnal-ebd645e7e65aa46fc5e95fda0b47590f4331fc17.tar.bz2
cygnal-ebd645e7e65aa46fc5e95fda0b47590f4331fc17.zip
* cygheap.cc (cfree): Remove malloc debugging probe.
* dlmalloc.c (errprint): Remove abort() call which causes interesting error message printing to abort prematurely. * environ.cc: Sprinkle MALLOC_CHECKs liberally throughout. (_addenv): Allocate two empty elements at end of environ to (apparently) work around problems with some buggy applications. (winenv): Avoid calling alloca if no forced environment variable is present. * exceptions.cc (open_stackdumpfile): Don't print "Dumping stack trace to..." when running in a cygwin environment (i.e., the parent is a cygwin process). * dtable.cc (dtable::init_std_file_from_handle): Move device type detection code from build_fhandler here since it is only used by this function. (dtable::build_fhandler_from_name): New method. Renamed from dtable::build_fhandler. (dtable::build_fhandler): Use build_fhandler_from_name. (cygwin_attach_handle_to_fd): Ditto. * syscalls.cc (_open): Ditto. (stat_worker): Ditto. * dtable.h (dtable::build_fhandler_from_name): Rename declaration from dtable::build_fhandler.
-rw-r--r--winsup/cygwin/ChangeLog29
-rw-r--r--winsup/cygwin/cygheap.cc1
-rw-r--r--winsup/cygwin/dlmalloc.c24
-rw-r--r--winsup/cygwin/dtable.cc79
-rw-r--r--winsup/cygwin/dtable.h7
-rw-r--r--winsup/cygwin/environ.cc38
-rw-r--r--winsup/cygwin/exceptions.cc5
-rw-r--r--winsup/cygwin/syscalls.cc13
8 files changed, 120 insertions, 76 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 28d497173..f05a465ca 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,6 +1,29 @@
-Tue Oct 2 22:25:23 2001 Robert Collins <rbtcollins@hotmail.com>
-
- * how-fhandlers-work.txt: New file.
+Tue Oct 2 23:49:18 2001 Christopher Faylor <cgf@cygnus.com>
+
+ * cygheap.cc (cfree): Remove malloc debugging probe.
+ * dlmalloc.c (errprint): Remove abort() call which causes interesting
+ error message printing to abort prematurely.
+ * environ.cc: Sprinkle MALLOC_CHECKs liberally throughout.
+ (_addenv): Allocate two empty elements at end of environ to
+ (apparently) work around problems with some buggy applications.
+ (winenv): Avoid calling alloca if no forced environment variable is
+ present.
+
+ * exceptions.cc (open_stackdumpfile): Don't print "Dumping stack trace
+ to..." when running in a cygwin environment (i.e., the parent is a
+ cygwin process).
+
+ * dtable.cc (dtable::init_std_file_from_handle): Move device type
+ detection code from build_fhandler here since it is only used by this
+ function.
+ (dtable::build_fhandler_from_name): New method. Renamed from
+ dtable::build_fhandler.
+ (dtable::build_fhandler): Use build_fhandler_from_name.
+ (cygwin_attach_handle_to_fd): Ditto.
+ * syscalls.cc (_open): Ditto.
+ (stat_worker): Ditto.
+ * dtable.h (dtable::build_fhandler_from_name): Rename declaration from
+ dtable::build_fhandler.
Mon Oct 1 16:52:23 2001 Christopher Faylor <cgf@cygnus.com>
diff --git a/winsup/cygwin/cygheap.cc b/winsup/cygwin/cygheap.cc
index a0e00d3c7..b3e61ef19 100644
--- a/winsup/cygwin/cygheap.cc
+++ b/winsup/cygwin/cygheap.cc
@@ -322,7 +322,6 @@ crealloc (void *s, DWORD n)
extern "C" void __stdcall
cfree (void *s)
{
- MALLOC_CHECK;
assert (!inheap (s));
(void) _cfree (tocygheap (s));
MALLOC_CHECK;
diff --git a/winsup/cygwin/dlmalloc.c b/winsup/cygwin/dlmalloc.c
index 3435950b4..de14fcb6a 100644
--- a/winsup/cygwin/dlmalloc.c
+++ b/winsup/cygwin/dlmalloc.c
@@ -28,6 +28,29 @@
* malloc_usable_size(P) is equivalent to realloc(P, malloc_usable_size(P))
*
* $Log$
+ * Revision 1.5 2001/10/03 03:49:25 cgf
+ * * cygheap.cc (cfree): Remove malloc debugging probe.
+ * * dlmalloc.c (errprint): Remove abort() call which causes interesting error
+ * message printing to abort prematurely.
+ * * environ.cc: Sprinkle MALLOC_CHECKs liberally throughout.
+ * (_addenv): Allocate two empty elements at end of environ to
+ * (apparently) work around problems with some buggy applications.
+ * (winenv): Avoid calling alloca if no forced environment variable is present.
+ *
+ * * exceptions.cc (open_stackdumpfile): Don't print "Dumping stack trace to..."
+ * when running in a cygwin environment (i.e., the parent is a cygwin process).
+ *
+ * * dtable.cc (dtable::init_std_file_from_handle): Move device type detection
+ * code from build_fhandler here since it is only used by this function.
+ * (dtable::build_fhandler_from_name): New method. Renamed from
+ * dtable::build_fhandler.
+ * (dtable::build_fhandler): Use build_fhandler_from_name.
+ * (cygwin_attach_handle_to_fd): Ditto.
+ * * syscalls.cc (_open): Ditto.
+ * (stat_worker): Ditto.
+ * * dtable.h (dtable::build_fhandler_from_name): Rename declaration from
+ * dtable::build_fhandler.
+ *
* Revision 1.4 2001/09/07 21:32:04 cgf
* * cygheap.h (init_cygheap): Move heap pointers here.
* * include/sys/cygwin.h (perprocess): Remove heap pointers.
@@ -1843,7 +1866,6 @@ static void errprint(const char *file, int line, const char *err)
write(2, err, strlen(err));
write(2, "\n", 1);
recurs--;
- abort ();
}
static void malloc_err(const char *err, mchunkptr p)
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 96ee5a503..be60d11c0 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -168,22 +168,39 @@ dtable::release (int fd)
}
}
+extern "C"
+int
+cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
+ DWORD myaccess)
+{
+ if (fd == -1)
+ fd = cygheap->fdtab.find_unused_handle ();
+ path_conv pc;
+ fhandler_base *res = cygheap->fdtab.build_fhandler_from_name (fd, name, handle,
+ pc);
+ res->init (handle, myaccess, bin);
+ return fd;
+}
+
void
-dtable::init_std_file_from_handle (int fd, HANDLE handle,
- DWORD myaccess)
+dtable::init_std_file_from_handle (int fd, HANDLE handle, DWORD myaccess)
{
int bin;
- const char *name = NULL;
+ const char *name;
+ CONSOLE_SCREEN_BUFFER_INFO buf;
+ struct sockaddr sa;
+ int sal = sizeof (sa);
+ DCB dcb;
+
+ first_fd_for_open = 0;
if (__fmode)
bin = __fmode;
else
bin = binmode ?: 0;
- first_fd_for_open = 0;
/* See if we can consoleify it - if it is a console,
don't open it in binary. That will screw up our crlfs*/
- CONSOLE_SCREEN_BUFFER_INFO buf;
if (GetConsoleScreenBufferInfo (handle, &buf))
{
if (ISSTATE (myself, PID_USETTY))
@@ -192,7 +209,7 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle,
name = "/dev/conout";
bin = 0;
}
- else if (FlushConsoleInputBuffer (handle))
+ else if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &buf))
{
if (ISSTATE (myself, PID_USETTY))
name = "/dev/tty";
@@ -204,56 +221,28 @@ dtable::init_std_file_from_handle (int fd, HANDLE handle,
{
if (fd == 0)
name = "/dev/piper";
- else if (fd == 1 || fd == 2)
+ else
name = "/dev/pipew";
if (bin == 0)
bin = O_BINARY;
}
+ else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0)
+ name = "/dev/socket";
+ else if (GetCommState (handle, &dcb))
+ name = "/dev/ttyS0"; // FIXME - determine correct device
+ else
+ name = "unknown disk file";
path_conv pc;
- build_fhandler (fd, name, handle, pc)->init (handle, myaccess, bin);
+ build_fhandler_from_name (fd, name, handle, pc)->init (handle, myaccess, bin);
set_std_handle (fd);
paranoid_printf ("fd %d, handle %p", fd, handle);
}
-extern "C"
-int
-cygwin_attach_handle_to_fd (char *name, int fd, HANDLE handle, mode_t bin,
- DWORD myaccess)
-{
- if (fd == -1)
- fd = cygheap->fdtab.find_unused_handle ();
- path_conv pc;
- fhandler_base *res = cygheap->fdtab.build_fhandler (fd, name, handle, pc);
- res->init (handle, myaccess, bin);
- return fd;
-}
-
fhandler_base *
-dtable::build_fhandler (int fd, const char *name, HANDLE handle, path_conv& pc,
- unsigned opt, suffix_info *si)
+dtable::build_fhandler_from_name (int fd, const char *name, HANDLE handle,
+ path_conv& pc, unsigned opt, suffix_info *si)
{
- if (!name && handle)
- {
- struct sockaddr sa;
- int sal = sizeof (sa);
- CONSOLE_SCREEN_BUFFER_INFO cinfo;
- DCB dcb;
-
- if (GetNumberOfConsoleInputEvents (handle, (DWORD *) &cinfo))
- name = "/dev/conin";
- else if (GetConsoleScreenBufferInfo (handle, &cinfo))
- name = "/dev/conout";
- else if (wsock_started && getpeername ((SOCKET) handle, &sa, &sal) == 0)
- name = "/dev/socket";
- else if (GetFileType (handle) == FILE_TYPE_PIPE)
- name = "/dev/pipe";
- else if (GetCommState (handle, &dcb))
- name = "/dev/ttyS0"; // FIXME - determine correct device
- else
- name = "some disk file";
- }
-
pc.check (name, opt | PC_NULLEMPTY, si);
if (pc.error)
{
@@ -338,7 +327,7 @@ dtable::build_fhandler (int fd, DWORD dev, const char *name, int unit)
{
/* FIXME - this could recurse forever */
path_conv pc;
- return build_fhandler (fd, name, NULL, pc);
+ return build_fhandler_from_name (fd, name, NULL, pc);
}
}
diff --git a/winsup/cygwin/dtable.h b/winsup/cygwin/dtable.h
index 0a00d91f5..ebf8ab2a9 100644
--- a/winsup/cygwin/dtable.h
+++ b/winsup/cygwin/dtable.h
@@ -50,9 +50,10 @@ public:
void fixup_after_fork (HANDLE);
fhandler_base *build_fhandler (int fd, DWORD dev, const char *name,
int unit = -1);
- fhandler_base *build_fhandler (int fd, const char *name, HANDLE h,
- path_conv& pc, unsigned opts = PC_SYM_FOLLOW,
- suffix_info *si = NULL);
+ fhandler_base *build_fhandler_from_name (int fd, const char *name, HANDLE h,
+ path_conv& pc,
+ unsigned opts = PC_SYM_FOLLOW,
+ suffix_info *si = NULL);
inline int not_open (int fd)
{
SetResourceLock (LOCK_FD_LIST, READ_LOCK, "not_open");
diff --git a/winsup/cygwin/environ.cc b/winsup/cygwin/environ.cc
index c1529e704..e311e4b56 100644
--- a/winsup/cygwin/environ.cc
+++ b/winsup/cygwin/environ.cc
@@ -76,6 +76,7 @@ static unsigned char conv_start_chars[256] = {0};
void
win_env::add_cache (const char *in_posix, const char *in_native)
{
+ MALLOC_CHECK;
posix = (char *) realloc (posix, strlen (in_posix) + 1);
strcpy (posix, in_posix);
if (in_native)
@@ -90,6 +91,7 @@ win_env::add_cache (const char *in_posix, const char *in_native)
(void) strcpy (native, name);
towin32 (in_posix, native + namelen);
}
+ MALLOC_CHECK;
debug_printf ("posix %s", posix);
debug_printf ("native %s", native);
}
@@ -145,6 +147,7 @@ posify (char **here, const char *value)
debug_printf ("env var converted to %s", outenv);
*here = outenv;
free (src);
+ MALLOC_CHECK;
}
/*
@@ -177,6 +180,7 @@ my_findenv (const char *name, int *offset)
*offset = p - cur_environ ();
return (char *) (++c);
}
+ MALLOC_CHECK;
return NULL;
}
@@ -231,12 +235,12 @@ _addenv (const char *name, const char *value, int overwrite)
else
{ /* Create new slot. */
int sz = envsize (cur_environ ());
- int allocsz = sz + sizeof (char *);
+ int allocsz = sz + (2 * sizeof (char *));
offset = (sz - 1) / sizeof (char *);
/* Allocate space for additional element plus terminating NULL. */
- if (__cygwin_environ == lastenviron)
+ if (cur_environ () == lastenviron)
lastenviron = __cygwin_environ = (char **) realloc (cur_environ (),
allocsz);
else if ((lastenviron = (char **) malloc (allocsz)) != NULL)
@@ -248,7 +252,7 @@ _addenv (const char *name, const char *value, int overwrite)
#ifdef DEBUGGING
try_to_debug ();
#endif
- return -1; /* Oops. No more memory. */
+ return -1; /* Oops. No more memory. */
}
__cygwin_environ[offset + 1] = NULL; /* NULL terminate. */
@@ -282,6 +286,7 @@ _addenv (const char *name, const char *value, int overwrite)
if ((spenv = getwinenv (envhere)))
spenv->add_cache (value);
+ MALLOC_CHECK;
return 0;
}
@@ -612,13 +617,11 @@ parse_options (char *buf)
static void __stdcall
regopt (const char *name)
{
- MALLOC_CHECK;
/* FIXME: should not be under mount */
reg_key r (KEY_READ, CYGWIN_INFO_PROGRAM_OPTIONS_NAME, NULL);
char buf[MAX_PATH];
char lname[strlen(name) + 1];
strlwr (strcpy (lname, name));
- MALLOC_CHECK;
if (r.get_string (lname, buf, sizeof (buf) - 1, "") == ERROR_SUCCESS)
parse_options (buf);
else
@@ -810,18 +813,21 @@ winenv (const char * const *envp, int keep_posix)
for (int i = 0; forced_winenv_vars[i]; i++)
if (!saw_forced_winenv[i])
{
- int namelen = strlen (forced_winenv_vars[i]) + 1;
- int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0) + 1;
- p = (char *) alloca (namelen + vallen);
- strcpy (p, forced_winenv_vars[i]);
- strcat (p, "=");
- if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen,
- vallen + 1))
- debug_printf ("warning: %s not present in environment", *srcp);
- else
+ int vallen = GetEnvironmentVariable (forced_winenv_vars[i], dum, 0);
+ if (vallen > 0)
{
- *dstp++ = p;
- tl += strlen (p) + 1;
+ int namelen = strlen (forced_winenv_vars[i]) + 1;
+ p = (char *) alloca (namelen + ++vallen);
+ strcpy (p, forced_winenv_vars[i]);
+ strcat (p, "=");
+ if (!GetEnvironmentVariable (forced_winenv_vars[i], p + namelen,
+ vallen))
+ debug_printf ("warning: %s not present in environment", *srcp);
+ else
+ {
+ *dstp++ = p;
+ tl += strlen (p) + 1;
+ }
}
}
diff --git a/winsup/cygwin/exceptions.cc b/winsup/cygwin/exceptions.cc
index 0102371a7..e3d3c45f4 100644
--- a/winsup/cygwin/exceptions.cc
+++ b/winsup/cygwin/exceptions.cc
@@ -170,7 +170,10 @@ open_stackdumpfile ()
CREATE_ALWAYS, 0, 0);
if (h != INVALID_HANDLE_VALUE)
{
- system_printf ("Dumping stack trace to %s", corefile);
+ if (!myself->ppid_handle)
+ system_printf ("Dumping stack trace to %s", corefile);
+ else
+ debug_printf ("Dumping stack trace to %s", corefile);
SetStdHandle (STD_ERROR_HANDLE, h);
}
}
diff --git a/winsup/cygwin/syscalls.cc b/winsup/cygwin/syscalls.cc
index f4e53db50..2459f108a 100644
--- a/winsup/cygwin/syscalls.cc
+++ b/winsup/cygwin/syscalls.cc
@@ -377,7 +377,6 @@ done:
else
syscall_printf ("%d = write (%d, %p, %d)", res, fd, ptr, len);
- MALLOC_CHECK;
return (ssize_t)res;
}
@@ -499,7 +498,8 @@ _open (const char *unix_path, int flags, ...)
else
{
path_conv pc;
- if (!(fh = cygheap->fdtab.build_fhandler (fd, unix_path, NULL, pc)))
+ if (!(fh = cygheap->fdtab.build_fhandler_from_name (fd, unix_path,
+ NULL, pc)))
res = -1; // errno already set
else if (!fh->open (pc, flags, (mode & 07777) & ~cygheap->umask))
{
@@ -1087,10 +1087,11 @@ stat_worker (const char *caller, const char *name, struct stat *buf,
if (check_null_invalid_struct_errno (buf))
goto done;
- fh = cygheap->fdtab.build_fhandler (-1, name, NULL, real_path,
- (nofollow ? PC_SYM_NOFOLLOW : PC_SYM_FOLLOW)
- | PC_FULL, stat_suffixes);
-
+ fh = cygheap->fdtab.build_fhandler_from_name (-1, name, NULL, real_path,
+ (nofollow ?
+ PC_SYM_NOFOLLOW
+ : PC_SYM_FOLLOW)
+ | PC_FULL, stat_suffixes);
if (real_path.error)
{
set_errno (real_path.error);