[erlang-questions] file:read_file/2 bug?

Christian S chsu79@REDACTED
Thu May 1 15:27:55 CEST 2008


On Thu, May 1, 2008 at 4:36 AM, Serge Aleynikov <saleyn@REDACTED> wrote:
> For some reason file:read_file/1 always returns empty binary when
>  reading from any file in the "/proc" filesystem.

Running strace reveals what is done behind the scenes:

stat64("/proc/self/environ", {st_mode=S_IFREG|0400, st_size=0, ...}) = 0
open("/proc/self/environ", O_RDONLY|O_LARGEFILE) = 7
close(7)                                = 0

Looking at /erts/emulator/drivers/unix/unix_efile.c one can also see
that efile_openfile calls stat() on the filename before it open() the
file.

I dont understand why everything is done in efile_openfile that is
done, but my guess is that if one first open() the file then use
fstat() on the file descriptor, then the proc filesystem would report
nonzero file length.

Understanding would make it worthwile to submit a patch for the efile driver.

The linux kernel generates the proc file's content as a snapshot at
the instance the file is opened. Before open() it doesnt know how long
the content will be.



More information about the erlang-questions mailing list