From be71d120e7107fcea6fd5e92d1481ea0530a6ee8 Mon Sep 17 00:00:00 2001 From: Thomas Orozco Date: Wed, 10 Aug 2016 08:49:44 +0200 Subject: [PATCH] Embed license and add -l flag to show it This adds 1k of weight to the resulting binary, which is reasonable (it's less than 5% for the smaller non-static binary), but alleviates legitimate user concern that the license requires being included when Tini is redistributed. --- .travis.yml | 1 + CMakeLists.txt | 10 ++++++++++ Dockerfile | 2 +- ci/run_build.sh | 4 ++++ src/tini.c | 15 +++++++++++++-- tpl/travis.yml.tpl | 1 + 6 files changed, 30 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index de07fa7..40ccaa7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,6 +24,7 @@ addons: - python-virtualenv - hardening-includes - gnupg + - vim-common env: global: diff --git a/CMakeLists.txt b/CMakeLists.txt index 1004422..0897239 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,16 @@ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Bsymbolic-functions # Build +execute_process( + COMMAND xxd -i "LICENSE" "${PROJECT_BINARY_DIR}/tiniLicense.h" + WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}" + RESULT_VARIABLE xxd_ret +) + +if(NOT "${xxd_ret}" EQUAL 0) + message(SEND_ERROR "xxd on LICENSE failed: ${xxd_ret}") +endif() + configure_file ( "${PROJECT_SOURCE_DIR}/src/tiniConfig.h.in" "${PROJECT_BINARY_DIR}/tiniConfig.h" diff --git a/Dockerfile b/Dockerfile index e92ce24..2db0692 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ FROM ubuntu:precise RUN apt-get update \ - && apt-get install --no-install-recommends --yes build-essential git gdb valgrind cmake rpm python-dev libcap-dev python-pip python-virtualenv hardening-includes gnupg \ + && apt-get install --no-install-recommends --yes build-essential git gdb valgrind cmake rpm python-dev libcap-dev python-pip python-virtualenv hardening-includes gnupg vim-common \ && rm -rf /var/lib/apt/lists/* # Pre-install those here for faster local builds. diff --git a/ci/run_build.sh b/ci/run_build.sh index ffbf149..6318bc0 100755 --- a/ci/run_build.sh +++ b/ci/run_build.sh @@ -2,6 +2,7 @@ # Should be run from the root dir, or SOURCE_DIR should be set. set -o errexit set -o nounset +set -o pipefail # Default compiler : ${CC:="gcc"} @@ -54,6 +55,9 @@ 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 diff --git a/src/tini.c b/src/tini.c index 40142ad..ce3e5ba 100644 --- a/src/tini.c +++ b/src/tini.c @@ -15,6 +15,7 @@ #include #include "tiniConfig.h" +#include "tiniLicense.h" #define PRINT_FATAL(...) fprintf(stderr, "[FATAL tini (%i)] ", getpid()); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); #define PRINT_WARNING(...) if (verbosity > 0) { fprintf(stderr, "[WARN tini (%i)] ", getpid()); fprintf(stderr, __VA_ARGS__); fprintf(stderr, "\n"); } @@ -33,11 +34,11 @@ typedef struct { #ifdef PR_SET_CHILD_SUBREAPER #define HAS_SUBREAPER 1 -#define OPT_STRING "hsvg" +#define OPT_STRING "hsvgl" #define SUBREAPER_ENV_VAR "TINI_SUBREAPER" #else #define HAS_SUBREAPER 0 -#define OPT_STRING "hvg" +#define OPT_STRING "hvgl" #endif @@ -151,9 +152,14 @@ void print_usage(char* const name, FILE* const file) { #endif fprintf(file, " -v: Generate more verbose output. Repeat up to 3 times.\n"); fprintf(file, " -g: Send signals to the child's process group.\n"); + fprintf(file, " -l: Show license and exit.\n"); fprintf(file, "\n"); } +void print_license(FILE* const file) { + fwrite(LICENSE, sizeof(char), LICENSE_len, 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]; @@ -179,6 +185,11 @@ int parse_args(const int argc, char* const argv[], char* (**child_args_ptr_ptr)[ kill_process_group++; break; + case 'l': + print_license(stdout); + *parse_fail_exitcode_ptr = 0; + return 1; + case '?': print_usage(name, stderr); return 1; diff --git a/tpl/travis.yml.tpl b/tpl/travis.yml.tpl index 967db84..52960b4 100644 --- a/tpl/travis.yml.tpl +++ b/tpl/travis.yml.tpl @@ -24,6 +24,7 @@ addons: - python-virtualenv - hardening-includes - gnupg + - vim-common env: global: