httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r..@covalent.net
Subject Re: [?PATCH?] using getpwnam_r in mod_userdir
Date Sat, 11 Nov 2000 17:47:20 GMT
On Sat, 11 Nov 2000, Sascha Schumann wrote:

> > I had a brainstorm this morning.  We are re-inventing the wheel here.  APR
> > has already solved this EXACT problem for readdir and other
> > functions.  Let's just move getpwnam into APR under a new user
> > directory.  That is about as non-portable as you can get right now, so
> > this makes sense for APR anyway.  Then, we just solve this the same way it
> > was solved for readdir.
> 
>     How were those other cases solved?

Basically we do this in the C code

apr_status_t apr_readdir(apr_dir_t *thedir)
{
#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
    && !defined(READDIR_IS_THREAD_SAFE)
    apr_status_t ret;
#endif

#if APR_HAS_THREADS && defined(_POSIX_THREAD_SAFE_FUNCTIONS) \
    && !defined(READDIR_IS_THREAD_SAFE)

    ret = readdir_r(thedir->dirstruct, thedir->entry, &thedir->entry);
    /* Avoid the Linux problem where at end-of-directory thedir->entry
     * is set to NULL, but ret = APR_SUCCESS.
     */
    return (ret == APR_SUCCESS && thedir->entry == NULL) ? APR_ENOENT
: ret;
#else

    thedir->entry = readdir(thedir->dirstruct);
    if (thedir->entry == NULL) {
        /* If NULL was returned, this can NEVER be a success. Can it?! */
        if (errno == APR_SUCCESS) {
            return APR_ENOENT;
        }
        return errno;
    }
    return APR_SUCCESS;
#endif
}

And this in the configure.in:

ac_cv_define_READDIR_IS_THREAD_SAFE=no
if test "$threads" = "1"; then
    echo "APR will use threads"
    AC_CHECK_LIB(c_r, readdir, AC_DEFINE(READDIR_IS_THREAD_SAFE))
else
    echo "APR will be non-threaded"
fi


This can be improved by checking for _POSIX_THREAD_SAFE_FUNCTIONS
correctly, and outputting an error message if we have threads and
_POSIX_THREAD_SAFE_FUNCTIONS but not _r.

Ryan


_______________________________________________________________________________
Ryan Bloom                        	rbb@apache.org
406 29th St.
San Francisco, CA 94131
-------------------------------------------------------------------------------


Mime
View raw message