summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-06-13 13:28:18 +0000
committerLaurent Bercot <ska@appnovation.com>2022-06-13 13:28:18 +0000
commitf397b21ae0336ed2d6e22a9c7394a2a17497ad32 (patch)
treee5982c18bf29b9920b97002959037ce26945ceb1 /src
parent5646d591d90d2fd78a4aeb8e313a1c50a11776c2 (diff)
downloads6-linux-init-f397b21ae0336ed2d6e22a9c7394a2a17497ad32.tar.xz
Make scandir compile-time configurable
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/include-local/initctl.h12
-rw-r--r--src/init/s6-linux-init-maker.c97
-rw-r--r--src/init/s6-linux-init.c2
-rw-r--r--src/shutdown/s6-linux-init-shutdownd.c1
4 files changed, 53 insertions, 59 deletions
diff --git a/src/include-local/initctl.h b/src/include-local/initctl.h
index a1be5c8..4e3df00 100644
--- a/src/include-local/initctl.h
+++ b/src/include-local/initctl.h
@@ -5,26 +5,26 @@
#include <s6-linux-init/config.h>
-#define SCANDIR "service"
+#define SCANDIRFULL S6_LINUX_INIT_TMPFS "/" S6_LINUX_INIT_SCANDIR
#define SHUTDOWND_SERVICEDIR "s6-linux-init-shutdownd"
#define SHUTDOWND_FIFO "fifo"
-#define INITCTL S6_LINUX_INIT_TMPFS "/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO
+#define INITCTL SCANDIRFULL "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO
#define RUNLEVELD_SERVICEDIR "s6-linux-init-runleveld"
#define RUNLEVELD_SOCKET "s"
-#define RUNLEVELD_PATH S6_LINUX_INIT_TMPFS "/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/" RUNLEVELD_SOCKET
+#define RUNLEVELD_PATH SCANDIRFULL "/" RUNLEVELD_SERVICEDIR "/" RUNLEVELD_SOCKET
#define LOGOUTHOOKD_SERVICEDIR "s6-linux-init-logouthookd"
#define LOGOUTHOOKD_SOCKET "s"
-#define LOGOUTHOOKD_PATH S6_LINUX_INIT_TMPFS "/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/" LOGOUTHOOKD_SOCKET
+#define LOGOUTHOOKD_PATH SCANDIRFULL "/" LOGOUTHOOKD_SERVICEDIR "/" LOGOUTHOOKD_SOCKET
#define LOGGER_SERVICEDIR "s6-svscan-log"
#define LOGGER_FIFO "fifo"
-#define LOGFIFO S6_LINUX_INIT_TMPFS "/" SCANDIR "/" LOGGER_SERVICEDIR "/" LOGGER_FIFO
+#define LOGFIFO SCANDIRFULL "/" LOGGER_SERVICEDIR "/" LOGGER_FIFO
#define EARLYGETTY_SERVICEDIR "s6-linux-init-early-getty"
-#define EARLYGETTY S6_LINUX_INIT_TMPFS "/" SCANDIR "/" EARLYGETTY_SERVICEDIR
+#define EARLYGETTY SCANDIRFULL "/" EARLYGETTY_SERVICEDIR
#define CONTAINER_RESULTS "s6-linux-init-container-results"
diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c
index f17bc37..840695f 100644
--- a/src/init/s6-linux-init-maker.c
+++ b/src/init/s6-linux-init-maker.c
@@ -316,7 +316,7 @@ static void cleanup (char const *base)
errno = e ;
}
-static void auto_dir_internal (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode, int strict)
+static void auto_dir_internal (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode, unsigned int options)
{
size_t clen = strlen(base) ;
size_t dlen = strlen(dir) ;
@@ -325,9 +325,21 @@ static void auto_dir_internal (char const *base, char const *dir, uid_t uid, gid
fn[clen] = dlen ? '/' : 0 ;
memcpy(fn + clen + 1, dir, dlen + 1) ;
+ if (options & 2)
+ {
+ for (size_t i = clen + 1 ; i < clen + 1 + dlen ; i++) if (fn[i] == '/')
+ {
+ fn[i] = 0 ;
+ if (mkdir(fn, 0755) < 0 && (errno != EEXIST || (options & 1))) goto err ;
+ fn[i] = '/' ;
+ }
+ }
+
+ if (options & 4) return ;
+
if (mkdir(fn, mode) < 0)
{
- if (errno != EEXIST || strict) goto err ;
+ if (errno != EEXIST || (options & 1)) goto err ;
}
else
{
@@ -500,21 +512,6 @@ static void getug (char const *base, char const *s, uid_t *uid, gid_t *gid)
#ifdef S6_LINUX_INIT_UTMPD_PATH
-static inline void auto_basedir (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode)
-{
- size_t n = strlen(dir) ;
- char tmp[n + 1] ;
- for (size_t i = 0 ; i < n ; i++)
- {
- if ((dir[i] == '/') && i)
- {
- tmp[i] = 0 ;
- auto_dir_internal(base, tmp, uid, gid, mode, 0) ;
- }
- tmp[i] = dir[i] ;
- }
-}
-
static int utmpd_script (buffer *b, char const *aux)
{
size_t sabase = satmp.len ;
@@ -544,15 +541,15 @@ static int utmpd_script (buffer *b, char const *aux)
static inline void make_utmps (char const *base)
{
- auto_dir(base, "run-image/" SCANDIR "/utmpd", 0, 0, 0755) ;
- auto_file(base, "run-image/" SCANDIR "/utmpd/notification-fd", "3\n", 2) ;
- auto_script(base, "run-image/" SCANDIR "/utmpd/run", &utmpd_script, 0) ;
+ auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/utmpd", 0, 0, 0755) ;
+ auto_file(base, "run-image/" S6_LINUX_INIT_SCANDIR "/utmpd/notification-fd", "3\n", 2) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/utmpd/run", &utmpd_script, 0) ;
{
uid_t uid ;
gid_t gid ;
getug(base, utmp_user, &uid, &gid) ;
auto_dir(base, "run-image/" UTMPS_DIR, uid, gid, 0755) ;
- auto_basedir(base, "run-image/" S6_LINUX_INIT_UTMPD_PATH, uid, gid, 0755) ;
+ auto_dir_internal(base, "run-image/" S6_LINUX_INIT_UTMPD_PATH, uid, gid, 0755, 6) ;
}
}
@@ -560,15 +557,13 @@ static inline void make_utmps (char const *base)
static inline void make_image (char const *base)
{
- auto_dir(base, "run-image", 0, 0, 0755) ;
- auto_dir(base, "run-image/" SCANDIR, 0, 0, 0755) ;
- auto_dir(base, "run-image/" SCANDIR "/.s6-svscan", 0, 0, 0755) ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGQUIT", &put_shebang_options, 0) ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGINT", &sig_script, "-r") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGUSR1", &sig_script, "-p") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGUSR2", &sig_script, "-h") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGPWR", &sig_script, "-p") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGWINCH", &put_shebang_options, 0) ;
+ auto_dir_internal(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan", 0, 0, 0755, 3) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGQUIT", &put_shebang_options, 0) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGINT", &sig_script, "-r") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGUSR1", &sig_script, "-p") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGUSR2", &sig_script, "-h") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGPWR", &sig_script, "-p") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGWINCH", &put_shebang_options, 0) ;
if (!nologger)
{
@@ -576,45 +571,45 @@ static inline void make_image (char const *base)
gid_t gid ;
getug(base, log_user, &uid, &gid) ;
auto_dir(base, "run-image/" UNCAUGHT_DIR, uid, gid, 02750) ;
- auto_dir(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR, 0, 0, 0755) ;
- auto_fifo(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/" LOGGER_FIFO) ;
- auto_file(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/notification-fd", "3\n", 2) ;
- auto_script(base, "run-image/" SCANDIR "/" LOGGER_SERVICEDIR "/run", &s6_svscan_log_script, 0) ;
+ auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGGER_SERVICEDIR, 0, 0, 0755) ;
+ auto_fifo(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGGER_SERVICEDIR "/" LOGGER_FIFO) ;
+ auto_file(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGGER_SERVICEDIR "/notification-fd", "3\n", 2) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGGER_SERVICEDIR "/run", &s6_svscan_log_script, 0) ;
}
- auto_dir(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR, 0, 0, 0755) ;
- auto_fifo(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/" SHUTDOWND_FIFO) ;
- auto_script(base, "run-image/" SCANDIR "/" SHUTDOWND_SERVICEDIR "/run", &shutdownd_script, 0) ;
+ 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_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" SHUTDOWND_SERVICEDIR "/run", &shutdownd_script, 0) ;
if (inns)
{
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGTERM", &sig_script, "-h") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/crash", &container_crash_script, 0) ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/finish", &container_exit_script, 0) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGTERM", &sig_script, "-h") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/crash", &container_crash_script, 0) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/finish", &container_exit_script, 0) ;
auto_dir(base, "run-image/" CONTAINER_RESULTS, 0, 0, 0755) ;
auto_file(base, "run-image/" CONTAINER_RESULTS "/exitcode", "0\n", 2) ;
}
else
{
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/SIGTERM", &put_shebang_options, 0) ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/crash", &death_script, "crashed") ;
- auto_script(base, "run-image/" SCANDIR "/.s6-svscan/finish", &death_script, "exited") ;
- auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR, 0, 0, 0755) ;
- auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/notification-fd", "3\n", 2) ;
- auto_script(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/run", &runleveld_script, 0) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/SIGTERM", &put_shebang_options, 0) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/crash", &death_script, "crashed") ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/.s6-svscan/finish", &death_script, "exited") ;
+ auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" RUNLEVELD_SERVICEDIR, 0, 0, 0755) ;
+ auto_file(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" RUNLEVELD_SERVICEDIR "/notification-fd", "3\n", 2) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" RUNLEVELD_SERVICEDIR "/run", &runleveld_script, 0) ;
}
if (logouthookd)
{
- auto_dir(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR, 0, 0, 0755) ;
- auto_file(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/notification-fd", "1\n", 2) ;
- auto_script(base, "run-image/" SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/run", &logouthookd_script, 0) ;
+ auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGOUTHOOKD_SERVICEDIR, 0, 0, 0755) ;
+ auto_file(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/notification-fd", "1\n", 2) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" LOGOUTHOOKD_SERVICEDIR "/run", &logouthookd_script, 0) ;
}
if (early_getty)
{
- auto_dir(base, "run-image/" SCANDIR "/" EARLYGETTY_SERVICEDIR, 0, 0, 0755) ;
- auto_script(base, "run-image/" SCANDIR "/" EARLYGETTY_SERVICEDIR "/run", &line_script, early_getty) ;
+ auto_dir(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" EARLYGETTY_SERVICEDIR, 0, 0, 0755) ;
+ auto_script(base, "run-image/" S6_LINUX_INIT_SCANDIR "/" EARLYGETTY_SERVICEDIR "/run", &line_script, early_getty) ;
}
#ifdef S6_LINUX_INIT_UTMPD_PATH
diff --git a/src/init/s6-linux-init.c b/src/init/s6-linux-init.c
index d0bb442..d9585d6 100644
--- a/src/init/s6-linux-init.c
+++ b/src/init/s6-linux-init.c
@@ -289,7 +289,7 @@ int main (int argc, char const **argv, char const *const *envp)
char const *newenvp[2] = { 0, 0 } ;
size_t pathlen = path ? strlen(path) : 0 ;
char fmtfd[2 + UINT_FMT] = "-" ;
- char const *newargv[5] = { S6_EXTBINPREFIX "s6-svscan", fmtfd, "--", S6_LINUX_INIT_TMPFS "/" SCANDIR, 0 } ;
+ char const *newargv[5] = { S6_EXTBINPREFIX "s6-svscan", fmtfd, "--", SCANDIRFULL, 0 } ;
char pathvar[6 + pathlen] ;
if (path)
{
diff --git a/src/shutdown/s6-linux-init-shutdownd.c b/src/shutdown/s6-linux-init-shutdownd.c
index ddf5804..ed02721 100644
--- a/src/shutdown/s6-linux-init-shutdownd.c
+++ b/src/shutdown/s6-linux-init-shutdownd.c
@@ -36,7 +36,6 @@
#include "hpr.h"
#define STAGE4_FILE "stage 4"
-#define SCANDIRFULL S6_LINUX_INIT_TMPFS "/" SCANDIR
#define SCANPREFIX SCANDIRFULL "/"
#define SCANPREFIXLEN (sizeof(SCANPREFIX) - 1)
#define DOTPREFIX ".s6-linux-init-shutdownd:"