Skip to content

Instantly share code, notes, and snippets.

@chaser92
Last active October 19, 2020 21:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chaser92/d108c1dfdadda6ccab66ae30ccbd07bd to your computer and use it in GitHub Desktop.
Save chaser92/d108c1dfdadda6ccab66ae30ccbd07bd to your computer and use it in GitHub Desktop.
ojejq runner
#!/bin/bash
#MEM_LIMIT=""
if [ $# -lt 1 ]; then
echo "Usage: $0 <program_to_test> [args...]"
fi
SELF="$(readlink -f "$0")"
SELF_DIR="$(dirname "$SELF")"
if [ -n "$MEM_LIMIT" ]; then
MEASURE_MEM=1
fi
OPTS=""
if [ -z "$MEASURE_MEM" ]; then
OPTS+=" --seccomp off"
OPTS+=" --ptrace off"
fi
OPTS+=" --mount-namespace off"
OPTS+=" --pid-namespace off"
OPTS+=" --uts-namespace off"
OPTS+=" --ipc-namespace off"
OPTS+=" --perf off"
OPTS+=" --net-namespace off"
OPTS+=" --capability-drop off --user-namespace off"
OPTS+=" -s"
if [ -n "$MEM_LIMIT" ]; then
OPTS+=" -m $MEM_LIMIT"
fi
TMPFILE="$(mktemp)"
sio2jail -f 3 -o oiaug $OPTS -- "$@" 3>"$TMPFILE"
read STATUS CODE TIME NVM MEM SYSC <"$TMPFILE"
exec >&2
echo ""
echo "-------------------------"
echo "Status: $STATUS"
echo "Program exit code: $CODE"
echo "Time: ${TIME}ms"
if [ -n "$MEASURE_MEM" ]; then
echo "Memory: ${MEM}kB"
fi
if [ "$STATUS" != "OK" ]; then
echo "Details:"
tail -n+2 "$TMPFILE"
fi
rm "$TMPFILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment