From 31e7fe4de0502c6065244d07ebbae7410c7da9f7 Mon Sep 17 00:00:00 2001 From: Ralph Ronnquist Date: Tue, 29 Mar 2022 12:22:42 +1100 Subject: [PATCH] reaper in C (bbonev) --- src/Makefile | 22 ++++++++++++++++++++++ src/reaper.c | 19 +++++++++++++++++++ src/reaper_nsl.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 src/Makefile create mode 100644 src/reaper.c create mode 100644 src/reaper_nsl.c diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..82cffb0 --- /dev/null +++ b/src/Makefile @@ -0,0 +1,22 @@ +all: reaper reaperc reapernsl + +STRIP?=strip + +reaper: reaper.asm + fasm $^ -s $@.fas $@ + chmod a+x $@ + +reaper.map: reaper + ./fas2txt.lsp $@.fas > $@.map + +reaperc: reaper.c + $(CC) -O3 -flto -o $@ $^ + $(STRIP) $@ + +reapernsl: reaper_nsl.c + #$(CC) -O3 -flto -nostdlib -static -fdata-sections -ffunction-sections -o $@ $^ -Wl,--gc-sections -Wl,--strip-all -Wl,--build-id=none + $(CC) -O3 -flto -nostdlib -static -o $@ $^ -Wl,--build-id=none + $(STRIP) --remove-section=.comment $@ + +clean: + rm -f reaper reaperc reaper.fas reaper.map reapernsl diff --git a/src/reaper.c b/src/reaper.c new file mode 100644 index 0000000..f1c2f9a --- /dev/null +++ b/src/reaper.c @@ -0,0 +1,19 @@ +#include +#include +#include +#include +#include +#include + +int main(void) { + sigset_t set; + siginfo_t status; + + if (getpid()!=1) + return 1; + sigfillset(&set); + sigprocmask(SIG_BLOCK,&set,NULL); + memset(&status,0,sizeof status); + while (-ECHILD!=waitid(P_ALL,0,&status,WEXITED)); + return 1; +} diff --git a/src/reaper_nsl.c b/src/reaper_nsl.c new file mode 100644 index 0000000..b788562 --- /dev/null +++ b/src/reaper_nsl.c @@ -0,0 +1,36 @@ +//#include +//#include +//#include +//#include +//#include +//#include + +//int main(void) { +// sigset_t set; +// siginfo_t status; +// +// if (getpid()!=1) +// return 1; +// sigfillset(&set); +// sigprocmask(SIG_BLOCK,&set,NULL); +// memset(&status,0,sizeof status); +// while (-ECHILD!=waitid(P_ALL,0,&status,WEXITED)); +// return 1; +//} + +#define _GNU_SOURCE + +#include +#include +#include +#include + +static inline void nsl_exit1(void) { + asm("mov $60,%eax"); + asm("mov $1,%rdi"); + asm("syscall"); +} + +__attribute__((naked)) void _start(void) { + nsl_exit1(); +} -- 2.39.2