summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-06-06 19:27:21 +0000
committerLaurent Bercot <ska@appnovation.com>2023-06-06 19:27:21 +0000
commit2a4e570485e8dee285843ca46f6dd6155972c437 (patch)
treeecb19738ece505d9d1d71e6891196345a3a907b8 /src
parent392a1b8d4cfdb40812fa9434f06fd3ff73e39973 (diff)
downloads6-linux-init-2a4e570485e8dee285843ca46f6dd6155972c437.tar.xz
Add notification to shutdownd
This saves 1 second between stage 3 and stage 4. Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/init/s6-linux-init-maker.c3
-rw-r--r--src/shutdown/s6-linux-init-shutdownd.c17
2 files changed, 17 insertions, 3 deletions
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c
index 98b9b46..d3b921d 100644
--- a/src/init/s6-linux-init-maker.c
+++ b/src/init/s6-linux-init-maker.c
@@ -186,7 +186,7 @@ static int shutdownd_script (buffer *b, char const *data)
size_t sabase = satmp.len ;
char fmt[UINT_FMT] ;
if (!put_shebang(b)
- || buffer_puts(b, S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init-shutdownd -c ") < 0
+ || buffer_puts(b, S6_LINUX_INIT_EXTBINPREFIX "s6-linux-init-shutdownd -d3 -c ") < 0
|| !string_quote(&satmp, robase, strlen(robase))) return 0 ;
if (buffer_put(b, satmp.s + sabase, satmp.len - sabase) < 0) goto err ;
satmp.len = sabase ;
@@ -527,6 +527,7 @@ static inline void make_image (char const *base)
auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" SHUTDOWND_SERVICEDIR, 0, 0, 0755) ;
auto_fifo(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO) ;
+ auto_file(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" SHUTDOWND_SERVICEDIR "/notification-fd", "3\n", 2) ;
auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" SHUTDOWND_SERVICEDIR "/run", &shutdownd_script, 0) ;
if (inns)
diff --git a/src/shutdown/s6-linux-init-shutdownd.c b/src/shutdown/s6-linux-init-shutdownd.c
index be84baf..8b2741a 100644
--- a/src/shutdown/s6-linux-init-shutdownd.c
+++ b/src/shutdown/s6-linux-init-shutdownd.c
@@ -43,7 +43,7 @@
#define DOTSUFFIXLEN (sizeof(DOTSUFFIX) - 1)
#define CONTAINERDIR S6_LINUX_INIT_TMPFS "/" CONTAINER_RESULTS
-#define USAGE "s6-linux-init-shutdownd [ -c basedir ] [ -g gracetime ] [ -C ] [ -B ]"
+#define USAGE "s6-linux-init-shutdownd [ -d notif ] [ -c basedir ] [ -g gracetime ] [ -C ] [ -B ]"
#define dieusage() strerr_dieusage(100, USAGE)
static char const *basedir = BASEDIR ;
@@ -255,6 +255,7 @@ int main (int argc, char const *const *argv)
unsigned int grace_time = 3000 ;
tain deadline ;
int fdr, fdw ;
+ unsigned int notif = 0 ;
buffer b ;
char what = 'S' ;
char buf[64] ;
@@ -264,10 +265,11 @@ int main (int argc, char const *const *argv)
subgetopt l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "c:g:CB", &l) ;
+ int opt = subgetopt_r(argc, argv, "d:c:g:CB", &l) ;
if (opt == -1) break ;
switch (opt)
{
+ case 'd' : if (!uint0_scan(l.arg, &notif)) dieusage() ; break ;
case 'c' : basedir = l.arg ; break ;
case 'g' : if (!uint0_scan(l.arg, &grace_time)) dieusage() ; break ;
case 'C' : inns = 1 ; break ;
@@ -279,6 +281,11 @@ int main (int argc, char const *const *argv)
}
if (basedir[0] != '/')
strerr_dief2x(100, "basedir", " must be an absolute path") ;
+ if (notif)
+ {
+ if (notif < 3) strerr_dief1x(100, "notification fd must be 3 or more") ;
+ if (fcntl(notif, F_GETFD) < 0) strerr_dief1sys(100, "invalid notification fd") ;
+ }
if (grace_time > 300000) grace_time = 300000 ;
/* if we're in stage 4, exec it immediately */
@@ -315,6 +322,12 @@ int main (int argc, char const *const *argv)
buffer_init(&b, &buffer_read, fdr, buf, 64) ;
tain_now_set_stopwatch_g() ;
tain_add_g(&deadline, &tain_infinite_relative) ;
+ if (notif)
+ {
+ write(notif, "\n", 1) ;
+ close(notif) ;
+ notif = 0 ;
+ }
for (;;)
{