You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Branko Čibej <br...@xbc.nu> on 2001/07/11 00:28:26 UTC

apr_dir_read failing on sparc-sun-solaris2.6

Lately I've been trying to find out why Subversion is failing on Solaris 
2.6 with an EINVAL error from APR. I tracked it down to a possible bug 
in Solaris' readdir_r implementation. The following program, which  does 
more or less the same thing as APR, illustrates the problem:

----------------------------------------
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <sys/types.h>
#include <dirent.h>

struct {
  struct dirent entry;
  char buffer[4096];
} entry;

int main (void)
{
  DIR* dir;
  struct dirent* result;
  dir = opendir(".");
  if (dir == NULL)
  {
    fprintf(stderr, "Can't open .: %s", strerror(errno));
    exit(1);
  }

  for (;;)
  {
#ifdef _POSIX_PTHREAD_SEMANTICS
    int err = readdir_r(dir, &entry.entry, &result);
    if (result != &entry.entry)
    {
      fprintf(stderr, "Can't read .: %s\n", strerror(err));
      exit(err != 0);
    }
#else
    result = readdir_r(dir, &entry.entry);
    if (result != &entry.entry)
    {
      fprintf(stderr, "Can't read .: %s\n", strerror(errno));
      exit(errno != 0);
    }
#endif

    printf("./%s\n", entry.entry.d_name);
  }
  closedir(dir);
  return 0;
}
----------------------------------------


When compiled with

    cc -D_REENTRANT -o dir dir.c -lpthread

the progam lists the directory, prints

    Can't read .: Error 0

and exits with 0. However, when -D_POSIX_PTHREAD_SEMANTICS is added to 
the command line, it lists the contents of the directory, but then prints

    Can't read .: Invalid argument

and exits with 1.

I /think/ this is a bug in Solaris' readdir_r, which, by all accounts, 
should set "result" to NULL and return 0 when it reaches the end of the 
directory. This implementation does set "result" to NULL, but returns 
EINVAL instead.

I'm not sure what to do here. Clearly, not defining 
_POSIX_PTHREAD_SEMANTICS is not an option, and using readdir instead 
would probably not be reentrant. We could #ifdef the termination 
condition in apr_dir_read(), but that seems like a dirty hack to me.

Unfortunately, the Solaris 2.6 machine I have access to is going away 
this week, and when it comes bach, it'll be Solaris 8. So I'll have to 
stop working on this, and am hereby dropping it into somebody else's lap.

    Brane

-- 
Brane Čibej
    home:   <br...@xbc.nu>             http://www.xbc.nu/brane/
    work:   <br...@hermes.si>   http://www.hermes-softlab.com/
     ACM :   <br...@acm.org>            http://www.acm.org/



solaris access (was: Re: apr_dir_read failing on sparc-sun-solaris2.6)

Posted by Dale Ghent <da...@elemental.org>.
On Tue, 10 Jul 2001, Cliff Woolley wrote:

| I have access to several Solaris 2.6 boxes and will until they're upgraded
| (which may or may not be anytime soon... they've been saying it'll be
| "soon" for months and months, so I'm guessing they will continue to do
| so).  I'll try to figure this out.  It might just have to be an ugly hack.
| :-/

If you (or any of the apr/httpd core hackers for that matter) need a
reliable Solaris box to log into to check stuff like this, please drop me
a note privately and I'll be happy to set up an account for you.

/dale


Re: apr_dir_read failing on sparc-sun-solaris2.6

Posted by Cliff Woolley <jw...@virginia.edu>.
On Wed, 11 Jul 2001, Branko [ISO-8859-2] �ibej wrote:

> Unfortunately, the Solaris 2.6 machine I have access to is going away
> this week, and when it comes bach, it'll be Solaris 8. So I'll have to
> stop working on this, and am hereby dropping it into somebody else's lap.

I have access to several Solaris 2.6 boxes and will until they're upgraded
(which may or may not be anytime soon... they've been saying it'll be
"soon" for months and months, so I'm guessing they will continue to do
so).  I'll try to figure this out.  It might just have to be an ugly hack.
:-/

--Cliff


--------------------------------------------------------------
   Cliff Woolley
   cliffwoolley@yahoo.com
   Charlottesville, VA