Skip to content

Commit 903e306

Browse files
committed
Add support for NoMMU
1 parent 5ccca9c commit 903e306

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SHELL=bash
2-
CFLAGS=-std=gnu99 -static -s -Wall -Werror -O3
2+
CFLAGS_AUTO=-std=gnu99 -static-pie -s -Wall -Werror -O3
33

44
TEST_PACKAGE_DEPS := build-essential python python-pip procps python-dev python-setuptools
55

@@ -8,7 +8,7 @@ VERSION = $(shell cat VERSION)
88

99
.PHONY: build
1010
build: VERSION.h
11-
$(CC) $(CFLAGS) -o dumb-init dumb-init.c
11+
$(CC) $(CFLAGS_AUTO) $(CFLAGS) -o dumb-init dumb-init.c
1212

1313
VERSION.h: VERSION
1414
echo '// THIS FILE IS AUTOMATICALLY GENERATED' > VERSION.h

dumb-init.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <stdio.h>
1616
#include <stdlib.h>
1717
#include <string.h>
18+
#include <spawn.h>
1819
#include <sys/ioctl.h>
1920
#include <sys/types.h>
2021
#include <sys/wait.h>
@@ -292,9 +293,9 @@ int main(int argc, char *argv[]) {
292293
}
293294
}
294295

295-
child_pid = fork();
296+
child_pid = vfork();
296297
if (child_pid < 0) {
297-
PRINTERR("Unable to fork. Exiting.\n");
298+
PRINTERR("Unable to vfork. Exiting.\n");
298299
return 1;
299300
} else if (child_pid == 0) {
300301
/* child */
@@ -306,7 +307,7 @@ int main(int argc, char *argv[]) {
306307
errno,
307308
strerror(errno)
308309
);
309-
exit(1);
310+
_exit(1);
310311
}
311312

312313
if (ioctl(STDIN_FILENO, TIOCSCTTY, 0) == -1) {
@@ -322,7 +323,7 @@ int main(int argc, char *argv[]) {
322323

323324
// if this point is reached, exec failed, so we should exit nonzero
324325
PRINTERR("%s: %s\n", cmd[0], strerror(errno));
325-
return 2;
326+
_exit(2);
326327
} else {
327328
/* parent */
328329
DEBUG("Child spawned with PID %d.\n", child_pid);
@@ -337,4 +338,6 @@ int main(int argc, char *argv[]) {
337338
handle_signal(signum);
338339
}
339340
}
341+
342+
return 1;
340343
}

0 commit comments

Comments
 (0)