OSDN Git Service

2009-04-24 Jeff johnston <jjohnstn@redhat.com>
authorjjohnstn <jjohnstn>
Fri, 24 Apr 2009 22:52:51 +0000 (22:52 +0000)
committerjjohnstn <jjohnstn>
Fri, 24 Apr 2009 22:52:51 +0000 (22:52 +0000)
        * libc/stdio/fgetc.c: Make sure sfp lock is acquired before the
        file lock and released before the file lock to avoid a deadlock
        scenario.
        * libc/stdio/fgets.c: Ditto.
        * libc/stdio/fgetwc.c: Ditto.
        * libc/stdio/fgetws.c: Ditto.
        * libc/stdio/fread.c: Ditto.
        * libc/stdio/fseek.c: Ditto.
        * libc/stdio/getc.c: Ditto.
        * libc/stdio/getdelim.c: Ditto.
        * libc/stdio/gets.c: Ditto.

newlib/ChangeLog
newlib/libc/stdio/fgetc.c
newlib/libc/stdio/fgets.c
newlib/libc/stdio/fgetwc.c
newlib/libc/stdio/fgetws.c
newlib/libc/stdio/fread.c
newlib/libc/stdio/fseek.c
newlib/libc/stdio/getc.c
newlib/libc/stdio/getdelim.c
newlib/libc/stdio/gets.c

index c7f3110..64a6a1e 100644 (file)
@@ -1,5 +1,19 @@
 2009-04-24  Jeff johnston  <jjohnstn@redhat.com>
 
+       * libc/stdio/fgetc.c: Make sure sfp lock is acquired before the
+       file lock and released before the file lock to avoid a deadlock
+       scenario.
+       * libc/stdio/fgets.c: Ditto.
+       * libc/stdio/fgetwc.c: Ditto.
+       * libc/stdio/fgetws.c: Ditto.
+       * libc/stdio/fread.c: Ditto.
+       * libc/stdio/fseek.c: Ditto.
+       * libc/stdio/getc.c: Ditto.
+       * libc/stdio/getdelim.c: Ditto.
+       * libc/stdio/gets.c: Ditto.
+
+2009-04-24  Jeff johnston  <jjohnstn@redhat.com>
+
        * configure.in: Add configuration test for long double equals dbl
        and set flag _LDBL_EQ_DBL if true.
        * configure: Regenerated.
index e275cfe..9837a2e 100644 (file)
@@ -93,9 +93,11 @@ _DEFUN(fgetc, (fp),
 #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
   int result;
   CHECK_INIT(_REENT, fp);
+  __sfp_lock_acquire ();
   _flockfile (fp);
   result = __sgetc_r (_REENT, fp);
   _funlockfile (fp);
+  __sfp_lock_release ();
   return result;
 #else
   return _fgetc_r (_REENT, fp);
index 7f02e3f..21bfdd4 100644 (file)
@@ -98,6 +98,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
 
   CHECK_INIT(ptr, fp);
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
 #ifdef __SCLE
   if (fp->_flags & __SCLE)
@@ -113,10 +114,12 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
       if (c == EOF && s == buf)
         {
           _funlockfile (fp);
+         __sfp_lock_release ();
           return NULL;
         }
       *s = 0;
       _funlockfile (fp);
+      __sfp_lock_release ();
       return buf;
     }
 #endif
@@ -135,6 +138,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
              if (s == buf)
                 {
                   _funlockfile (fp);
+                 __sfp_lock_release ();
                   return 0;
                 }
              break;
@@ -160,6 +164,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
          _CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
          s[len] = 0;
           _funlockfile (fp);
+         __sfp_lock_release ();
          return (buf);
        }
       fp->_r -= len;
@@ -170,6 +175,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
   while ((n -= len) != 0);
   *s = 0;
   _funlockfile (fp);
+  __sfp_lock_release ();
   return buf;
 }
 
index 38a79bc..f4c81dd 100644 (file)
@@ -164,10 +164,12 @@ _DEFUN(_fgetwc_r, (ptr, fp),
 {
   wint_t r;
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
   ORIENT(fp, 1);
   r = __fgetwc (ptr, fp);
   _funlockfile (fp);
+  __sfp_lock_release ();
   return r;
 }
 
index 2784f15..3dbae06 100644 (file)
@@ -93,6 +93,7 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
   const char *src;
   unsigned char *nl;
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
   ORIENT (fp, 1);
 
@@ -143,10 +144,12 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
     goto error;
   *wsp++ = L'\0';
   _funlockfile (fp);
+  __sfp_lock_release ();
   return ws;
 
 error:
   _funlockfile (fp);
+  __sfp_lock_release ();
   return NULL;
 }
 
index a39e9d8..dda2044 100644 (file)
@@ -146,6 +146,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
 
   CHECK_INIT(ptr, fp);
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
   ORIENT (fp, -1);
   if (fp->_r < 0)
@@ -196,10 +197,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
               if (fp->_flags & __SCLE)
                {
                  _funlockfile (fp);
+                 __sfp_lock_release ();
                  return crlf_r (ptr, fp, buf, total-resid, 1) / size;
                }
 #endif
              _funlockfile (fp);
+             __sfp_lock_release ();
              return (total - resid) / size;
            }
        }
@@ -221,10 +224,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
              if (fp->_flags & __SCLE)
                {
                  _funlockfile (fp);
+                 __sfp_lock_release ();
                  return crlf_r (ptr, fp, buf, total-resid, 1) / size;
                }
 #endif
              _funlockfile (fp);
+             __sfp_lock_release ();
              return (total - resid) / size;
            }
        }
@@ -238,10 +243,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
   if (fp->_flags & __SCLE)
     {
       _funlockfile (fp);
+      __sfp_lock_release ();
       return crlf_r(ptr, fp, buf, total, 0) / size;
     }
 #endif
   _funlockfile (fp);
+  __sfp_lock_release ();
   return count;
 }
 
index 4d5fda4..526ae4c 100644 (file)
@@ -138,6 +138,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
 
   CHECK_INIT (ptr, fp);
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
 
   /* If we've been doing some writing, and we're in append mode
@@ -155,6 +156,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
     {
       ptr->_errno = ESPIPE;    /* ??? */
       _funlockfile (fp);
+      __sfp_lock_release ();
       return EOF;
     }
 
@@ -180,6 +182,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
          if (curoff == -1L)
            {
              _funlockfile (fp);
+             __sfp_lock_release ();
              return EOF;
            }
        }
@@ -205,6 +208,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
     default:
       ptr->_errno = EINVAL;
       _funlockfile (fp);
+      __sfp_lock_release ();
       return (EOF);
     }
 
@@ -263,6 +267,8 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
   if ((long)target != target)
     {
       ptr->_errno = EOVERFLOW;
+      _funlockfile (fp);
+      __sfp_lock_release ();
       return EOF;
     }
 
@@ -319,6 +325,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
       fp->_flags &= ~__SEOF;
       memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
       _funlockfile (fp);
+      __sfp_lock_release ();
       return 0;
     }
 
@@ -349,6 +356,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
     }
   memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
   _funlockfile (fp);
+  __sfp_lock_release ();
   return 0;
 
   /*
@@ -361,6 +369,7 @@ dumb:
       || seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
     {
       _funlockfile (fp);
+      __sfp_lock_release ();
       return EOF;
     }
   /* success: clear EOF indicator and discard ungetc() data */
@@ -379,6 +388,7 @@ dumb:
   fp->_flags &= ~__SNPT;
   memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
   _funlockfile (fp);
+  __sfp_lock_release ();
   return 0;
 }
 
index 5b1fa88..544ac73 100644 (file)
@@ -92,9 +92,11 @@ _DEFUN(_getc_r, (ptr, fp),
 {
   int result;
   CHECK_INIT (ptr, fp);
+  __sfp_lock_acquire ();
   _flockfile (fp);
   result = __sgetc_r (ptr, fp);
   _funlockfile (fp);
+  __sfp_lock_release ();
   return result;
 }
 
@@ -106,9 +108,11 @@ _DEFUN(getc, (fp),
 {
   int result;
   CHECK_INIT (_REENT, fp);
+  __sfp_lock_acquire ();
   _flockfile (fp);
   result = __sgetc_r (_REENT, fp);
   _funlockfile (fp);
+  __sfp_lock_release ();
   return result;
 }
 
index 23fc502..41460ab 100644 (file)
@@ -81,6 +81,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
 
   CHECK_INIT (_REENT, fp);
 
+  __sfp_lock_acquire ();
   _flockfile (fp);
 
   numbytes = *n;
@@ -130,6 +131,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
     }
 
   _funlockfile (fp);
+  __sfp_lock_release ();
 
   /* if no input data, return failure */
   if (ptr == buf)
index 17d1443..daa42e9 100644 (file)
@@ -79,12 +79,14 @@ _DEFUN(_gets_r, (ptr, buf),
   register int c;
   register char *s = buf;
 
+  __sfp_lock_acquire ();
   _flockfile (stdin);
   while ((c = __sgetc_r (ptr, stdin)) != '\n')
     if (c == EOF)
       if (s == buf)
        {
          _funlockfile (stdin);
+         __sfp_lock_release ();
          return NULL;
        }
       else
@@ -93,6 +95,7 @@ _DEFUN(_gets_r, (ptr, buf),
       *s++ = c;
   *s = 0;
   _funlockfile (stdin);
+  __sfp_lock_release ();
   return buf;
 }