apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Branko ─îibej <br...@xbc.nu>
Subject apr_dir_read failing on sparc-sun-solaris2.6
Date Tue, 10 Jul 2001 22:28:26 GMT
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));

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

    printf("./%s\n", entry.entry.d_name);
  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 ─îibej
    home:   <brane@xbc.nu>             http://www.xbc.nu/brane/
    work:   <branko.cibej@hermes.si>   http://www.hermes-softlab.com/
     ACM :   <brane@acm.org>            http://www.acm.org/

View raw message