This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: more: latest glibc glob code broken


%% Ulrich Drepper <drepper@cygnus.com> writes:

  ud> "Paul D. Smith" <psmith@BayNetworks.COM> writes:
  >> In the new version, it _does_ look for the file.  Then, after all that
  >> looking, if it's not found it just copies over the file anyway (if
  >> GLOB_NOCHECK is set).  So if there are no meta chars the results will be
  >> the same (the single file name) whether or not the file is found in the
  >> directory!!

  ud> I do not remember the reason for the changes in the moment.  All I can
  ud> say in this moment is that if there is a real change (unlike the
  ud> missing optimization mentioned in the other mail) it was necessary.
  ud> The last time I changed glob it was because some tests I've run
  ud> failed.  I'll take a look at all this ASAP.  It would help a lot if
  ud> you could provide some testing dat a(a shell script creating an
  ud> appropriate file hierachy).

I'm taking the make alpha testers off the list for the moment--they
probably don't care about the details :)

Anyway, there's no need for a shell script to create testing data or
anything.  Just invoke glob() with a static file name, and the
GLOB_NOCHECK option.  Here's a sample program:

  #include <stdio.h>
  #include <dirent.h>
  #include <sys/stat.h>

  #include <glob.h>

  int main( int argc, char **argv )
  {
      int results;
      glob_t g;

      g.gl_opendir = opendir;
      g.gl_readdir = readdir;
      g.gl_closedir = closedir;
      g.gl_stat = stat;

      results = glob(argv[1], GLOB_NOCHECK, NULL, &g);
      if (results == 0)
        printf("Success: %s\n", g.gl_pathv[0]);
      else
        printf("Unsuccessful: %d\n", results);

      return 0;
  }


Try it with a file name that exists, and again with one that doesn't.
Don't put meta-chars in either, of course.

You'll see that regardless of whether the file exists, you'll get back
the same result: success.  If you debug, you'll see that, even though
you get back the same result whether or not the filename exists,
glob_in_dir() _still_ reads through the entire directory looking for the
file... then when it can't find it and it sees NOCHECK set, it "fakes"
finding it.

Why should it do all that searching, when the results are the same
either way?

I think that, like the other change, this is also a missing
optimization.  The code will behave the same in this case, whether or
not you search the directory--so the missing optimization is to avoid
searching it.  No behavior is changed, it's just faster :)

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]