summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2020-02-26 17:27:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2020-02-26 17:27:24 +0000
commit559a8893841d3126e5a1cf2490cee8f34cb65d7a (patch)
tree33f555e63e4482a70c4b9f034b0975fd8ebff53e
parenteb5b5d843d4584f6e3548b1de069126deb3edb69 (diff)
downloads6-linux-init-559a8893841d3126e5a1cf2490cee8f34cb65d7a.tar.xz
Simplify kbrequest management
- the ioctl never works on /dev/console, so trying to use it on stdin is useless. - /dev/tty0 always exists in a devtmpfs, so the late test is okay. It works on serial consoles too. If no devtmpfs, creating a correct /dev/tty0 is the responsibility of the integrator. - Also added SIGINT blocking before disablecad, to avoid potential early panic. For it to work on kernels without signalfd, it requires the skalibs commit that unblocks selfpipe-trapped signals when not using signalfd. - No such block is needed for kbrequest, because the default action for SIGWINCH is ignore, not terminate.
-rw-r--r--src/init/s6-linux-init.c39
1 files changed, 13 insertions, 26 deletions
diff --git a/src/init/s6-linux-init.c b/src/init/s6-linux-init.c
index 10faa70..2e22850 100644
--- a/src/init/s6-linux-init.c
+++ b/src/init/s6-linux-init.c
@@ -13,7 +13,6 @@
#include <linux/kd.h>
-#include <skalibs/sysdeps.h>
#include <skalibs/types.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/sgetopt.h>
@@ -67,27 +66,21 @@ static inline void wait_for_notif (int fd)
close(fd) ;
}
-static void kbspecials (int dokbr)
+static void kbspecials (void)
{
+ int fd ;
if (inns) return ;
-
- /* second attempt to handle kbr: after we have our /dev for certain */
- if (dokbr)
+ fd = open("/dev/tty0", O_RDONLY | O_NOCTTY) ;
+ if (fd < 0)
+ strerr_warnwu2sys("open /dev/", "tty0 (kbrequest will not be handled)") ;
+ else
{
- int fd = open("/dev/tty0", O_RDONLY | O_NOCTTY) ;
- if (fd < 0)
- strerr_warnwu2sys("open /dev/", "tty0 (kbrequest will not be handled)") ;
- else
- {
- if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
- strerr_warnwu2sys("ioctl KDSIGACCEPT on ", "tty0 (kbrequest will not be handled)") ;
- close(fd) ;
- }
+ if (ioctl(fd, KDSIGACCEPT, SIGWINCH) < 0)
+ strerr_warnwu2sys("ioctl KDSIGACCEPT on ", "tty0 (kbrequest will not be handled)") ;
+ close(fd) ;
}
-#ifdef SKALIBS_HASSIGNALFD
- sig_block(SIGINT) ; /* eliminate the tiny race */
-#endif
+ sig_block(SIGINT) ; /* don't panic on early cad before s6-svscan catches it */
if (reboot(RB_DISABLE_CAD) == -1)
strerr_warnwu1sys("trap ctrl-alt-del") ;
}
@@ -132,7 +125,6 @@ int main (int argc, char const **argv, char const *const *envp)
char const *envdumpdir = 0 ;
char const *initdefault = "default" ;
int mounttype = 1 ;
- int dokbr = 1 ;
stralloc envmodifs = STRALLOC_ZERO ;
PROG = "s6-linux-init" ;
@@ -180,12 +172,7 @@ int main (int argc, char const **argv, char const *const *envp)
close(3) ;
}
}
- else
- {
- allwrite(1, BANNER, sizeof(BANNER) - 1) ;
- /* first attempt to handle kbr: before closing stdin */
- if (ioctl(0, KDSIGACCEPT, SIGWINCH) == 0) dokbr = 0 ;
- }
+ else allwrite(1, BANNER, sizeof(BANNER) - 1) ;
if (chdir("/") == -1) strerr_diefu1sys(111, "chdir to /") ;
umask(mask) ;
setpgid(0, 0) ;
@@ -285,7 +272,7 @@ int main (int argc, char const **argv, char const *const *envp)
close(notifpipe[0]) ;
fmtfd[1] = 'd' ;
fmtfd[2 + uint_fmt(fmtfd + 2, notifpipe[1])] = 0 ;
- kbspecials(dokbr) ;
+ kbspecials() ;
}
else
{
@@ -293,7 +280,7 @@ int main (int argc, char const **argv, char const *const *envp)
if (fd < 0) strerr_diefu1sys(111, "dup stderr") ;
fmtfd[1] = 'X' ;
fmtfd[2 + uint_fmt(fmtfd + 2, (unsigned int)fd)] = 0 ;
- kbspecials(dokbr) ;
+ kbspecials() ;
if (fd_copy(2, 1) == -1)
strerr_diefu1sys(111, "redirect output file descriptor") ;
}