2016-06-15
strace の -y や -yy でFD番号と共にファイルパスやIPアドレス・ポート番号を表示する
strace を使う場合、プロセスが起動している間に lsof や /proc/[pid]/fd でファイルディスクリプタ(FD)番号とファイルパスの対応を確認しておかないと、read(17, ... などと出力されている場合に、17 のファイルパスがわからなくなりますが*1、
- strace 4.7 (2012年5月リリース) から -y でFD番号と対応するファイルパス
Noteworthy changes in release 4.7 ================================= ... * Improvements * Added x32 personality support (x86_64 architecture). * Added -y and -P options to print file descriptor paths and filter by those paths.
- strace 4.10 (2015年3月リリース) から -yy でFD番号と対応するソケットの送信元と送信先のIPアドレスとポート番号
Noteworthy changes in release 4.10 (2015-03-06) =============================================== * Improvements * Added -yy option to print protocol and address information associated with socket descriptors.
を表示してくれます。これは便利!
インストール
- strace - Browse /strace/4.12 at SourceForge.net から strace-4.12.tar.xz をダウンロードする。
- ビルドする(試しに実行するだけなので make install していません)。
$ tar xfvJ strace-4.12.tar.xz $ cd strace-4.12 $ ./configure $ make
- ヘルプを見ると -y と -yy オプションが存在する。
$ ./strace -h|grep '\-y' -y print paths associated with file descriptor arguments -yy print protocol specific information associated with socket file descriptors
実行例
- -y でFD番号とともにファイルパスを表示する
$ ./strace -y ls > /dev/null execve("/bin/ls", ["ls"], [/* 23 vars */]) = 0 ... open("/etc/ld.so.cache", O_RDONLY) = 3</etc/ld.so.cache> fstat(3</etc/ld.so.cache>★, {st_mode=S_IFREG|0644, st_size=41296, ...}) = 0 mmap(NULL, 41296, PROT_READ, MAP_PRIVATE, 3</etc/ld.so.cache>, 0) = 0x7f2de6449000 close(3</etc/ld.so.cache>) = 0
FD番号"3"のパス"/etc/ld.so.cache"が表示されている。
参考
-y Print paths associated with file descriptor arguments. -yy Print ip:port pairs associated with socket file descriptors.
Add ability to print file descriptor paths and filter by those paths ... (usage, main): Implement handling of -y and -P options. * strace.1: Add descriptions of -y and -P options.
Add -yy option: print ip and port associated with socket descriptors When two ore more -y options are given, print local and remote ip:port pairs associated with socket descriptors. This implementation uses NETLINK_INET_DIAG for sockaddr lookup; it's based on the patch prepared by Zubin Mithra as a part of his GSoC 2014 strace project.
関連
トラックバック - http://d.hatena.ne.jp/yohei-a/20160615/1466010160
リンク元
- 751 https://www.google.co.jp/
- 349 https://www.google.co.jp
- 222 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0ahUKEwjcqK_LjKnNAhXk5aYKHSCIDHAQFggbMAA&url=http://d.hatena.ne.jp/yohei-a/20090622/1245638171&usg=AFQjCNEvP0zNEY3vY9VXsQUPie-VbHjxHw&bvm=bv.124272578,d.dGY
- 106 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=0ahUKEwi_o8nUjanNAhVEFJQKHbdZCUYQFggkMAE&url=http://d.hatena.ne.jp/yohei-a/20091222/1261458975&usg=AFQjCNEU8BMHtC68V9-7WSz3jKVdCT_Zig&bvm=bv.124272578,d.dGY
- 85 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=3&ved=0ahUKEwjT8NvPjKnNAhXmhaYKHfuBB1cQFggmMAI&url=http://d.hatena.ne.jp/yohei-a/20110610/1307696284&usg=AFQjCNFiCmCAkjwrWd_ehCSSlHvAEo8S9w&bvm=bv.124272578,d.dGY
- 49 http://www.google.co.jp/url?sa=t&rct=j&q=&esrc=s&source=web&cd=4&ved=0ahUKEwjJntK2lKnNAhUhLKYKHSEaB0EQFggtMAM&url=http://d.hatena.ne.jp/yohei-a/20120910/1347249284&usg=AFQjCNFP57W7tkDMC5KZ1v2lyD8Xnr3C6g
- 46 http://b.hatena.ne.jp/
- 46 http://www.google.co.jp/url?url=http://d.hatena.ne.jp/yohei-a/20081228/1230459304&rct=j&frm=1&q=&esrc=s&sa=U&ved=0ahUKEwjhs-3AkKnNAhXmg6YKHUi6C1UQFggaMAE&sig2=fZZzkhwdw4HBx7xRZPZtLg&usg=AFQjCNEf14aWp8HpbgOW9OrTaVy0wUkMww
- 46 http://www.google.co.uk/url?sa=t&source=web&cd=1
- 43 https://t.co/yGPQdN38wr