Optionally disable arg parsing (-DNO_ARGS=ON)

no-args
Thomas Orozco 8 years ago
parent fa597944fa
commit 480fed14ae
  1. 8
      .travis.yml
  2. 7
      CMakeLists.txt
  3. 70
      ci/run_build.sh
  4. 1
      ddist.sh
  5. 4
      src/tini.c
  6. 26
      test/run_inner_tests.py
  7. 8
      tpl/travis.yml.tpl

@ -10,9 +10,10 @@ language: generic
env:
matrix:
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1
- CC=arm-linux-gnueabihf-gcc ARCH_SUFFIX=armhf ARCH_NATIVE=
- CC=aarch64-linux-gnu-gcc ARCH_SUFFIX=arm64 ARCH_NATIVE=
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1 NO_ARGS=
- CC=arm-linux-gnueabihf-gcc ARCH_SUFFIX=armhf ARCH_NATIVE= NO_ARGS=
- CC=aarch64-linux-gnu-gcc ARCH_SUFFIX=arm64 ARCH_NATIVE= NO_ARGS=
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1 NO_ARGS=1
global:
- SIGN_BINARIES=1
- secure: "RKF9Z9gLxp6k/xITqn7ma1E9HfpYcDXuJFf4862WeH9EMnK9lDq+TWnGsQfkIlqh8h9goe7U+BvRiTibj9MiD5u7eluLo3dlwsLxPpYtyswYeLeC1wKKdT5LPGAXbRKomvBalRYMI+dDnGIM4w96mHgGGvx2zZXGkiAQhm6fJ3k="
@ -35,3 +36,4 @@ deploy:
on:
repo: krallin/tini
tags: true
condition: '-z "$NO_ARGS"'

@ -6,6 +6,13 @@ set (tini_VERSION_MAJOR 0)
set (tini_VERSION_MINOR 10)
set (tini_VERSION_PATCH 0)
# Build options
option(NO_ARGS "Disable argument parsing" OFF)
if(NO_ARGS)
add_definitions(-DTINI_NO_ARGS=1)
endif()
# Extract git version and dirty-ness
execute_process (
COMMAND git --git-dir "${PROJECT_SOURCE_DIR}/.git" --work-tree "${PROJECT_SOURCE_DIR}" log -n 1 --date=local --pretty=format:%h

@ -44,7 +44,11 @@ export REAL_PATH="${PATH}"
export PATH="${SOURCE_DIR}/ci/util:${PATH}"
# Build
cmake -B"${BUILD_DIR}" -H"${SOURCE_DIR}"
CMAKE_ARGS=(-B"${BUILD_DIR}" -H"${SOURCE_DIR}")
if [[ -n "${NO_ARGS:-}" ]]; then
CMAKE_ARGS+=(-DNO_ARGS=ON)
fi
cmake "${CMAKE_ARGS[@]}"
pushd "${BUILD_DIR}"
make clean
@ -56,32 +60,56 @@ popd
pkg_version="$(cat "${BUILD_DIR}/VERSION")"
if [[ -n "${ARCH_NATIVE:=}" ]]; then
echo "Built native package (ARCH_NATIVE=${ARCH_NATIVE})"
echo "Running smoke and internal tests"
BIN_TEST_DIR="${BUILD_DIR}/bin-test"
mkdir -p "$BIN_TEST_DIR"
export PATH="${BIN_TEST_DIR}:${PATH}"
# Smoke tests (actual tests need Docker to run; they don't run within the CI environment)
for tini in "${BUILD_DIR}/tini" "${BUILD_DIR}/tini-static"; do
echo "Smoke test for $tini"
"${tini}" -h
echo "Testing $tini for license"
"${tini}" -l | grep -i "mit license"
echo "Testing $tini with: true"
"${tini}" -vvv true
echo "Testing $tini with: false"
if "${tini}" -vvv false; then
exit 1
fi
# Test stdin / stdout are handed over to child
echo "Testing pipe"
echo "exit 0" | "${tini}" -vvv sh
if [[ ! "$?" -eq "0" ]]; then
echo "Pipe test failed"
exit 1
if [[ -n "${NO_ARGS:-}" ]]; then
echo "Testing $tini with: true"
"${tini}" true
echo "Testing $tini with: false"
if "${tini}" false; then
exit 1
fi
# We try running binaries named after flags (both valid and invalid
# flags) and test that they run.
for flag in h s x; do
bin="-${flag}"
echo "Testing $tini can run binary: ${bin}"
cp "$(which true)" "${BIN_TEST_DIR}/${bin}"
"$tini" "$bin"
done
else
echo "Smoke test for $tini"
"${tini}" -h
echo "Testing $tini for license"
"${tini}" -l | grep -i "mit license"
echo "Testing $tini with: true"
"${tini}" -vvv true
echo "Testing $tini with: false"
if "${tini}" -vvv false; then
exit 1
fi
# Test stdin / stdout are handed over to child
echo "Testing pipe"
echo "exit 0" | "${tini}" -vvv sh
if [[ ! "$?" -eq "0" ]]; then
echo "Pipe test failed"
exit 1
fi
fi
echo "Checking hardening on $tini"

@ -24,4 +24,5 @@ docker run -it --rm \
-e CC="${CC:=gcc}" \
-e ARCH_NATIVE="${ARCH_NATIVE-1}" \
-e ARCH_SUFFIX="${ARCH_SUFFIX-}" \
-e NO_ARGS="${NO_ARGS-}" \
"${IMG}" "${SRC}/ci/run_build.sh"

@ -164,6 +164,9 @@ void print_license(FILE* const file) {
int parse_args(const int argc, char* const argv[], char* (**child_args_ptr_ptr)[], int* const parse_fail_exitcode_ptr) {
char* name = argv[0];
#if TINI_NO_ARGS
*parse_fail_exitcode_ptr = 0;
#else
int c;
while ((c = getopt(argc, argv, OPT_STRING)) != -1) {
switch (c) {
@ -197,6 +200,7 @@ int parse_args(const int argc, char* const argv[], char* (**child_args_ptr_ptr)[
return 1;
}
}
#endif
*child_args_ptr_ptr = calloc(argc-optind+1, sizeof(char*));
if (*child_args_ptr_ptr == NULL) {

@ -29,18 +29,19 @@ def main():
src = os.environ["SOURCE_DIR"]
build = os.environ["BUILD_DIR"]
args_disabled = os.environ.get("NO_ARGS")
proxy = os.path.join(src, "test", "subreaper-proxy.py")
tini = os.path.join(build, "tini")
subreaper_support = bool(int(os.environ["FORCE_SUBREAPER"]))
tests = [([proxy, tini, "--"], {}),]
tests = [([proxy, tini], {}),]
if subreaper_support:
tests.extend([
([tini, "-s", "--"], {}),
([tini, "--"], {"TINI_SUBREAPER": ""}),
])
if not args_disabled:
tests.append(([tini, "-s"], {}))
tests.append(([tini], {"TINI_SUBREAPER": ""}))
for target, env in tests:
# Run the reaping test
@ -71,17 +72,18 @@ def main():
# Run the process group test
# This test has Tini spawn a process that ignores SIGUSR1 and spawns a child that doesn't (and waits on the child)
# We send SIGUSR1 to Tini, and expect the grand-child to terminate, then the child, and then Tini.
print "Running process group test"
p = subprocess.Popen([tini, '-g', '--', os.path.join(src, "test", "pgroup", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if not args_disabled:
print "Running process group test"
p = subprocess.Popen([tini, '-g', os.path.join(src, "test", "pgroup", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
busy_wait(lambda: len(psutil.Process(p.pid).children(recursive=True)) == 2, 10)
p.send_signal(signal.SIGUSR1)
busy_wait(lambda: p.poll() is not None, 10)
busy_wait(lambda: len(psutil.Process(p.pid).children(recursive=True)) == 2, 10)
p.send_signal(signal.SIGUSR1)
busy_wait(lambda: p.poll() is not None, 10)
# Run failing test
print "Running zombie reaping failure test (Tini should warn)"
p = subprocess.Popen([tini, "--", os.path.join(src, "test", "reaping", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen([tini, os.path.join(src, "test", "reaping", "stage_1.py")], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
assert "zombie reaping won't work" in err, "No warning message was output!"
ret = p.wait()
@ -91,7 +93,7 @@ def main():
# Test that the signals are properly in place here.
print "running signal configuration test"
p = subprocess.Popen([os.path.join(build, "sigconf-test"), tini, '-g', '--', "cat", "/proc/self/status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
p = subprocess.Popen([os.path.join(build, "sigconf-test"), tini, "cat", "/proc/self/status"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
out, err = p.communicate()
# Extract the signal properties, and add a zero at the end.

@ -10,9 +10,10 @@ language: generic
env:
matrix:
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1
- CC=arm-linux-gnueabihf-gcc ARCH_SUFFIX=armhf ARCH_NATIVE=
- CC=aarch64-linux-gnu-gcc ARCH_SUFFIX=arm64 ARCH_NATIVE=
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1 NO_ARGS=
- CC=arm-linux-gnueabihf-gcc ARCH_SUFFIX=armhf ARCH_NATIVE= NO_ARGS=
- CC=aarch64-linux-gnu-gcc ARCH_SUFFIX=arm64 ARCH_NATIVE= NO_ARGS=
- CC=gcc ARCH_SUFFIX=amd64 ARCH_NATIVE=1 NO_ARGS=1
global:
- SIGN_BINARIES=1
- secure: "RKF9Z9gLxp6k/xITqn7ma1E9HfpYcDXuJFf4862WeH9EMnK9lDq+TWnGsQfkIlqh8h9goe7U+BvRiTibj9MiD5u7eluLo3dlwsLxPpYtyswYeLeC1wKKdT5LPGAXbRKomvBalRYMI+dDnGIM4w96mHgGGvx2zZXGkiAQhm6fJ3k="
@ -35,3 +36,4 @@ deploy:
on:
repo: krallin/tini
tags: true
condition: '-z "$NO_ARGS"'

Loading…
Cancel
Save