From owner-freebsd-bugs Wed Mar 3 12:40:19 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id D478D14FA9 for ; Wed, 3 Mar 1999 12:40:16 -0800 (PST) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.2/8.9.2) id MAA82138; Wed, 3 Mar 1999 12:40:01 -0800 (PST) (envelope-from gnats@FreeBSD.org) Date: Wed, 3 Mar 1999 12:40:01 -0800 (PST) Message-Id: <199903032040.MAA82138@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: John Plevyak Subject: Re: kern/8011: libc_r does not have pread() or pwrite() interfaces Reply-To: John Plevyak Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR kern/8011; it has been noted by GNATS. From: John Plevyak 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