Bundle libseccomp 2.3.1
[linux-seccomp.git] / libseccomp / tools / scmp_app_inspector
CommitLineData
8befd5cc
MG
1#!/bin/bash
2
3#
4# Runtime syscall inspector
5#
6# Copyright (c) 2012 Red Hat <pmoore@redhat.com>
7# Author: Paul Moore <paul@paul-moore.com>
8#
9
10#
11# This library is free software; you can redistribute it and/or modify it
12# under the terms of version 2.1 of the GNU Lesser General Public License as
13# published by the Free Software Foundation.
14#
15# This library is distributed in the hope that it will be useful, but WITHOUT
16# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
18# for more details.
19#
20# You should have received a copy of the GNU Lesser General Public License
21# along with this library; if not, see <http://www.gnu.org/licenses>.
22#
23
24####
25# functions
26
27function verify_deps() {
28 [[ -z "$1" ]] && return
29 if ! which "$1" >& /dev/null; then
30 echo "error: install \"$1\" and include it in your \$PATH"
31 exit 1
32 fi
33}
34
35####
36# main
37
38# verify script dependencies
39verify_deps strace
40verify_deps sed
41verify_deps sort
42verify_deps uniq
43
44# get the command line arguments
45opt_freq=0
46opt_args=0
47opt_out="/proc/self/fd/1"
48while getopts "afo:h" opt; do
49 case $opt in
50 a)
51 opt_args=1
52 ;;
53 f)
54 opt_freq=1
55 ;;
56 o)
57 opt_out="$OPTARG"
58 ;;
59 h|*)
60 echo "usage $0 [-f] [-a] [-o <file>] <command> [<args>]"
61 exit 1
62 esac
63done
64shift $(expr $OPTIND - 1)
65
66# generate a temporary output file
67raw=$(mktemp -t strace-raw_XXXXXX)
68out="$raw-out"
69
70# capture the strace output
71strace -o $raw -- $*
72
73# filter the raw strace
74if [[ $opt_args -eq 0 ]]; then
75 if [[ $opt_freq -eq 0 ]]; then
76 cat $raw | sed -e 's/(.*//' | sort -u > $out
77 else
78 cat $raw | sed -e 's/(.*//' | sort | uniq -c | sort -nr > $out
79 fi
80else
81 if [[ $opt_freq -eq 0 ]]; then
82 cat $raw | sed -e 's/)[ \t]*=.*$/)/' \
83 | sed -e 's/".*,/"...",/g;s/\/\*.*\*\//.../g' \
84 | sed -e 's/0x[a-f0-9]\+/.../g' \
85 | sort -u > $out
86 else
87 cat $raw | sed -e 's/)[ \t]*=.*$/)/' \
88 | sed -e 's/".*,/"...",/g;s/\/\*.*\*\//.../g' \
89 | sed -e 's/0x[a-f0-9]\+/.../g' \
90 | sort | uniq -c | sort -nr > $out
91 fi
92fi
93
94# display the output
95echo "============================================================" > $opt_out
96echo "Syscall Report (\"$*\")" >> $opt_out
97[[ $opt_freq -eq 1 ]] && echo " freq syscall" >> $opt_out
98echo "============================================================" >> $opt_out
99cat $out >> $opt_out
100
101# cleanup and exit
102rm -f $raw $out
103exit 0
This page took 0.015051 seconds and 4 git commands to generate.