logo

bootstrap-initrd

Linux initrd to bootstrap from a small binary seed git clone https://hacktivis.me/git/bootstrap-initrd.git
commit: a0078c01ea1e474360c0f33ec4440cd02a6a5f36
parent 2718c9d1ec9bbdc7394b342372c1943162ba1967
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Sun, 23 Jun 2024 21:03:10 +0200

init.c: Create /dev/null

Diffstat:

Minit.c8++++++++
1 file changed, 8 insertions(+), 0 deletions(-)

diff --git a/init.c b/init.c @@ -3,6 +3,7 @@ // SPDX-License-Identifier: MPL-2.0 #define _POSIX_C_SOURCE 200809L +#define _XOPEN_SOURCE 700 // mknod #include "loksh_tcc.h" @@ -75,6 +76,13 @@ main(int argc, char *argv[]) if(mount("devtmpfs", "/dev", "devtmpfs", MS_NOSUID | MS_NOEXEC, NULL) < 0) fprintf(stderr, "Failed to mount /proc: %s\n", strerror(errno)); + errno = 0; + if(mknod("/dev/null", S_IFCHR | 0666, makedev(0x1, 0x3)) < 0) + { + if(errno != 0 && errno != EEXIST) + fprintf(stderr, "Failed to create /dev/null: %s\n", strerror(errno)); + } + // PS1 shouldn't be exported but '\h\$ ' is an *awful* default // and oksh also doesn't sources ksh-specific files by default setenv("PS1", "$? $PWD # ", 1);