On Thu, 2 Jun 2016 15:00:26 -0600 Eric Blake <ebl...@redhat.com> wrote:
> On 06/02/2016 02:52 AM, Greg Kurz wrote: > > This patch changes the 9p code to use readdir() again instead of > > readdir_r(), which is deprecated in glibc 2.24. > > > > All the locking was put in place by a previous patch. > > > > Signed-off-by: Greg Kurz <gk...@linux.vnet.ibm.com> > > --- > > > > +++ b/hw/9pfs/codir.c > > @@ -17,8 +17,7 @@ > > #include "qemu/coroutine.h" > > #include "coth.h" > > > > -int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent > > *dent, > > - struct dirent **result) > > +int v9fs_co_readdir(V9fsPDU *pdu, V9fsFidState *fidp, struct dirent **dent) > > { > > int err; > > V9fsState *s = pdu->s; > > @@ -28,11 +27,14 @@ int v9fs_co_readdir_r(V9fsPDU *pdu, V9fsFidState *fidp, > > struct dirent *dent, > > } > > v9fs_co_run_in_worker( > > { > > - errno = 0; > > - err = s->ops->readdir_r(&s->ctx, &fidp->fs, dent, result); > > - if (!*result && errno) { > > + struct dirent *entry; > > + int old_errno = errno; > > + > > + entry = s->ops->readdir(&s->ctx, &fidp->fs); > > + if (!entry && errno != old_errno) { > > err = -errno; > > Not safe. The only safe way to check errno after readdir() is to assign > it to 0 before readdir(). > Yeah, you're right, errno could already be set to one of the values returned by readdir() in case of error... > > } else { > > + *dent = entry; > > err = 0; > > } > > }); > >