From c9ff1b6917c0710e4ee3d39e37e091776677ad62 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Thu, 3 Nov 2016 19:24:50 +0100 Subject: [PATCH 1/2] Add a --version flag See: https://github.com/krallin/tini/issues/55 --- ci/run_build.sh | 9 +++++++++ src/tini.c | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/ci/run_build.sh b/ci/run_build.sh index 3752090..543aeea 100755 --- a/ci/run_build.sh +++ b/ci/run_build.sh @@ -71,6 +71,9 @@ if [[ -n "${ARCH_NATIVE:=}" ]]; then # 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 "Testing ${tini} --version" + "$tini" --version | grep "tini version" + if [[ -n "${NO_ARGS:-}" ]]; then echo "Testing $tini with: true" "${tini}" true @@ -88,6 +91,12 @@ if [[ -n "${ARCH_NATIVE:=}" ]]; then cp "$(which true)" "${BIN_TEST_DIR}/${bin}" "$tini" "$bin" done + + echo "Testing $tini can run binary --version if args are given" + cp "$(which true)" "${BIN_TEST_DIR}/--version" + if "$tini" "--version" --foo | grep "tini version"; then + exit 1 + fi else echo "Smoke test for $tini" "${tini}" -h diff --git a/src/tini.c b/src/tini.c index d189d24..fa86254 100644 --- a/src/tini.c +++ b/src/tini.c @@ -41,6 +41,8 @@ typedef struct { #define OPT_STRING "hvgl" #endif +#define TINI_VERSION_STRING "tini version " TINI_VERSION TINI_GIT + #if HAS_SUBREAPER static unsigned int subreaper = 0; @@ -141,9 +143,8 @@ int spawn(const signal_configuration_t* const sigconf_ptr, char* const argv[], i } } - void print_usage(char* const name, FILE* const file) { - fprintf(file, "%s (version %s%s)\n", basename(name), TINI_VERSION, TINI_GIT); + fprintf(file, "%s (%s)\n", basename(name), TINI_VERSION_STRING); fprintf(file, "Usage: %s [OPTIONS] PROGRAM -- [ARGS]\n\n", basename(name)); fprintf(file, "Execute a program under the supervision of a valid init process (%s)\n\n", basename(name)); fprintf(file, " -h: Show this help message and exit.\n"); @@ -164,6 +165,13 @@ 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]; + // We handle --version if it's the *only* argument provided. + if (argc == 2 && strcmp("--version", argv[1]) == 0) { + *parse_fail_exitcode_ptr = 0; + fprintf(stdout, "%s\n", TINI_VERSION_STRING); + return 1; + } + #if TINI_NO_ARGS *parse_fail_exitcode_ptr = 0; #else From 99b7ab7004d399bfe307e8f297837058dfece7e7 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Thu, 3 Nov 2016 22:38:02 +0100 Subject: [PATCH 2/2] Bump version to 0.12.0 --- CMakeLists.txt | 2 +- README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 315cfdf..e664e1b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ project (tini C) # Config set (tini_VERSION_MAJOR 0) -set (tini_VERSION_MINOR 11) +set (tini_VERSION_MINOR 12) set (tini_VERSION_PATCH 0) # Build options diff --git a/README.md b/README.md index 5b33be7..ddbd4aa 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ In Docker, you will want to use an entrypoint so you don't have to remember to manually invoke Tini: # Add Tini - ENV TINI_VERSION v0.11.0 + ENV TINI_VERSION v0.12.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini RUN chmod +x /tini ENTRYPOINT ["/tini", "--"] @@ -63,7 +63,7 @@ The `tini` and `tini-static` binaries are signed using the key `595E85A6B1B4779E You can verify their signatures using `gpg` (which you may install using your package manager): - ENV TINI_VERSION v0.11.0 + ENV TINI_VERSION v0.12.0 ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini.asc /tini.asc RUN gpg --keyserver ha.pool.sks-keyservers.net --recv-keys 595E85A6B1B4779EA4DAAEC70B588DFF0527A9B7 \