From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1680076808; bh=U2yVz5kDj49k5kSXrrDcDPCpLylv2Qxo7YFjfI7HK8w=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=c4xhtk8uW7d6JzISQoRHVs2nrcZEzZXjH6AdMTgYInIHrK+97VxX+KOwGVM6pHfNv HLXeuxaWD10b8PukikEWcpKxcqIliagP88ZyxIFAPU1I0C8rSOMPfZBZcWbHiEg5HW ShXjYCRXf77yeHa7kxXqGF2j1hDwJM1YE2YbOIKVeT4NXvx8HvbozPkQptsrDqlRXV B4/Yp+8HlHZWyYQKVP9EJMRz7BVBypEcX9SiC4r7ApN7alIUcENpwDlPkylbq/HOYW cPwfRWEmCAFPmpKJO4LGmx1Xi6rWsBIL73qfx15HeANnQtZXkJyhr9Rx4Jc8Whnhdh 3fxVlNoEn8GGg== Received: from localhost.localdomain (unknown [182.253.88.211]) by gnuweeb.org (Postfix) with ESMTPSA id 01F3F242F2A; Wed, 29 Mar 2023 08:00:04 +0000 (UTC) From: Ammar Faizi To: GNU/Weeb Mailing List Cc: Muhamad Hazmi Alfarizqi , Muhamad Hazmi Alfarizqi , Alviro Iskandar Setiawan , Arthur Lapz , Ammar Faizi Subject: [PATCH a001 v1 6/7] Create a simple init program Date: Wed, 29 Mar 2023 14:59:31 +0700 Message-Id: <20230329075932.492885-7-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230329075932.492885-1-ammarfaizi2@gnuweeb.org> References: <20230329075932.492885-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Using "tail -f /dev/null" as the init program is wrong because it doesn't handle the SIGCHLD signal, resulting many zombie processes like these: Zs 08:30 0:00 [master] Z 08:30 0:00 [qmgr] Zs 08:30 0:00 [dovecot] Z 08:30 0:00 [anvil] Z 08:30 0:00 [log] Z 08:30 0:00 [config] Z 08:30 0:00 [tlsmgr] Z 08:30 0:00 [stats] Z 08:33 0:00 [imap-login] Z 08:33 0:00 [imap] Z 08:33 0:00 [imap-login] Z 08:33 0:00 [imap] Z 08:39 0:01 [imap-login] Z 08:39 0:03 [imap] Z 11:50 0:00 [pickup] Zs 12:31 0:00 [dovecot] Z 12:31 0:00 [anvil] Z 12:31 0:00 [log] Z 12:31 0:00 [config] Z 12:31 0:00 [imap-login] Z 12:31 0:00 [stats] Z 12:31 0:00 [imap] Create a simple init program that ignores SIGCHLD so that the zombie processes are gone. Signed-off-by: Ammar Faizi --- .gitignore | 1 + Dockerfile | 5 +++-- init.c | 15 +++++++++++++++ install.sh | 1 + 4 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 init.c diff --git a/.gitignore b/.gitignore index 50cf6dedd170238f..bceb5ce4098add1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ /config +/init diff --git a/Dockerfile b/Dockerfile index 7bc54e0afb43d8ce..3492aa0408b7b5a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -41,10 +41,11 @@ RUN apt update \ postfix-policyd-spf-python dovecot-core dovecot-imapd \ dovecot-lmtpd dovecot-mysql opendkim opendmarc +COPY init /bin/gwinitd COPY mailserver /root/mailserver RUN --mount=type=secret,required=true,id=config /root/mailserver/setup.sh - +RUN chmod -v +x /bin/gwinitd COPY docker-entrypoint.sh / ENTRYPOINT [ "/docker-entrypoint.sh" ] -CMD [ "tail", "-f", "/dev/null" ] +CMD [ "/bin/gwinitd" ] diff --git a/init.c b/init.c new file mode 100644 index 0000000000000000..adc67275dd3414c0 --- /dev/null +++ b/init.c @@ -0,0 +1,15 @@ +#include +#include + +int main(void) +{ + struct sigaction a = { .sa_handler = SIG_IGN }; + + if (sigaction(SIGCHLD, &a, NULL) < 0) + return 1; + + while (1) + sleep(1000000); + + return 0; +} diff --git a/install.sh b/install.sh index 652861d263a698dc..dea60516f2e27512 100755 --- a/install.sh +++ b/install.sh @@ -1,4 +1,5 @@ #!/bin/bash set -e; +gcc -Wall -Wextra -Os init.c -o init; DOCKER_BUILDKIT=1 docker build --secret id=config -t server-a001 .; -- Ammar Faizi