aboutgitcodelistschat:MatrixIRC
path: root/seitan-run
blob: c90e1d091509df249d07d31d574c5479fd4326ae (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/sh -e
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
# seitan - Syscall Expressive Interpreter, Transformer and Notifier
#
# seitan-run - Convenience script: run target command with syscall model
#
# Copyright (c) 2022 Red Hat GmbH
# Authors: Alice Frosi <afrosi@redhat.com>
#	   Stefano Brivio <sbrivio@redhat.com>

usage() {
	echo "${0} JSON COMMAND"
	exit 1
}

cleanup() {
	rm -rf "${DIR}/gluten" "${DIR}/bpf" "${DIR}/eater.pid"
	rmdir "${DIR}" 2>/dev/null || :
}

trap cleanup EXIT INT

[ ${#} -lt 2 ]		&& usage

[ -z "${DIR}" ]		&& DIR="$(mktemp -d)"

[ -z "${COOKER}" ]	&& COOKER="$(command -v ./seitan-cooker seitan-cooker)"
[ -z "${COOKER}" ]	&& echo "seitan-cooker not found"	&& exit 1

[ -z "${EATER}" ]	&& EATER="$(command -v ./seitan-eater seitan-eater)"
[ -z "${EATER}" ]	&& echo "seitan-eater not found"	&& exit 1

[ -z "${SEITAN}" ]	&& SEITAN="$(command -v ./seitan seitan)"
[ -z "${SEITAN}" ]	&& echo "seitan not found"		&& exit 1

"${COOKER}" "${1}" "${DIR}/gluten" "${DIR}/bpf"
echo "Cooked files now at ${DIR}"

shift
( "${EATER}" -i "${DIR}/bpf" -- ${@} & echo "${!}" > "${DIR}/eater.pid" 2>&1 ) &
sleep 0.1 || sleep 1
"${SEITAN}" -p "$(cat "${DIR}/eater.pid")" -i "${DIR}/gluten"