gentoo-guestのインストール済みディレクトリ(9p)で、次の操作を行います。
TMPDIR='./foo' # The directory './foo' exists and the name 'TMPDIR' is important
cat <<EOF
hello world
EOF
次の結果が表示されます。
cat: -: No such file or directory
設定を解除する$TMPDIR
か、./foo
すべてを削除すると期待どおりに機能します。
猫が依存しているようです$TMPDIR
。これはバグですか?
編集する
次のようになりますstrace
。
execve("/bin/cat", ["cat"], 0x7fffdbbfeb20 /* 23 vars */) = 0
brk(NULL) = 0x55eca4cce000
access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory)
openat(AT_FDCWD, "/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=22796, ...}) = 0
mmap(NULL, 22796, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7f7166997000
close(3) = 0
openat(AT_FDCWD, "/lib64/libc.so.6", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\34\2\0\0\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1857312, ...}) = 0
mmap(NULL, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f7166995000
mmap(NULL, 3963464, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f71663af000
mprotect(0x7f716656d000, 2097152, PROT_NONE) = 0
mmap(0x7f716676d000, 24576, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x1be000) = 0x7f716676d000
mmap(0x7f7166773000, 14920, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x7f7166773000
close(3) = 0
arch_prctl(ARCH_SET_FS, 0x7f7166996540) = 0
mprotect(0x7f716676d000, 16384, PROT_READ) = 0
mprotect(0x55eca40ce000, 4096, PROT_READ) = 0
mprotect(0x7f716699d000, 4096, PROT_READ) = 0
munmap(0x7f7166997000, 22796) = 0
brk(NULL) = 0x55eca4cce000
brk(0x55eca4cef000) = 0x55eca4cef000
fstat(1, {st_mode=S_IFCHR|0600, st_rdev=makedev(229, 0), ...}) = 0
fstat(0, 0x7ffe16cc1ec0) = -1 ENOENT (No such file or directory)
write(2, "cat: ", 5) = 5
write(2, "-", 1) = 1
write(2, ": No such file or directory", 27) = 27
write(2, "\n", 1) = 1
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(1) = ?
+++ exited with 1 +++
答え1
実際にはcat
依存しませんが、$TMPDIR
シェルリダイレクトは<<
依存します。
この場合(fd 0)でcat
実行しようとすると、何らかの理由で(straceで)失敗するようです。fstat()
stdin
fstat(0, 0x7ffe16cc1ec0) = -1 ENOENT (No such file or directory)
一般的な状況ではこれは問題ではありません。
strace -f cat <<FOO
> bar
> FOO
execve("/usr/bin/cat", ["cat"], [/* 91 vars */]) = 0
...
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 0), ...}) = 0
fstat(0, {st_mode=S_IFREG|0600, st_size=4, ...}) = 0
fadvise64(0, 0, 0, POSIX_FADV_SEQUENTIAL) = 0
mmap(NULL, 139264, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f4844156000
read(0, "bar\n", 131072) = 4
write(1, "bar\n", 4bar
) = 4
read(0, "", 131072) = 0
munmap(0x7f4844156000, 139264) = 0
close(0) = 0
close(1) = 0
close(2) = 0
exit_group(0) = ?
+++ exited with 0 +++
繰り返しますが、これは仮想環境のバグではなく、cat
仮想環境の一部のバグです。