From: Ralph Ronnquist Date: Wed, 30 Mar 2022 11:12:59 +0000 (+1100) Subject: Merge branch 'wip-libc' X-Git-Tag: deb_0.1.3~5 X-Git-Url: https://git.rrq.au/?a=commitdiff_plain;h=38518c9efa04fe598979fcf152460255669bbea7;hp=6392a347aec9dbc6f7c7f6429b3832592e72d57d;p=rrq%2Foverlay-boot.git Merge branch 'wip-libc' --- diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..7567e7b --- /dev/null +++ b/src/Makefile @@ -0,0 +1,13 @@ +all: reaper + +# Pick compiler by preference +CCPREFS = /usr/bin/musl-gcc /usr/bin/gcc +CC = $(word 1,$(shell ls $(CCPREFS) 2>/dev/null)) + +CFLAGS = -Wall -static -O3 -flto + +reaper: reaper.c + $(CC) $(CFLAGS) -o $@ $^ + +clean: + rm -f reaper diff --git a/src/reaper.c b/src/reaper.c new file mode 100644 index 0000000..9da2124 --- /dev/null +++ b/src/reaper.c @@ -0,0 +1,21 @@ +/** + * This program waits for child process and "reaps" them, i.e. read + * off their status so that they can terminate. The program exits when + * it runs out of children. + */ +#include +#include +#include + +int main(void) { + sigset_t set; + siginfo_t status; + + sigfillset(&set); + sigprocmask(SIG_BLOCK,&set,NULL); + + do { + memset( &status, 0, sizeof( status ) ); + } while ( waitid( P_ALL, 0, &status, WEXITED ) == 0 ); + return 0; +} 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(); +}