Date: Wed, 3 Mar 1999 12:40:01 -0800 (PST) From: John Plevyak <jplevyak@inktomi.com> To: freebsd-bugs@FreeBSD.org Subject: Re: kern/8011: libc_r does not have pread() or pwrite() interfaces Message-ID: <199903032040.MAA82138@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/8011; it has been noted by GNATS.
From: John Plevyak <jplevyak@inktomi.com>
To: freebsd-gnats-submit@freebsd.org, info@highwind.com
Cc:
Subject: Re: kern/8011: libc_r does not have pread() or pwrite() interfaces
Date: Wed, 03 Mar 1999 20:44:16 +0000
The pread/pwrite patch is flawed as it sets fp->f_offset which can cause
problems
in multithreaded programs.
Here is a patch for the patch:
*** sys_generic.c.save Wed Mar 3 12:23:55 1999
--- sys_generic.c Wed Mar 3 12:23:58 1999
***************
*** 153,159 ****
struct uio auio; struct iovec aiov;
long cnt, error = 0;
- off_t curoff;
#ifdef KTRACE
struct iovec ktriov;
#endif
--- 153,158 ----
***************
*** 168,174 ****
aiov.iov_len = uap->nbyte;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
! auio.uio_offset = -1;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
--- 167,173 ----
aiov.iov_len = uap->nbyte;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
! auio.uio_offset = uap->offse;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
return (EINVAL);
auio.uio_resid = uap->nbyte;
***************
*** 183,196 ****
ktriov = aiov; #endif
cnt = uap->nbyte;
- curoff = fp->f_offset;
- fp->f_offset = uap->offset;
if ((error = (*fp->f_ops->fo_read)(fp, &auio, fp->f_cred)))
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
error = 0;
cnt -= auio.uio_resid;
- fp->f_offset = curoff;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p->p_tracep, uap->fd, UIO_READ, &ktriov, cnt,
error);
--- 182,192 ----
***************
*** 373,379 ****
struct uio auio;
struct iovec aiov;
long cnt, error = 0;
- off_t curoff;
#ifdef KTRACE
struct iovec ktriov;
#endif
--- 369,374 ----
#endif
--- 369,374 ----
***************
*** 388,394 ****
aiov.iov_len = uap->nbyte; auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
! auio.uio_offset = -1;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
--- 383,389 ----
aiov.iov_len = uap->nbyte;
auio.uio_iov = &aiov;
auio.uio_iovcnt = 1;
! auio.uio_offset = uap->offset;
if (uap->nbyte > INT_MAX)
return (EINVAL);
auio.uio_resid = uap->nbyte;
***************
*** 403,410 ****
ktriov = aiov;
#endif
cnt = uap->nbyte;
- curoff = fp->f_offset;
- fp->f_offset = uap->offset;
if ((error = (*fp->f_ops->fo_write)(fp, &auio, fp->f_cred))) {
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
if (auio.uio_resid != cnt && (error == ERESTART ||
error == EINTR || error == EWOULDBLOCK))
--- 398,403 ----
***************
*** 413,419 **** psignal(p, SIGPIPE);
}
cnt -= auio.uio_resid;
- fp->f_offset = curoff;
#ifdef KTRACE
if (KTRPOINT(p, KTR_GENIO) && error == 0)
ktrgenio(p->p_tracep, uap->fd, UIO_WRITE,
--- 406,411 ----
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199903032040.MAA82138>
