Re: [libvirt] PATCH: 19/25: Remove use of non-threadsafe POSIX apis

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Jan 16, 2009 at 12:25:02PM +0000, Daniel P. Berrange wrote:
> On Fri, Jan 16, 2009 at 12:21:59PM +0000, Richard W.M. Jones wrote:
> > On Tue, Jan 13, 2009 at 05:46:37PM +0000, Daniel P. Berrange wrote:
> > > +        char buf[1024];
> > 
> > sysconf (_SC_GETPW_R_SIZE_MAX)?
> > 
> > Looking at glibc's implementation of getpwuid (which uses getpwuid_r),
> > I see that glibc dynamically reallocates the buffer as necessary to
> > the correct size for the return value.  The logic of this is fairly
> > simple so maybe we should do the same?
> > 
> > From glibc:
> > 
> >   buffer = malloc (/*some_initial_size*/);
> > 
> >   while (buffer != NULL
> >          && (getpwuid_r (const char *name, &resbuf, buffer,
> >                          buffer_size, &result)
> >              == ERANGE))
> >     {
> >       char *new_buf;
> >       buffer_size *= 2;
> >       new_buf = (char *) realloc (buffer, buffer_size);
> >       if (new_buf == NULL)
> >         {
> >           free (buffer);
> >           errno = ENOMEM;
> >         }
> >       buffer = new_buf;
> >     }
> > 
> > 
> > Anyhow, +1 but I'd be happier if these functions were centralized in
> > somewhere like src/utils.c.
> 
> That's a good idea - in all the cases where we currently use getpwuid
> all we actually want is the home directory path. So we could add a
> simple func:
> 
>    char *virUserHomeDirectory(uid_t uid);
> 
> and hide all the horrific code in there.

  yes +1, patch looks sane to me but that would be an improvement !

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel@xxxxxxxxxxxx  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/

--
Libvir-list mailing list
Libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list

[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]