Quantcast
Channel: Filter out failed syscalls from strace log - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 4

Filter out failed syscalls from strace log

$
0
0

I can run strace on a command like sleep 1and see what files it's accessing like this:

strace -e trace=file -o strace.log sleep 1

However, on my machine, many of the calls have a return value of -1indicating that the file does not exist. For example:

$ grep '= -1 ENOENT' strace.log | headaccess("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_IDENTIFICATION", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_MEASUREMENT", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_TELEPHONE", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_ADDRESS", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_NAME", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)open("/usr/lib/locale/en_US.UTF-8/LC_PAPER", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

I'm not really interested in the files that don't exist,I want to know what files the process actually found and read from.Aside from grep -v '=-1 ENOENT',how can I reliably filter out failed calls?

Addendum

I was surprised to learnthat strace has had this feature in the works since 2002in the form of the -z flag, which is an alias for -e status=successful,fully functional since version 5.2(2019-07-12),also available as --successful-onlysince version 5.6 (2020-04-07).

Also available since version 5.2 is the complement of -z, the -Z flag,which is an alias for -e status=failed,available as --failed-only since version 5.6.

The -z flag was first added in a commit from 2002 and released in version 4.5.18 (2008-08-28),bit it had never been documented because it was not working properly.

Relevant links:


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>