in reply to Re: failing to use getdents system call on Linux
in thread failing to use getdents system call on Linux

But the logic in the Perl program is different. It subtracts from $read and shortens the buffer by the processed bytes.

I think the Perl program could run into an infinite loop if $read becomes negative, but that doesn't seem to be the problem here...

Replies are listed 'Best First'.
Re^3: failing to use getdents system call on Linux
by Anonymous Monk on Nov 06, 2016 at 19:59 UTC

    Aye, sorry, scratch my hasty that. The syscall() must return a good value. OP problem seems to be in the unpack template. Should try native types instead: "L!L!SZ*". Perl L is 4 bytes...

      Yup, the problem was with unpack indeed... I changed the line below from:

      my ( $ino, $off, $len, $name ) = unpack( "LLSZ*", $buf );

      To:

      my ( $ino, $off, $len, $name ) = unpack( "L!L!SZ*", $buf );

      And the program finally worked as expected:

      [me@localhost ~]$ ./test2.pl -d sample/ | head sample/xaaaaaaaaff sample/xaaaaaaabdu sample/xaaaaaaabjw sample/xaaaaaaaaos sample/xaaaaaaaalu sample/xaaaaaaaags sample/xaaaaaaabci sample/xaaaaaaabhy sample/xaaaaaaabjv sample/xaaaaaaaaxa

      All good, but some questions remains:

      1. What could have happened that cause this change in the system? Originally I didn't need to worry about that. Maybe some change related going from 32 to 64 bits platforms?
      2. How can I double check if I need to use "native" sizes with the unpack template? Besides the program malfunctions, of course. :-)
      Alceu Rodrigues de Freitas Junior
      ---------------------------------
      "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill
Re^3: failing to use getdents system call on Linux
by glasswalk3r (Friar) on Nov 07, 2016 at 18:54 UTC

    Oh yes, infinite loop is a problem here, since I'm getting 1 or zero from $len. Here is the updated code:

    The part changed to Pod is exactly the one that put me in a "infinite" loop (probably not infinite, but long enough to create a very large file, but I killed the process once it reached GB).

    As you can see in the code, I used the same buffer size as in the C code... but results are the same:

    Alceu Rodrigues de Freitas Junior
    ---------------------------------
    "You have enemies? Good. That means you've stood up for something, sometime in your life." - Sir Winston Churchill