forked from google/syzkaller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyz-env
executable file
·69 lines (65 loc) · 2.23 KB
/
syz-env
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/usr/bin/env bash
# Copyright 2020 syzkaller project authors. All rights reserved.
# Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
# syz-env is a wrapper around gcr.io/syzkaller/env container,
# which includes all tools necessary to develop/test syzkaller.
# It's recommended to create an alias for this script:
#
# alias syz-env="$(go env GOPATH)/src/github.com/google/syzkaller/tools/syz-env"
#
# Then it can be used to wrap almost any make invocation as:
#
# syz-env make format
# syz-env make presubmit
# syz-env make extract SOURCEDIR=~/linux
#
# Or you may run the shell inside of the container with just syz-env.
#
# Note: this way everything runs inside of the container
# and uses all tools bundled in the container rather than host tools.
#
# Note: syz-env assumes a sudo-less Docker is installed, see:
# https://docs.docker.com/engine/install
# https://docs.docker.com/engine/install/linux-postinstall
# (Googlers see go/docker).
COMMAND=""
DOCKERARGS=()
for ARG in "$@"; do
while IFS='=' read KEY VAL; do
# If we have a kernel path passed in, we mount it in the container
# at /syzkaller/kernel and fix up SOURCEDIR argument.
if [ "$KEY" == "SOURCEDIR" ]; then
DOCKERARGS+=" --volume $VAL:/syzkaller/kernel"
COMMAND+=" SOURCEDIR=/syzkaller/kernel"
else
COMMAND+=" $ARG"
fi
done <<< "$ARG"
done
if [ "$CI" == "" ]; then
# This gives interactive shell and allows to abort commands with Ctrl+C.
DOCKERARGS+=" -it"
fi
if [ "$COMMAND" == "" ]; then
COMMAND="bash"
fi
SCRIPT_DIR="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd -P)"
IMAGE="env"
if [ "$(basename -- "$0")" == "syz-big-env" ]; then
IMAGE="big-env"
fi
# Run everything as the host user, this is important for created/modified files.
docker run \
--user $(id -u ${USER}):$(id -g ${USER}) \
--volume "$SCRIPT_DIR/..:/syzkaller/gopath/src/github.com/google/syzkaller" \
--volume "$HOME/.cache:/syzkaller/.cache" \
--volume "/var/run/docker.sock":"/var/run/docker.sock" \
--workdir /syzkaller/gopath/src/github.com/google/syzkaller \
--env HOME=/syzkaller \
--env GOPATH=/syzkaller/gopath:/gopath \
--env FUZZIT_API_KEY \
--env GITHUB_REF \
--env GITHUB_SHA \
--env CI \
${DOCKERARGS[@]} \
gcr.io/syzkaller/${IMAGE} -c "$COMMAND"