From 23fba266a9454ee6ca095b7f6eccf523f6526607 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Sat, 2 Mar 2019 09:41:24 +0000 Subject: Save pending changes in 1.0.0.0 branch --- src/state/s6-linux-init-single.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/state/s6-linux-init-single.c (limited to 'src/state/s6-linux-init-single.c') diff --git a/src/state/s6-linux-init-single.c b/src/state/s6-linux-init-single.c new file mode 100644 index 0000000..4f23340 --- /dev/null +++ b/src/state/s6-linux-init-single.c @@ -0,0 +1,54 @@ +/* ISC license. */ + +#include +#include +#include + +#include +#include +#include + +#include "initctl.h" + +#define USAGE "s6-linux-init-single" +#define dieusage() strerr_dieusage(100, USAGE) + +#define BANNER "Executing interactive root shell.\n" + +int main (void) +{ + int fd ; + PROG = "s6-linux-init-single" ; + fd = open(EARLYGETTY, O_RDONLY) ; + if (fd == -1) + { + if (errno != ENOENT) + strerr_diefu2sys(111, "opendir ", EARLYGETTY) ; + goto shell ; + } + if (faccessat(fd, "down", F_OK, 0) == 0) + { + fd_close(fd) ; + goto shell ; + } + if (errno != ENOENT) + strerr_diefu3sys(111, "access ", EARLYGETTY, "/down") ; + return 0 ; + + shell: + + fd = open("/dev/console", O_RDONLY) ; + if (fd == -1) strerr_diefu2sys(111, "open /dev/console for ", "reading") ; + if (fd_move(0, fd) == -1) strerr_diefu1sys(111, "move /dev/console fd to 0") ; + fd = open("/dev/console", O_WRONLY) ; + if (fd == -1) strerr_diefu2sys(111, "open /dev/console for ", "writing") ; + if (fd_move(1, fd) == -1) strerr_diefu1sys(111, "move /dev/console fd to 1") ; + if (fd_copy(2, 1) == -1) strerr_diefu1sys(111, "dup2 1 to 2") ; + if (allwrite(1, BANNER, sizeof(BANNER) - 1) < sizeof(BANNER) - 1) + strerr_diefu1sys(111, "write banner") ; + { + char *argv[3] = { "/bin/sh", "-i", 0 } ; + execv(argv[0], argv) ; + strerr_dieexec(111, argv[0]) ; + } +} -- cgit v1.3.1