mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
ee3ac3aa66
This adds a small C binary for fighting zombies. It is mounted under `/dev/init` and is prepended to the args specified by the user. You enable it via a daemon flag, `dockerd --init`, as it is disable by default for backwards compat. You can also override the daemon option or specify this on a per container basis with `docker run --init=true|false`. You can test this by running a process like this as the pid 1 in a container and see the extra zombie that appears in the container as it is running. ```c int main(int argc, char ** argv) { pid_t pid = fork(); if (pid == 0) { pid = fork(); if (pid == 0) { exit(0); } sleep(3); exit(0); } printf("got pid %d and exited\n", pid); sleep(20); } ``` Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
82 lines
2.3 KiB
Bash
82 lines
2.3 KiB
Bash
#!/bin/bash
|
|
|
|
CROSS="$DEST/../cross"
|
|
|
|
set -e
|
|
|
|
if [ ! -d "$CROSS/linux/amd64" ]; then
|
|
echo >&2 'error: binary and cross must be run before tgz'
|
|
false
|
|
fi
|
|
|
|
(
|
|
for d in "$CROSS/"*/*; do
|
|
export GOARCH="$(basename "$d")"
|
|
export GOOS="$(basename "$(dirname "$d")")"
|
|
|
|
source "${MAKEDIR}/.binary-setup"
|
|
|
|
BINARY_NAME="${DOCKER_CLIENT_BINARY_NAME}-$VERSION"
|
|
DAEMON_BINARY_NAME="${DOCKER_DAEMON_BINARY_NAME}-$VERSION"
|
|
PROXY_BINARY_NAME="${DOCKER_PROXY_BINARY_NAME}-$VERSION"
|
|
BINARY_EXTENSION="$(export GOOS && binary_extension)"
|
|
if [ "$GOOS" = 'windows' ]; then
|
|
# if windows use a zip, not tgz
|
|
BUNDLE_EXTENSION=".zip"
|
|
IS_TAR="false"
|
|
else
|
|
BUNDLE_EXTENSION=".tgz"
|
|
IS_TAR="true"
|
|
fi
|
|
BINARY_FULLNAME="$BINARY_NAME$BINARY_EXTENSION"
|
|
DAEMON_BINARY_FULLNAME="$DAEMON_BINARY_NAME$BINARY_EXTENSION"
|
|
PROXY_BINARY_FULLNAME="$PROXY_BINARY_NAME$BINARY_EXTENSION"
|
|
mkdir -p "$DEST/$GOOS/$GOARCH"
|
|
TGZ="$DEST/$GOOS/$GOARCH/$BINARY_NAME$BUNDLE_EXTENSION"
|
|
|
|
# The staging directory for the files in the tgz
|
|
BUILD_PATH="$DEST/build"
|
|
|
|
# The directory that is at the root of the tar file
|
|
TAR_BASE_DIRECTORY="docker"
|
|
|
|
# $DEST/build/docker
|
|
TAR_PATH="$BUILD_PATH/$TAR_BASE_DIRECTORY"
|
|
|
|
# Copy the correct docker binary
|
|
mkdir -p $TAR_PATH
|
|
cp -L "$d/$BINARY_FULLNAME" "$TAR_PATH/${DOCKER_CLIENT_BINARY_NAME}${BINARY_EXTENSION}"
|
|
if [ -f "$d/$DAEMON_BINARY_FULLNAME" ]; then
|
|
cp -L "$d/$DAEMON_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_DAEMON_BINARY_NAME}${BINARY_EXTENSION}"
|
|
fi
|
|
if [ -f "$d/$PROXY_BINARY_FULLNAME" ]; then
|
|
cp -L "$d/$PROXY_BINARY_FULLNAME" "$TAR_PATH/${DOCKER_PROXY_BINARY_NAME}${BINARY_EXTENSION}"
|
|
fi
|
|
|
|
# copy over all the extra binaries
|
|
copy_binaries $TAR_PATH
|
|
|
|
if [ "$IS_TAR" == "true" ]; then
|
|
echo "Creating tgz from $BUILD_PATH and naming it $TGZ"
|
|
tar --numeric-owner --owner 0 -C "$BUILD_PATH" -czf "$TGZ" $TAR_BASE_DIRECTORY
|
|
else
|
|
# ZIP needs to full absolute dir path, not the absolute path
|
|
ZIP=`pwd`"/$TGZ"
|
|
# keep track of where we are, for later.
|
|
pushd .
|
|
# go into the BUILD_PATH since zip does not have a -C equivalent.
|
|
cd $BUILD_PATH
|
|
echo "Creating zip from $BUILD_PATH and naming it $ZIP"
|
|
zip -q -r $ZIP $TAR_BASE_DIRECTORY
|
|
# go back to where we started
|
|
popd
|
|
fi
|
|
|
|
hash_files "$TGZ"
|
|
|
|
# cleanup after ourselves
|
|
rm -rf "$BUILD_PATH"
|
|
|
|
echo "Created tgz: $TGZ"
|
|
done
|
|
)
|