From cb5b1af6dee0ff41e73a3bc0661ba7aa7b1d1b94 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 18 Apr 2019 21:19:46 +0000 Subject: Add support for nsss and utmps; add skel management --- Makefile | 6 +- configure | 55 ++++++++- package/deps-build | 2 + package/modes | 4 +- package/targets.mak | 11 ++ skel/rc.init | 0 skel/rc.shutdown | 0 skel/runlevel | 0 src/include-local/defaults.h | 2 +- src/include-local/initctl.h | 5 +- src/init/deps-exe/s6-linux-init-maker | 2 + src/init/s6-linux-init-maker.c | 206 ++++++++++++++++++++++++++-------- 12 files changed, 234 insertions(+), 59 deletions(-) create mode 100755 skel/rc.init create mode 100755 skel/rc.shutdown create mode 100755 skel/runlevel diff --git a/Makefile b/Makefile index 610dbb6..45228b6 100644 --- a/Makefile +++ b/Makefile @@ -88,7 +88,6 @@ install-libexec: $(LIBEXEC_TARGETS:%=$(DESTDIR)$(libexecdir)/%) install-bin: $(BIN_TARGETS:%=$(DESTDIR)$(bindir)/%) install-lib: $(STATIC_LIBS:lib%.a.xyzzy=$(DESTDIR)$(libdir)/lib%.a) install-include: $(ALL_INCLUDES:src/include/$(package)/%.h=$(DESTDIR)$(includedir)/$(package)/%.h) -install-data: $(ALL_DATA:src/etc/%=$(DESTDIR)$(datadir)/%) ifneq ($(exthome),) @@ -109,9 +108,6 @@ $(DESTDIR)$(sproot)/library.so/lib%.so.$(version_M): $(DESTDIR)$(dynlibdir)/lib% endif -$(DESTDIR)$(datadir)/%: src/etc/% - exec $(INSTALL) -D -m 644 $< $@ - $(DESTDIR)$(dynlibdir)/lib%.so: lib%.so.xyzzy $(INSTALL) -D -m 755 $< $@.$(version) && \ $(INSTALL) -l $(@F).$(version) $@.$(version_m) && \ @@ -146,6 +142,6 @@ lib%.a.xyzzy: lib%.so.xyzzy: exec $(REALCC) -o $@ $(CFLAGS_ALL) $(CFLAGS_SHARED) $(LDFLAGS_ALL) $(LDFLAGS_SHARED) -Wl,-soname,$(patsubst lib%.so.xyzzy,lib%.so.$(version_M),$@) $^ $(EXTRA_LIBS) $(LDLIBS) -.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include install-data +.PHONY: it all clean distclean tgz strip install install-dynlib install-bin install-lib install-include .DELETE_ON_ERROR: diff --git a/configure b/configure index 43dc71e..5aff30e 100755 --- a/configure +++ b/configure @@ -22,7 +22,8 @@ Fine tuning of the installation directories: --libexecdir=DIR package-scoped executables [EPREFIX/libexec] --libdir=DIR static library files [PREFIX/lib/$package] --includedir=DIR C header files [PREFIX/include] - --tmpfsdir=DIR assume the initial tmpfs will be mounted on DIR [/run] + --skeldir=DIR script skeleton files [PREFIX/etc/s6-linux-init/skel] + --tmpfsdir=DIR assume the initial tmpfs will be mounted on DIR [/run] If no --prefix option is given, by default libdir (but not dynlibdir) will be /usr/lib/$package, and includedir will be /usr/include. @@ -46,6 +47,7 @@ Optional features: --enable-absolute-paths do not rely on PATH to access this package's binaries, hardcode absolute BINDIR/foobar paths instead [disabled] + --enable-nsss use the nsss library for user information [disabled] --enable-utmps link against the utmps library [disabled] EOF @@ -74,6 +76,10 @@ fail () { exit 1 } +isprefix() { + case "$1" in "$2"*) return 0 ;; *) return 1 ;; esac ; +} + fnmatch () { eval "case \"\$2\" in $1) return 0 ;; *) return 1 ;; esac" } @@ -120,6 +126,13 @@ tryldflag () { fi } +getmacro () { + echo "#include <$1>" | $CC_AUTO -v $CPPFLAGS_AUTO $CPPFLAGS $CPPFLAGS_POST $CFLAGS_AUTO $CFLAGS $CFLAGS_POST -E -dM - | grep -F -- "$2" | cut -d' ' -f3- +} + +getmacrostring () { + getmacro "$1" "$2" | sed -e 's/^"//' -e 's/"$//' +} # Actual script @@ -149,6 +162,7 @@ static=true allpic=true slashpackage=false abspath=false +usensss=false sproot= home= exthome= @@ -160,6 +174,7 @@ addlibdpath='' vpaths='' vpathd='' build= +skeldir='$prefix/etc/s6-linux-init/skel' tmpfsdir=/run utmps=false @@ -192,6 +207,9 @@ for arg ; do --disable-slashpackage) sproot= ; slashpackage=false ;; --enable-absolute-paths|--enable-absolute-paths=yes) abspath=true ;; --disable-absolute-paths|--enable-absolute-paths=no) abspath=false ;; + --enable-nsss|--enable-nsss=yes) usensss=true ;; + --disable-nsss|--enable-nsss=no) usensss=false ;; + --skeldir=*) skeldir=${arg#*=} ;; --tmpfsdir=*) tmpfsdir=${arg#*=} ;; --enable-utmps|--enable-utmps=yes) utmps=true ;; --disable-utmps|--enable-utmps=no) utmps=false ;; @@ -219,7 +237,7 @@ fi # Expand installation directories stripdir prefix -for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot ; do +for i in exec_prefix dynlibdir libexecdir bindir libdir includedir sysdeps sproot tmpfsdir skeldir ; do eval tmp=\${$i} eval $i=$tmp stripdir $i @@ -254,6 +272,7 @@ if $slashpackage ; then libdir=${home}/library libexecdir=$bindir includedir=${home}/include + skeldir=${home}/etc/skel while read dep condvar ; do if test -n "$condvar" ; then eval "cond=$condvar" @@ -366,6 +385,23 @@ if test -z "$vpaths" ; then done < package/deps-build fi +if $utmps ; then + echo "Sanity checking cross-package configuration..." + p=`getmacrostring utmps/config.h UTMPS_UTMPD_PATH` + if isprefix "$p" "$tmpfsdir"/ ; then : ; else + echo "UTMPS_UTMPD_PATH has been configured as $p which is not located under $tmpfsdir" + exit 1 + fi + utmpd_path=${p##${tmpfsdir}/} + p=`getmacrostring utmps/config.h UTMPS_WTMPD_PATH` + if isprefix "$p" "$tmpfsdir"/ ; then : ; else + echo "UTMPS_WTMPD_PATH has been configured as $p which is not located under $tmpfsdir" + exit 1 + fi + wtmpd_path=${p##${tmpfsdir}/} + echo " ... ok" +fi + echo "creating config.mak..." cmdline=$(quote "$0") for i ; do cmdline="$cmdline $(quote "$i")" ; done @@ -384,6 +420,7 @@ libexecdir := $libexecdir bindir := $bindir libdir := $libdir includedir := $includedir +skeldir := $skeldir sysdeps := $sysdeps slashpackage := $slashpackage sproot := $sproot @@ -432,6 +469,13 @@ if $allpic ; then else echo "STATIC_LIBS_ARE_PIC :=" fi +if $usensss ; then + echo "LIBNSSS := -lnsss" + echo "MAYBEPTHREAD_LIB := -lpthread" +else + echo "LIBNSSS :=" + echo "MAYBEPTHREAD_LIB :=" +fi if $utmps ; then echo "LIBUTMPS := -lutmps" else @@ -465,12 +509,15 @@ else echo "#define ${package_macro_name}_EXTBINPREFIX \"\"" fi echo "#define ${package_macro_name}_LIBEXECPREFIX \"$libexecdir/\"" +echo "#define ${package_macro_name}_SKELDIR \"$skeldir\"" echo "#define ${package_macro_name}_TMPFS \"$tmpfsdir\"" echo if $utmps ; then - echo "#define ${package_macro_name}_HAS_UTMPS" + echo "#define ${package_macro_name}_UTMPD_PATH \"$utmpd_path\"" + echo "#define ${package_macro_name}_WTMPD_PATH \"$wtmpd_path\"" else - echo "#undef ${package_macro_name}_HAS_UTMPS" + echo "#undef ${package_macro_name}_UTMPD_PATH" + echo "#undef ${package_macro_name}_WTMPD_PATH" fi echo echo "#endif" diff --git a/package/deps-build b/package/deps-build index d63229b..f622849 100644 --- a/package/deps-build +++ b/package/deps-build @@ -1,3 +1,5 @@ /package/prog/skalibs +/package/admin/nsss $usensss +/package/admin/utmps $utmps /package/admin/execline /package/admin/s6 diff --git a/package/modes b/package/modes index eff9d76..a2cac61 100644 --- a/package/modes +++ b/package/modes @@ -5,7 +5,7 @@ s6-linux-init-reboot 0750 s6-linux-init-shutdown 0755 s6-linux-init-shutdownd 0700 s6-linux-init-telinit 0750 -s6-linux-init-logouthookd 0755 +s6-linux-init-logouthookd 0700 s6-linux-init-echo 0755 s6-linux-init-umountall 0750 -s6-linux-init-maker 0755 +s6-linux-init-maker 0700 diff --git a/package/targets.mak b/package/targets.mak index b3c3151..ebe7d3c 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -14,3 +14,14 @@ BIN_TARGETS := \ s6-linux-init-maker LIB_DEFS := S6_LINUX_INIT=s6_linux_init + +SKELFILES := $(wildcard skel/*) + +$(DESTDIR)$(skeldir)/%: skel/% + ./tools/install.sh -D -m 0755 $< $@ + +install-skel: $(SKELFILES:skel/%=$(DESTDIR)$(skeldir)/%) + +.PHONY: install-skel + +install: install-skel diff --git a/skel/rc.init b/skel/rc.init new file mode 100755 index 0000000..e69de29 diff --git a/skel/rc.shutdown b/skel/rc.shutdown new file mode 100755 index 0000000..e69de29 diff --git a/skel/runlevel b/skel/runlevel new file mode 100755 index 0000000..e69de29 diff --git a/src/include-local/defaults.h b/src/include-local/defaults.h index a22693b..a28e2e5 100644 --- a/src/include-local/defaults.h +++ b/src/include-local/defaults.h @@ -3,7 +3,7 @@ #ifndef S6_LINUX_INIT_DEFAULTS_H #define S6_LINUX_INIT_DEFAULTS_H -#define BASEDIR "/etc/s6-linux-init" +#define BASEDIR "/etc/s6-linux-init/current" #define INITPATH "/usr/bin:/bin" #endif diff --git a/src/include-local/initctl.h b/src/include-local/initctl.h index 6610de8..73caf02 100644 --- a/src/include-local/initctl.h +++ b/src/include-local/initctl.h @@ -29,8 +29,7 @@ #define RUNIMAGE "run-image" #define ENVSTAGE1 "env-global" #define ENVSTAGE2 "env-stage2" -#define STAGE2 "stage2" -#define STAGE3 "stage3" -#define STAGE4 "stage4" +#define STAGE2 "rc.init" +#define STAGE3 "rc.shutdown" #endif diff --git a/src/init/deps-exe/s6-linux-init-maker b/src/init/deps-exe/s6-linux-init-maker index e7187fe..ee4ed0b 100644 --- a/src/init/deps-exe/s6-linux-init-maker +++ b/src/init/deps-exe/s6-linux-init-maker @@ -1 +1,3 @@ +${LIBNSSS} -lskarnet +${MAYBEPTHREAD_LIB} diff --git a/src/init/s6-linux-init-maker.c b/src/init/s6-linux-init-maker.c index 2470c4d..62f04da 100644 --- a/src/init/s6-linux-init-maker.c +++ b/src/init/s6-linux-init-maker.c @@ -4,6 +4,8 @@ #include #include #include +#include + #include #include #include @@ -24,7 +26,16 @@ #include "defaults.h" #include "initctl.h" -#define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_uid -g log_gid | -U ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ] dir" +#ifdef S6_LINUX_INIT_UTMPD_PATH +# include +# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ] [ -U utmp_user ]" +# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:U:" +# define UTMPS_DIR "utmps" +#else +# define USAGE "s6-linux-init-maker [ -c basedir ] [ -u log_user ] [ -G early_getty_cmd ] [ -1 ] [ -L ] [ -p initial_path ] [ -m initial_umask ] [ -t timestamp_style ] [ -d slashdev ] [ -s env_store ] [ -e initial_envvar ... ] [ -q default_grace_time ]" +# define OPTION_STRING "c:u:G:1Lp:m:t:d:s:e:E:q:" +#endif + #define dieusage() strerr_dieusage(100, USAGE) #define dienomem() strerr_diefu1sys(111, "stralloc_catb") ; @@ -35,14 +46,17 @@ static char const *initial_path = INITPATH ; static char const *env_store = 0 ; static char const *early_getty = 0 ; static char const *slashdev = 0 ; -static uid_t uncaught_logs_uid = 0 ; -static gid_t uncaught_logs_gid = 0 ; +static char const *log_user = "root" ; static unsigned int initial_umask = 0022 ; static unsigned int timestamp_style = 1 ; static unsigned int finalsleep = 3000 ; static int console = 0 ; static int logouthookd = 0 ; +#ifdef S6_LINUX_INIT_UTMPD_PATH +static char const *utmp_user = "utmp" ; +#endif + typedef int writetobuf_func_t (buffer *, char const *) ; typedef writetobuf_func_t *writetobuf_func_t_ref ; @@ -74,20 +88,19 @@ static int death_script (buffer *b, char const *s) { return put_shebang(b) && buffer_puts(b, - EXECLINE_EXTBINPREFIX "redirfd -r 0 /dev/console\n" EXECLINE_EXTBINPREFIX "redirfd -w 1 /dev/console\n" EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n" EXECLINE_EXTBINPREFIX "foreground { " S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-echo -- \"s6-svscan ") >= 0 && buffer_puts(b, s) >= 0 && buffer_puts(b, - ". Dropping to an interactive shell.\" }\n" - "/bin/sh -i\n") >= 0 ; + ". Rebooting.\" }\n" + S6_LINUX_INIT_LIBEXECPREFIX "s6-linux-init-reboot\n") >= 0 ; } static int s6_svscan_log_script (buffer *b, char const *data) { - char fmt[UINT64_FMT] ; + size_t sabase = satmp.len ; if (!put_shebang(b) || buffer_puts(b, EXECLINE_EXTBINPREFIX "redirfd -w 2 /dev/console\n" @@ -95,12 +108,11 @@ static int s6_svscan_log_script (buffer *b, char const *data) || buffer_puts(b, console ? "console" : "null") < 0 || buffer_puts(b, "\n" EXECLINE_EXTBINPREFIX "redirfd -rnb 0 " LOGGER_FIFO "\n" - S6_EXTBINPREFIX "s6-applyuidgid -u ") < 0 - || buffer_put(b, fmt, uid_fmt(fmt, uncaught_logs_uid)) < 0 - || buffer_puts(b, " -g ") < 0 - || buffer_put(b, fmt, gid_fmt(fmt, uncaught_logs_gid)) < 0 - || buffer_puts(b, " --\ns6-log -bpd3 -- ") < 0) - return 0 ; + S6_EXTBINPREFIX "s6-setuidgid ") < 0 + || !string_quote(&satmp, log_user, strlen(log_user))) return 0 ; + if (buffer_puts(b, satmp.s + sabase) < 0) goto err ; + satmp.len = sabase ; + if (buffer_puts(b, "\ns6-log -bpd3 -- ") < 0) return 0 ; if (console) { if (timestamp_style & 1 && buffer_puts(b, "t ") < 0 @@ -114,6 +126,10 @@ static int s6_svscan_log_script (buffer *b, char const *data) return 0 ; (void)data ; return 1 ; + + err: + satmp.len = sabase ; + return 0 ; } static int logouthookd_script (buffer *b, char const *data) @@ -226,7 +242,7 @@ static void cleanup (char const *base) errno = e ; } -static void auto_dir (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode) +static void auto_dir_internal (char const *base, char const *dir, uid_t uid, gid_t gid, unsigned int mode, int strict) { size_t clen = strlen(base) ; size_t dlen = strlen(dir) ; @@ -234,15 +250,26 @@ static void auto_dir (char const *base, char const *dir, uid_t uid, gid_t gid, u memcpy(fn, base, clen) ; fn[clen] = dlen ? '/' : 0 ; memcpy(fn + clen + 1, dir, dlen + 1) ; - if (mkdir(fn, mode) < 0 - || ((uid || gid) && (chown(fn, uid, gid) < 0 || chmod(fn, mode) < 0))) + + if (mkdir(fn, mode) < 0) { - cleanup(base) ; - strerr_diefu2sys(111, "mkdir ", fn) ; + if (errno != EEXIST || strict) goto err ; + } + if (uid || gid) + { + if (chown(fn, uid, gid) < 0 + || chmod(fn, mode) < 0) goto err ; } + return ; + + err: + cleanup(base) ; + strerr_diefu2sys(111, "mkdir ", fn) ; } -static void auto_file (char const *base, char const *file, char const *s, unsigned int n, int executable) +#define auto_dir(base, dir, uid, gid, mode) auto_dir_internal(base, dir, uid, gid, (mode), 1) + +static void auto_file (char const *base, char const *file, char const *s, unsigned int n) { size_t clen = strlen(base) ; size_t flen = strlen(file) ; @@ -251,7 +278,7 @@ static void auto_file (char const *base, char const *file, char const *s, unsign fn[clen] = '/' ; memcpy(fn + clen + 1, file, flen + 1) ; if (!openwritenclose_unsafe(fn, s, n) - || chmod(fn, executable ? 0755 : 0644) == -1) + || chmod(fn, 0644) == -1) { cleanup(base) ; strerr_diefu2sys(111, "write to ", fn) ; @@ -311,6 +338,18 @@ static void auto_script (char const *base, char const *file, writetobuf_func_t_r fd_close(fd) ; } +static void copy_script (char const *base, char const *src, char const *dst) +{ + size_t baselen = strlen(base) ; + size_t dstlen = strlen(dst) ; + char fn[baselen + dstlen + 2] ; + memcpy(fn, base, baselen) ; + fn[baselen] = '/' ; + memcpy(fn + baselen + 1, dst, dstlen + 1) ; + if (!filecopy_unsafe(src, fn, 0755)) + strerr_diefu4sys(111, "copy ", src, " to ", fn) ; +} + static void auto_exec (char const *base, char const *name, char const *target) { if (S6_LINUX_INIT_LIBEXECPREFIX[0] == '/') @@ -339,17 +378,99 @@ static void make_env (char const *base, char const *envname, char const *modif, memcpy(fn + envnamelen + 1, modif, pos) ; fn[envnamelen + 1 + pos] = 0 ; - if (pos + 1 < len) auto_file(base, fn, modif + pos + 1, len - pos - 1, 0) ; - else if (pos + 1 == len) auto_file(base, fn, "\n", 1, 0) ; - else auto_file(base, fn, "", 0, 0) ; + if (pos + 1 < len) auto_file(base, fn, modif + pos + 1, len - pos - 1) ; + else if (pos + 1 == len) auto_file(base, fn, "\n", 1) ; + else auto_file(base, fn, "", 0) ; modif += len+1 ; modiflen -= len+1 ; } } +static void getug (char const *s, uid_t *uid, gid_t *gid) +{ + struct passwd *pw ; + errno = 0 ; + pw = getpwnam(s) ; + if (!pw) + { + if (!errno) strerr_diefu3x(100, "find user ", s, " in passwd database") ; + else strerr_diefu2sys(111, "getpwnam for ", s) ; + } + *uid = pw->pw_uid ; + *gid = pw->pw_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 ((s[i] == '/') && i) + { + tmp[i] = 0 ; + auto_dir_internal(base, tmp, uid, gid, mode, 0) ; + } + tmp[i] = s[i] ; + } +} + +static int utmpd_script (buffer *b, char const *uw) +{ + size_t sabase = satmp.len ; + if (!put_shebang(b) + || buffer_puts(b, + EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n" + S6_EXTBINPREFIX "s6-setuidgid ") < 0 + || !string_quote(&satmp, utmp_user, strlen(utmp_user))) return 0 ; + if (buffer_puts(b, satmp.s + sabase) < 0) goto err ; + satmp.len = sabase ; + if (buffer_puts(b, "\n" + EXECLINE_EXTBINPREFIX "cd " S6_LINUX_INIT_TMPFS "/" UTMPS_DIR "\n" + EXECLINE_EXTBINPREFIX "fdmove 1 3\n" + S6_EXTBINPREFIX "s6-ipcserver -1 -- ") < 0) return 0 ; + if (buffer_puts(b, uw[0] == 'u' ? UTMPS_UTMPD_PATH : UTMPS_WTMPD_PATH) < 0 + || buffer_puts(b, "\n" + UTMPS_EXTBINPREFIX "utmps-") < 0 + || buffer_puts(b, uw) < 0 + || buffer_puts(b, "tmpd\n") < 0) return 0 ; + return 1 ; + + err: + satmp.len = sabase ; + return 0 ; +} + +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, "u") ; + auto_dir(base, "run-image/" SCANDIR "/wtmpd", 0, 0, 0755) ; + auto_file(base, "run-image/" SCANDIR "/wtmpd/notification-fd", "3\n", 2) ; + auto_script(base, "run-image/" SCANDIR "/wtmpd/run", &utmpd_script, "w") ; + { + uid_t uid ; + gid_t gid ; + getug(utmp_user, &uid, &gid) ; + auto_dir(base, "run-image/" UTMPS_DIR, uid, gid, 0755) ; + auto_basedir(base, S6_LINUX_INIT_UTMPD_PATH, uid, gid, 0755) ; + auto_basedir(base, S6_LINUX_INIT_WTMPD_PATH, uid, gid, 0755) ; + } +} + +#endif + static inline void make_image (char const *base) { auto_dir(base, "run-image", 0, 0, 0755) ; - auto_dir(base, "run-image/" UNCAUGHT_DIR, uncaught_logs_uid, uncaught_logs_gid, 02700) ; + { + uid_t uid ; + gid_t gid ; + getug(log_user, &uid, &gid) ; + auto_dir(base, "run-image/" UNCAUGHT_DIR, uid, gid, 02700) ; + } 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/crash", &death_script, "crashed") ; @@ -363,7 +484,7 @@ static inline void make_image (char const *base) 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, 0) ; + 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/" SCANDIR "/" SHUTDOWND_SERVICEDIR, 0, 0, 0755) ; @@ -375,17 +496,17 @@ static inline void make_image (char const *base) auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules", 0, 0, 0755) ; auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid", 0, 0, 0755) ; auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid/0", 0, 0, 0755) ; - auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid/0/allow", "", 0, 0) ; + auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/gid/0/allow", "", 0) ; auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid", 0, 0, 0755) ; auto_dir(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid/0", 0, 0, 0755) ; - auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid/0/allow", "", 0, 0) ; - auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/notification-fd", "3\n", 2, 0) ; + auto_file(base, "run-image/" SCANDIR "/" RUNLEVELD_SERVICEDIR "/data/rules/uid/0/allow", "", 0) ; + 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) ; 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, 0) ; + 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) ; } @@ -394,14 +515,18 @@ static inline void make_image (char const *base) auto_dir(base, "run-image/" SCANDIR "/" EARLYGETTY_SERVICEDIR, 0, 0, 0755) ; auto_script(base, "run-image/" SCANDIR "/" EARLYGETTY_SERVICEDIR "/run", &line_script, early_getty) ; } + +#ifdef S6_LINUX_INIT_UTMPD_PATH + if (utmp_user[0]) make_utmps(base) ; +#endif } static inline void make_scripts (char const *base) { auto_dir(base, "scripts", 0, 0, 0755) ; - auto_script(base, "scripts/runlevel", &put_shebang_options, 0) ; - auto_script(base, "scripts/" STAGE2, &put_shebang_options, 0) ; - auto_script(base, "scripts/" STAGE3, &put_shebang_options, 0) ; + copy_script(base, S6_LINUX_INIT_SKELDIR "/runlevel", "scripts/runlevel") ; + copy_script(base, S6_LINUX_INIT_SKELDIR "/" STAGE2, "scripts/" STAGE2) ; + copy_script(base, S6_LINUX_INIT_SKELDIR "/" STAGE3, "scripts/" STAGE3) ; } static inline void make_bins (char const *base) @@ -424,22 +549,12 @@ int main (int argc, char const *const *argv, char const *const *envp) subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "c:u:g:UG:1Lp:m:t:d:s:e:E:q:", &l) ; + int opt = subgetopt_r(argc, argv, OPTION_STRING, &l) ; if (opt == -1) break ; switch (opt) { case 'c' : robase = l.arg ; break ; - case 'u' : if (!uint0_scan(l.arg, &uncaught_logs_uid)) dieusage() ; break ; - case 'g' : if (!uint0_scan(l.arg, &uncaught_logs_gid)) dieusage() ; break ; - case 'U' : - { - char const *x = env_get2(envp, "UID") ; - if (!x) strerr_dienotset(100, "UID") ; - if (!uint0_scan(x, &uncaught_logs_uid)) strerr_dieinvalid(100, "UID") ; - x = env_get2(envp, "GID") ; - if (!x) strerr_dienotset(100, "GID") ; - if (!uint0_scan(x, &uncaught_logs_gid)) strerr_dieinvalid(100, "GID") ; - } + case 'u' : log_user = l.arg ; break ; case 'G' : early_getty = l.arg ; break ; case '1' : console = 1 ; break ; case 'L' : logouthookd = 1 ; break ; @@ -451,6 +566,9 @@ int main (int argc, char const *const *argv, char const *const *envp) case 'e' : if (!stralloc_catb(&saenv1, l.arg, strlen(l.arg) + 1)) dienomem() ; break ; case 'E' : if (!stralloc_catb(&saenv2, l.arg, strlen(l.arg) + 1)) dienomem() ; break ; case 'q' : if (!uint0_scan(l.arg, &finalsleep)) dieusage() ; break ; +#ifdef S6_LINUX_INIT_UTMPD_PATH + case 'U' : utmp_user = l.arg ; break ; +#endif default : dieusage() ; } } -- cgit v1.2.3