-all: reaper reaperc reapernsl
+all: reaper
-STRIP?=strip
+CC = musl-gcc
+CFLAGS = -Wall -static -O3 -flto
-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 $@
+reaper: reaper.c
+ $(CC) $(CFLAGS) -o $@ $^
clean:
- rm -f reaper reaperc reaper.fas reaper.map reapernsl
+ rm -f reaper
-#include <errno.h>
+/**
+ * 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 <signal.h>
#include <string.h>
-#include <unistd.h>
#include <sys/wait.h>
-#include <sys/types.h>
int main(void) {
- sigset_t set;
- siginfo_t status;
+ 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;
+ sigfillset(&set);
+ sigprocmask(SIG_BLOCK,&set,NULL);
+
+ do {
+ memset( &status, 0, sizeof( status ) );
+ } while ( waitid( P_ALL, 0, &status, WEXITED ) == 0 );
+ return 0;
}