]> sourceware.org Git - newlib-cygwin.git/commitdiff
* cygheap.cc (cfree): Remove malloc debugging probe.
authorChristopher Faylor <me@cgf.cx>
Wed, 3 Oct 2001 03:49:26 +0000 (03:49 +0000)
committerChristopher Faylor <me@cgf.cx>
Wed, 3 Oct 2001 03:49:26 +0000 (03:49 +0000)
* 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.

winsup/cygwin/ChangeLog
winsup/cygwin/cygheap.cc
winsup/cygwin/dlmalloc.c
winsup/cygwin/dtable.cc
winsup/cygwin/dtable.h
winsup/cygwin/environ.cc
winsup/cygwin/exceptions.cc
winsup/cygwin/syscalls.cc

index 28d4971738ec1ba34135bae06d5990361a49deaf..f05a465ca1d08cfcce97dcaf6b160bc58e284c6e 100644 (file)
@@ -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>
 
index a0e00d3c79535cd15030ebde45a67e53670e283e..b3e61ef19d9c7ff7ec8614216069de72fc786d9b 100644 (file)
@@ -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;
index 3435950b415a5d09793756c9534960ca9d2b4beb..de14fcb6ab855f13e4dd40222c982c0b4d6453a9 100644 (file)
  *  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)
index 96ee5a503fe30715ef10a15cabad0f0991ccc45e..be60d11c02fcbed9754061323bcedfeabbd277ae 100644 (file)
@@ -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);
        }
     }
 
index 0a00d91f5e81caff598fb0b15ab1d51a2d578bee..ebf8ab2a92dac45262461e04ea2b5ee1949823c0 100644 (file)
@@ -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");
index c1529e704c3301c5a565266cef8df1af637dd512..e311e4b5648afc4896d356daab359fad70779cd2 100644 (file)
@@ -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;
+             }
          }
       }
 
index 0102371a7edbf41f5bfd1958de856f18ba462e48..e3d3c45f4379c293e8330782d2b2250d952ab725 100644 (file)
@@ -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);
        }
     }
index f4e53db50cba7741937f3dc7af15d7493d115b2a..2459f108a80b002acbb9cfb48460cc95c853efde 100644 (file)
@@ -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);
This page took 0.051164 seconds and 5 git commands to generate.