diff --git a/.gitignore b/.gitignore index 577a58f1..fda90951 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,7 @@ /ocic conmon/conmon conmon/conmon.o +pause/pause +pause/pause.o /docs/ocid.8 vendor/src/github.com/kubernetes-incubator/cri-o diff --git a/Makefile b/Makefile index 9abff264..a09f0e1a 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,9 @@ ${OCID_LINK}: conmon: make -C $@ +pause: + make -C $@ + ocid: ${OCID_LINK} go build -o ocid ./cmd/server/ @@ -44,6 +47,7 @@ clean: rm -f ocic ocid rm -f ${OCID_LINK} rm -f conmon/conmon.o conmon/conmon + rm -f pause/pause.o pause/pause rm -f docs/*.1 docs/*.8 find . -name \*~ -delete find . -name \#\* -delete @@ -64,7 +68,7 @@ integration: ocidimage localintegration: binaries ./test/test_runner.sh ${TESTFLAGS} -binaries: ${OCID_LINK} ocid ocic conmon +binaries: ${OCID_LINK} ocid ocic conmon pause MANPAGES_MD = $(wildcard docs/*.md) @@ -82,12 +86,13 @@ install: binaries docs install -D -m 755 ocid ${INSTALLDIR}/ocid install -D -m 755 ocic ${INSTALLDIR}/ocic install -D -m 755 conmon/conmon $(PREFIX)/libexec/ocid/conmon + install -D -m 755 pause/pause $(PREFIX)/libexec/ocid/pause install -d $(PREFIX)/share/man/man8 install -m 644 $(basename $(MANPAGES_MD)) $(PREFIX)/share/man/man8 uninstall: rm -f ${INSTALLDIR}/{ocid,ocic} - rm -f $(PREFIX)/libexec/ocid/conmon + rm -f $(PREFIX)/libexec/ocid/{conmon,pause} for i in $(basename $(MANPAGES_MD)); do \ rm -f $(PREFIX)/share/man/man8/$$(basename $${i}); \ done @@ -118,13 +123,14 @@ install.tools: .install.gitvalidation .install.gometalinter .install.md2man .PHONY: \ binaries \ + clean \ conmon \ default \ docs \ - ocid \ - ocic \ - clean \ - lint \ help \ install \ + lint \ + ocic \ + ocid \ + pause \ uninstall diff --git a/pause/.gitignore b/pause/.gitignore new file mode 100644 index 00000000..b7735d56 --- /dev/null +++ b/pause/.gitignore @@ -0,0 +1,3 @@ +/.container-* +/.push-* +/bin diff --git a/pause/Makefile b/pause/Makefile new file mode 100644 index 00000000..a6f886a6 --- /dev/null +++ b/pause/Makefile @@ -0,0 +1,13 @@ +src = $(wildcard *.c) +obj = $(src:.c=.o) + +override LIBS += +override CFLAGS += -Os -Wall -Wextra -static + +pause: $(obj) + $(CC) -o $@ $^ $(CFLAGS) $(LIBS) + strip $@ + +.PHONY: clean +clean: + rm -f $(obj) pause diff --git a/pause/pause.c b/pause/pause.c new file mode 100644 index 00000000..ffbceb69 --- /dev/null +++ b/pause/pause.c @@ -0,0 +1,36 @@ +/* +Copyright 2016 The Kubernetes Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include +#include +#include + +static void sigdown(int signo) { + psignal(signo, "shutting down, got signal"); + exit(0); +} + +int main() { + if (signal(SIGINT, sigdown) == SIG_ERR) + return 1; + if (signal(SIGTERM, sigdown) == SIG_ERR) + return 2; + signal(SIGKILL, sigdown); + for (;;) pause(); + fprintf(stderr, "error: infinite loop terminated\n"); + return 42; +}