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.
This commit is contained in:
parent
35f31b6a98
commit
bcde129400
|
@ -1,3 +1,17 @@
|
||||||
|
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>
|
2009-04-24 Jeff johnston <jjohnstn@redhat.com>
|
||||||
|
|
||||||
* configure.in: Add configuration test for long double equals dbl
|
* configure.in: Add configuration test for long double equals dbl
|
||||||
|
|
|
@ -93,9 +93,11 @@ _DEFUN(fgetc, (fp),
|
||||||
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
#if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__)
|
||||||
int result;
|
int result;
|
||||||
CHECK_INIT(_REENT, fp);
|
CHECK_INIT(_REENT, fp);
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
result = __sgetc_r (_REENT, fp);
|
result = __sgetc_r (_REENT, fp);
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return result;
|
return result;
|
||||||
#else
|
#else
|
||||||
return _fgetc_r (_REENT, fp);
|
return _fgetc_r (_REENT, fp);
|
||||||
|
|
|
@ -98,6 +98,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
|
||||||
|
|
||||||
CHECK_INIT(ptr, fp);
|
CHECK_INIT(ptr, fp);
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
#ifdef __SCLE
|
#ifdef __SCLE
|
||||||
if (fp->_flags & __SCLE)
|
if (fp->_flags & __SCLE)
|
||||||
|
@ -113,10 +114,12 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
|
||||||
if (c == EOF && s == buf)
|
if (c == EOF && s == buf)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
*s = 0;
|
*s = 0;
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -135,6 +138,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
|
||||||
if (s == buf)
|
if (s == buf)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -160,6 +164,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
|
||||||
_CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
|
_CAST_VOID memcpy ((_PTR) s, (_PTR) p, len);
|
||||||
s[len] = 0;
|
s[len] = 0;
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return (buf);
|
return (buf);
|
||||||
}
|
}
|
||||||
fp->_r -= len;
|
fp->_r -= len;
|
||||||
|
@ -170,6 +175,7 @@ _DEFUN(_fgets_r, (ptr, buf, n, fp),
|
||||||
while ((n -= len) != 0);
|
while ((n -= len) != 0);
|
||||||
*s = 0;
|
*s = 0;
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -164,10 +164,12 @@ _DEFUN(_fgetwc_r, (ptr, fp),
|
||||||
{
|
{
|
||||||
wint_t r;
|
wint_t r;
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
ORIENT(fp, 1);
|
ORIENT(fp, 1);
|
||||||
r = __fgetwc (ptr, fp);
|
r = __fgetwc (ptr, fp);
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,7 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
|
||||||
const char *src;
|
const char *src;
|
||||||
unsigned char *nl;
|
unsigned char *nl;
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
ORIENT (fp, 1);
|
ORIENT (fp, 1);
|
||||||
|
|
||||||
|
@ -143,10 +144,12 @@ _DEFUN(_fgetws_r, (ptr, ws, n, fp),
|
||||||
goto error;
|
goto error;
|
||||||
*wsp++ = L'\0';
|
*wsp++ = L'\0';
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return ws;
|
return ws;
|
||||||
|
|
||||||
error:
|
error:
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -146,6 +146,7 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
|
||||||
|
|
||||||
CHECK_INIT(ptr, fp);
|
CHECK_INIT(ptr, fp);
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
ORIENT (fp, -1);
|
ORIENT (fp, -1);
|
||||||
if (fp->_r < 0)
|
if (fp->_r < 0)
|
||||||
|
@ -196,10 +197,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
|
||||||
if (fp->_flags & __SCLE)
|
if (fp->_flags & __SCLE)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
|
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return (total - resid) / size;
|
return (total - resid) / size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -221,10 +224,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
|
||||||
if (fp->_flags & __SCLE)
|
if (fp->_flags & __SCLE)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
|
return crlf_r (ptr, fp, buf, total-resid, 1) / size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return (total - resid) / size;
|
return (total - resid) / size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,10 +243,12 @@ _DEFUN(_fread_r, (ptr, buf, size, count, fp),
|
||||||
if (fp->_flags & __SCLE)
|
if (fp->_flags & __SCLE)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return crlf_r(ptr, fp, buf, total, 0) / size;
|
return crlf_r(ptr, fp, buf, total, 0) / size;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -138,6 +138,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
|
|
||||||
CHECK_INIT (ptr, fp);
|
CHECK_INIT (ptr, fp);
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
|
|
||||||
/* If we've been doing some writing, and we're in append mode
|
/* 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; /* ??? */
|
ptr->_errno = ESPIPE; /* ??? */
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,6 +182,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
if (curoff == -1L)
|
if (curoff == -1L)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -205,6 +208,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
default:
|
default:
|
||||||
ptr->_errno = EINVAL;
|
ptr->_errno = EINVAL;
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return (EOF);
|
return (EOF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,6 +267,8 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
if ((long)target != target)
|
if ((long)target != target)
|
||||||
{
|
{
|
||||||
ptr->_errno = EOVERFLOW;
|
ptr->_errno = EOVERFLOW;
|
||||||
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -319,6 +325,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
fp->_flags &= ~__SEOF;
|
fp->_flags &= ~__SEOF;
|
||||||
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -349,6 +356,7 @@ _DEFUN(_fseek_r, (ptr, fp, offset, whence),
|
||||||
}
|
}
|
||||||
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -361,6 +369,7 @@ dumb:
|
||||||
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
|
|| seekfn (ptr, fp->_cookie, offset, whence) == POS_ERR)
|
||||||
{
|
{
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return EOF;
|
return EOF;
|
||||||
}
|
}
|
||||||
/* success: clear EOF indicator and discard ungetc() data */
|
/* success: clear EOF indicator and discard ungetc() data */
|
||||||
|
@ -379,6 +388,7 @@ dumb:
|
||||||
fp->_flags &= ~__SNPT;
|
fp->_flags &= ~__SNPT;
|
||||||
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
memset (&fp->_mbstate, 0, sizeof (_mbstate_t));
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,9 +92,11 @@ _DEFUN(_getc_r, (ptr, fp),
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
CHECK_INIT (ptr, fp);
|
CHECK_INIT (ptr, fp);
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
result = __sgetc_r (ptr, fp);
|
result = __sgetc_r (ptr, fp);
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,9 +108,11 @@ _DEFUN(getc, (fp),
|
||||||
{
|
{
|
||||||
int result;
|
int result;
|
||||||
CHECK_INIT (_REENT, fp);
|
CHECK_INIT (_REENT, fp);
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
result = __sgetc_r (_REENT, fp);
|
result = __sgetc_r (_REENT, fp);
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
|
||||||
|
|
||||||
CHECK_INIT (_REENT, fp);
|
CHECK_INIT (_REENT, fp);
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (fp);
|
_flockfile (fp);
|
||||||
|
|
||||||
numbytes = *n;
|
numbytes = *n;
|
||||||
|
@ -130,6 +131,7 @@ _DEFUN(__getdelim, (bufptr, n, delim, fp),
|
||||||
}
|
}
|
||||||
|
|
||||||
_funlockfile (fp);
|
_funlockfile (fp);
|
||||||
|
__sfp_lock_release ();
|
||||||
|
|
||||||
/* if no input data, return failure */
|
/* if no input data, return failure */
|
||||||
if (ptr == buf)
|
if (ptr == buf)
|
||||||
|
|
|
@ -79,12 +79,14 @@ _DEFUN(_gets_r, (ptr, buf),
|
||||||
register int c;
|
register int c;
|
||||||
register char *s = buf;
|
register char *s = buf;
|
||||||
|
|
||||||
|
__sfp_lock_acquire ();
|
||||||
_flockfile (stdin);
|
_flockfile (stdin);
|
||||||
while ((c = __sgetc_r (ptr, stdin)) != '\n')
|
while ((c = __sgetc_r (ptr, stdin)) != '\n')
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
if (s == buf)
|
if (s == buf)
|
||||||
{
|
{
|
||||||
_funlockfile (stdin);
|
_funlockfile (stdin);
|
||||||
|
__sfp_lock_release ();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -93,6 +95,7 @@ _DEFUN(_gets_r, (ptr, buf),
|
||||||
*s++ = c;
|
*s++ = c;
|
||||||
*s = 0;
|
*s = 0;
|
||||||
_funlockfile (stdin);
|
_funlockfile (stdin);
|
||||||
|
__sfp_lock_release ();
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue