[Ecls-list] directory function and stat system calls
Robert Dodier
robert.dodier at gmail.com
Wed Dec 16 05:14:45 UTC 2009
Hello,
We got a report about Maxima calling stat on a lot
of files when the program is launched.
Aside from all the files in the Maxima share directory,
which we expect Maxima to look at, stat was called
on a lot of other files as well (stuff outside the Maxima
directory structure).
I think the unexpected stat calls stem from the
following. When DIRECTORY is called on some
pathname, it calls stat on every item in each of
the successive directories in the path.
e.g. (directory (pathname "/var/tmp/foo"))
calls stat on all items in /, all items in /var,
and all items in /var/tmp.
I've append some strace output which shows that.
On slow filesystems (e.g. NFS) all those calls to
stat might take a long time (e.g. minutes).
Also, inspecting arbitrary files might cause raised
eyebrows among the security conscious.
In the absense of wild-card path components,
what purpose is served by calling stat on the
contents of directories? I wonder if it is possible
to suppress the calls to stat.
Thanks for your attention to this question.
Robert Dodier
PS. Here is part of the output from strace,
starting from the place I typed
(directory (pathname "/var/tmp/foo"))
at the input prompt:
read(0, "(directory (pathname \"/var/tmp/f"..., 1024) = 38
getcwd("/home/robert/tmp", 128) = 17
getcwd("/home/robert/tmp", 128) = 17
chdir("/") = 0
chdir("/") = 0
getcwd("/", 128) = 2
open("./", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
getdents64(3, /* 26 entries */, 4096) = 720
stat64("lost+found", {st_mode=S_IFDIR|0755, st_size=16384, ...}) = 0
stat64("boot", {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
stat64("proc", {st_mode=S_IFDIR|0555, st_size=0, ...}) = 0
stat64(".bash_history", {st_mode=S_IFREG|0600, st_size=3766, ...}) = 0
stat64("var", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=36864, ...}) = 0
stat64("dev", {st_mode=S_IFDIR|0755, st_size=122880, ...}) = 0
stat64("etc", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("usr", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("bin", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("home", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("mnt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("opt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("root", {st_mode=S_IFDIR|0750, st_size=4096, ...}) = 0
stat64("sbin", {st_mode=S_IFDIR|0755, st_size=8192, ...}) = 0
stat64("misc", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64(".viminfo", {st_mode=S_IFREG|0600, st_size=4297, ...}) = 0
stat64("directory", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64(".MCOP-random-seed", {st_mode=S_IFREG|0600, st_size=32, ...}) = 0
stat64(".journal", {st_mode=S_IFREG|0600, st_size=33554432, ...}) = 0
stat64("rhinstall-stage2.img", {st_mode=S_IFREG|0755,
st_size=67166208, ...}) = 0
stat64("initrd", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64(".autofsck", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
getdents64(3, /* 0 entries */, 4096) = 0
close(3) = 0
chdir("var") = 0
getcwd("/var", 128) = 5
open("./", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat64(3, {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
getdents64(3, /* 23 entries */, 4096) = 632
stat64("lib", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("log", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("db", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("local", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("lock", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat64("mail", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
stat64("nis", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("opt", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("preserve", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("run", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("spool", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("tmp", {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
stat64("gdm", {st_mode=S_IFDIR|S_ISVTX|0770, st_size=4096, ...}) = 0
stat64("yp", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("arpwatch", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("www", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("data", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("state", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("empty", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64(".com.zerog.registry.xml", {st_mode=S_IFREG|0777, st_size=1933, ...}) = 0
getdents64(3, /* 0 entries */, 4096) = 0
close(3) = 0
chdir("tmp") = 0
getcwd("/var/tmp", 128) = 9
open("./", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY) = 3
fstat64(3, {st_mode=S_IFDIR|S_ISVTX|0777, st_size=4096, ...}) = 0
fcntl64(3, F_SETFD, FD_CLOEXEC) = 0
getdents64(3, /* 6 entries */, 4096) = 168
getdents64(3, /* 0 entries */, 4096) = 0
close(3) = 0
stat64("foo", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat64("bar.1", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat64("bar.2", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
stat64("bar.3", {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
chdir("/var/") = 0
chdir("/") = 0
chdir("/home/robert/tmp/") = 0
chdir("/home/robert/tmp/") = 0
write(1, "\n", 1) = 1
write(1, "NIL", 3) = 3
write(1, "\n", 1) = 1
write(1, "> ", 2) = 2
read(0, "", 1024) = 0
write(1, "\n", 1) = 1
munmap(0xbf5ab000, 4096) = 0
exit_group(0) = ?
More information about the ecl-devel
mailing list