I am using a coroutine as a generator to list the files from a sub-tree.
However, I got this when I attempted some timing tests:

$ pil +
: (load "bug.l")
-> nextFile
: (do 20000 (while (nextFile "/tmp" NIL NIL)))
!? (in (list "stat" "-c" "%f %s %u %g %h %i %X %Y %Z" Path) (line))
Pipe error: Too many open files
? *NFCpt
-> 4081
: (bye)
[/home/laurent/.pil/history:1] !? (out (pil "history") (while (and New (n== New "Hist0")) (prinl (pop 'New)) (dec 'N)) (setq "Hist0" "History") (do N (NIL Old) (prinl (pop 'Old))))
"/home/laurent/.pil/history" -- Open error: Too many open files

lsof | grep -i pil shows a lot of open files that should not be, since

(stat "/tmp")

do not keep any file open after finishing.

Can anyone see what is the problem? (this is a partial code I used in an attempt to isolate the cause of the problem)

   S_IFDIR (hex "4000") #This is the file type constant of a directory file.
   S_IFLNK (hex "a000") #This is the file type constant of a symbolic link.

(de stat (Path)
   (mapcar pack
            (list "stat" "-c" "%f %s %u %g %h %i %X %Y %Z" Path)
            (line) )
         " " ) ) )

(de readlink (Path)
   NIL )

(de multimap (L1 L2)
      (while L1
         (link ((pop 'L1) (pop 'L2))) ) ) )

(setq *NFCpt 0)

(de nextFile (RootPath Exclusions Inclusions)
   (inc '*NFCpt)
   (co 'nextFile
      (let Dir RootPath
         (recur (Dir)
            (for F (dir Dir)
               (let Path (pack Dir "/" F)
                  # TODO: add here exclusion tests
                  (setq "Data"
                     (multimap # convert from string to integer
'(hex format format format format format format format format)
                        (stat Path) ) )
(yield (append # return (list Path <lstat data for Path> <target if softlink> NIL)
                            (list Path)
                               (if (= S_IFLNK (& S_IFLNK (car "Data")))
                                  (readlink Path)
                                  NIL ) ) ) )
                  (if (= S_IFDIR (& S_IFDIR (car "Data")))
                     (recurse Path) ) ) ) ) ) ) )

By the way, if anyone know what lib to use for (native) to make a lstat syscall so I can replace the stat shell call, I'd be very grateful: I can't find where it is! (contrary to what I thought, it is NOT in libc...)

Thanks in advance.

Laurent ARTAUD (laurent.art...@free.fr)
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to