From 085fc15de32238215b63f92ce8145ebc3741dd04 Mon Sep 17 00:00:00 2001 From: "Michael T. Kloos" Date: Sat, 9 Mar 2024 10:56:17 -0500 Subject: [PATCH] Add support for NoMMU --- Makefile | 4 ++-- dumb-init.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 1ddbb37..6612499 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ SHELL=bash -CFLAGS=-std=gnu99 -static -s -Wall -Werror -O3 +CFLAGS_AUTO=-std=gnu99 -static-pie -s -Wall -Werror -O3 TEST_PACKAGE_DEPS := build-essential python python-pip procps python-dev python-setuptools @@ -8,7 +8,7 @@ VERSION = $(shell cat VERSION) .PHONY: build build: VERSION.h - $(CC) $(CFLAGS) -o dumb-init dumb-init.c + $(CC) $(CFLAGS_AUTO) $(CFLAGS) -o dumb-init dumb-init.c VERSION.h: VERSION echo '// THIS FILE IS AUTOMATICALLY GENERATED' > VERSION.h diff --git a/dumb-init.c b/dumb-init.c index a97ab41..35942d0 100644 --- a/dumb-init.c +++ b/dumb-init.c @@ -292,9 +292,9 @@ int main(int argc, char *argv[]) { } } - child_pid = fork(); + child_pid = vfork(); if (child_pid < 0) { - PRINTERR("Unable to fork. Exiting.\n"); + PRINTERR("Unable to vfork. Exiting.\n"); return 1; } else if (child_pid == 0) { /* child */ @@ -306,7 +306,7 @@ int main(int argc, char *argv[]) { errno, strerror(errno) ); - exit(1); + _exit(1); } if (ioctl(STDIN_FILENO, TIOCSCTTY, 0) == -1) { @@ -322,7 +322,7 @@ int main(int argc, char *argv[]) { // if this point is reached, exec failed, so we should exit nonzero PRINTERR("%s: %s\n", cmd[0], strerror(errno)); - return 2; + _exit(2); } else { /* parent */ DEBUG("Child spawned with PID %d.\n", child_pid); @@ -337,4 +337,6 @@ int main(int argc, char *argv[]) { handle_signal(signum); } } + + return 1; }