[build]: add --init option in docker run for better signal handling (#5066)

--init: Run an init inside the container that forwards signals and
reaps processes

Before the change, process 1 is make, which does not do well to forward
signals and reaps process. We could see zombie process left if user
issues ctrl+c to interrupt the make process. with --init option,
a docker-init process will forwards the signals and reaps processes.
zombie process is no longer observed, and ctrl+c can reliably interrupt
the make process.

Before:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
lgh            1  0.3  0.0  12604 11908 pts/0    S+   10:54   0:00 make ...

After:
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
lgh            1  0.0  0.0   1080     4 pts/0    Ss   10:54   0:00 /sbin/docker-init -- make ...
lgh            7  0.3  0.0  12604 11908 pts/0    S+   10:54   0:00 make ...

Signed-off-by: Guohan Lu <lguohan@gmail.com>
This commit is contained in:
lguohan 2020-07-29 18:27:44 -07:00 committed by GitHub
parent 311045f01f
commit 70d1e0c899
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -108,7 +108,7 @@ ifeq ($(DOCKER_BUILDER_WORKDIR),)
override DOCKER_BUILDER_WORKDIR := "/sonic"
endif
DOCKER_RUN := docker run --rm=true --privileged \
DOCKER_RUN := docker run --rm=true --privileged --init \
-v $(DOCKER_BUILDER_MOUNT) \
-w $(DOCKER_BUILDER_WORKDIR) \
-e "http_proxy=$(http_proxy)" \