summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2022-08-20 09:20:56 +0000
committerLaurent Bercot <ska@appnovation.com>2022-08-20 09:20:56 +0000
commit28f5b4e7a5cce43198269f26583e66a232a976b5 (patch)
treea9fb8a49920db08193aa7ad2d88d533b8e1ea141
parent632acb58b77d08a384ada611b5ab1ebca96ff85d (diff)
downloads6-28f5b4e7a5cce43198269f26583e66a232a976b5.tar.xz
Factor s6_auto_write_logrun into a new libs6auto
libs6auto distinct from libs6 because of execline dep. Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r--package/deps.mak14
-rw-r--r--package/targets.mak1
-rw-r--r--src/include/s6/auto.h11
-rw-r--r--src/include/s6/s6.h1
-rw-r--r--src/libs6/deps-lib/s6auto1
-rw-r--r--src/libs6/s6_auto_write_logrun.c62
-rw-r--r--src/usertree/deps-exe/s6-usertree-maker1
-rw-r--r--src/usertree/s6-usertree-maker.c44
-rwxr-xr-xtools/gen-deps.sh2
9 files changed, 91 insertions, 46 deletions
diff --git a/package/deps.mak b/package/deps.mak
index f12c969..58d497d 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -5,7 +5,7 @@
src/include/s6/compat.h: src/include/s6/config.h
src/include/s6/ftrigr.h: src/include/s6/config.h
src/include/s6/lock.h: src/include/s6/config.h
-src/include/s6/s6.h: src/include/s6/accessrules.h src/include/s6/compat.h src/include/s6/ftrigr.h src/include/s6/ftrigw.h src/include/s6/lock.h src/include/s6/supervise.h
+src/include/s6/s6.h: src/include/s6/accessrules.h src/include/s6/auto.h src/include/s6/compat.h src/include/s6/ftrigr.h src/include/s6/ftrigw.h src/include/s6/lock.h src/include/s6/supervise.h
src/supervision/s6-svlisten.h: src/include/s6/ftrigr.h
src/conn-tools/s6-accessrules-cdb-from-fs.o src/conn-tools/s6-accessrules-cdb-from-fs.lo: src/conn-tools/s6-accessrules-cdb-from-fs.c
src/conn-tools/s6-accessrules-fs-from-cdb.o src/conn-tools/s6-accessrules-fs-from-cdb.lo: src/conn-tools/s6-accessrules-fs-from-cdb.c
@@ -73,6 +73,7 @@ src/libs6/s6_accessrules_keycheck_uidgid.o src/libs6/s6_accessrules_keycheck_uid
src/libs6/s6_accessrules_params_free.o src/libs6/s6_accessrules_params_free.lo: src/libs6/s6_accessrules_params_free.c src/include/s6/accessrules.h
src/libs6/s6_accessrules_uidgid_cdb.o src/libs6/s6_accessrules_uidgid_cdb.lo: src/libs6/s6_accessrules_uidgid_cdb.c src/include/s6/accessrules.h
src/libs6/s6_accessrules_uidgid_fs.o src/libs6/s6_accessrules_uidgid_fs.lo: src/libs6/s6_accessrules_uidgid_fs.c src/include/s6/accessrules.h
+src/libs6/s6_auto_write_logrun.o src/libs6/s6_auto_write_logrun.lo: src/libs6/s6_auto_write_logrun.c src/include/s6/auto.h src/include/s6/config.h
src/libs6/s6_compat_el_semicolon.o src/libs6/s6_compat_el_semicolon.lo: src/libs6/s6_compat_el_semicolon.c src/include/s6/config.h
src/libs6/s6_dtally_pack.o src/libs6/s6_dtally_pack.lo: src/libs6/s6_dtally_pack.c src/include/s6/supervise.h
src/libs6/s6_dtally_read.o src/libs6/s6_dtally_read.lo: src/libs6/s6_dtally_read.c src/include/s6/supervise.h
@@ -141,7 +142,7 @@ src/supervision/s6-svunlink.o src/supervision/s6-svunlink.lo: src/supervision/s6
src/supervision/s6-svwait.o src/supervision/s6-svwait.lo: src/supervision/s6-svwait.c src/supervision/s6-svlisten.h
src/supervision/s6_svlisten_loop.o src/supervision/s6_svlisten_loop.lo: src/supervision/s6_svlisten_loop.c src/supervision/s6-svlisten.h src/include/s6/ftrigr.h src/include/s6/ftrigw.h src/include/s6/supervise.h
src/supervision/s6_svlisten_signal_handler.o src/supervision/s6_svlisten_signal_handler.lo: src/supervision/s6_svlisten_signal_handler.c src/supervision/s6-svlisten.h
-src/usertree/s6-usertree-maker.o src/usertree/s6-usertree-maker.lo: src/usertree/s6-usertree-maker.c src/include/s6/config.h
+src/usertree/s6-usertree-maker.o src/usertree/s6-usertree-maker.lo: src/usertree/s6-usertree-maker.c src/include/s6/auto.h src/include/s6/config.h
s6-accessrules-cdb-from-fs: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB}
s6-accessrules-cdb-from-fs: src/conn-tools/s6-accessrules-cdb-from-fs.o
@@ -219,6 +220,13 @@ endif
libs6.so.xyzzy: EXTRA_LIBS := -lskarnet
libs6.so.xyzzy: src/libs6/ftrigr1_zero.lo src/libs6/ftrigr_check.lo src/libs6/ftrigr_checksa.lo src/libs6/ftrigr_ack.lo src/libs6/ftrigr_end.lo src/libs6/ftrigr_start.lo src/libs6/ftrigr_startf.lo src/libs6/ftrigr_subscribe.lo src/libs6/ftrigr_unsubscribe.lo src/libs6/ftrigr_update.lo src/libs6/ftrigr_updateb.lo src/libs6/ftrigr_wait_and.lo src/libs6/ftrigr_wait_or.lo src/libs6/ftrigr_zero.lo src/libs6/ftrigw_clean.lo src/libs6/ftrigw_fifodir_make.lo src/libs6/ftrigw_notify.lo src/libs6/ftrigw_notifyb.lo src/libs6/ftrigw_notifyb_nosig.lo src/libs6/s6_accessrules_backend_cdb.lo src/libs6/s6_accessrules_backend_fs.lo src/libs6/s6_accessrules_keycheck_ip4.lo src/libs6/s6_accessrules_keycheck_ip6.lo src/libs6/s6_accessrules_keycheck_reversedns.lo src/libs6/s6_accessrules_keycheck_uidgid.lo src/libs6/s6_accessrules_params_free.lo src/libs6/s6_accessrules_uidgid_cdb.lo src/libs6/s6_accessrules_uidgid_fs.lo src/libs6/s6_compat_el_semicolon.lo src/libs6/s6_dtally_pack.lo src/libs6/s6_dtally_unpack.lo src/libs6/s6_dtally_read.lo src/libs6/s6_dtally_write.lo src/libs6/s6_servicedir_file_list.lo src/libs6/s6_svc_ok.lo src/libs6/s6_svc_write.lo src/libs6/s6_svc_writectl.lo src/libs6/s6_svstatus_pack.lo src/libs6/s6_svstatus_read.lo src/libs6/s6_svstatus_unpack.lo src/libs6/s6_svstatus_write.lo src/libs6/s6lock_acquire.lo src/libs6/s6lock_check.lo src/libs6/s6lock_end.lo src/libs6/s6lock_release.lo src/libs6/s6lock_start.lo src/libs6/s6lock_startf.lo src/libs6/s6lock_update.lo src/libs6/s6lock_wait_and.lo src/libs6/s6lock_wait_or.lo src/libs6/s6lock_zero.lo src/libs6/s6_fdholder_delete.lo src/libs6/s6_fdholder_delete_async.lo src/libs6/s6_fdholder_end.lo src/libs6/s6_fdholder_getdump.lo src/libs6/s6_fdholder_list.lo src/libs6/s6_fdholder_list_async.lo src/libs6/s6_fdholder_list_cb.lo src/libs6/s6_fdholder_retrieve.lo src/libs6/s6_fdholder_retrieve_async.lo src/libs6/s6_fdholder_retrieve_cb.lo src/libs6/s6_fdholder_setdump.lo src/libs6/s6_fdholder_start.lo src/libs6/s6_fdholder_store.lo src/libs6/s6_fdholder_store_async.lo src/libs6/s6_supervise_link.lo src/libs6/s6_supervise_link_names.lo src/libs6/s6_supervise_unlink.lo src/libs6/s6_supervise_unlink_names.lo
ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
+libs6auto.a.xyzzy: src/libs6/s6_auto_write_logrun.o
+else
+libs6auto.a.xyzzy: src/libs6/s6_auto_write_logrun.lo
+endif
+libs6auto.so.xyzzy: EXTRA_LIBS :=
+libs6auto.so.xyzzy: src/libs6/s6_auto_write_logrun.lo
+ifeq ($(strip $(STATIC_LIBS_ARE_PIC)),)
libs6lockd.a.xyzzy: src/libs6/s6lockd_openandlock.o
else
libs6lockd.a.xyzzy: src/libs6/s6lockd_openandlock.lo
@@ -274,5 +282,5 @@ s6-svunlink: src/supervision/s6-svunlink.o ${LIBS6}
s6-svwait: EXTRA_LIBS := -lskarnet ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB}
s6-svwait: src/supervision/s6-svwait.o src/supervision/s6_svlisten_loop.o ${LIBS6}
s6-usertree-maker: EXTRA_LIBS := -lskarnet
-s6-usertree-maker: src/usertree/s6-usertree-maker.o
+s6-usertree-maker: src/usertree/s6-usertree-maker.o libs6auto.a.xyzzy
INTERNAL_LIBS := libs6lockd.a.xyzzy
diff --git a/package/targets.mak b/package/targets.mak
index 4208b12..bfbf3a6 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -63,5 +63,6 @@ LIBEXEC_TARGETS := s6lockd-helper
LIB_DEFS := S6=s6
ifneq ($(EXECLINE_LIB),)
+LIB_DEFS += S6AUTO=s6auto
BIN_TARGETS += s6-usertree-maker
endif
diff --git a/src/include/s6/auto.h b/src/include/s6/auto.h
new file mode 100644
index 0000000..b8faff6
--- /dev/null
+++ b/src/include/s6/auto.h
@@ -0,0 +1,11 @@
+/* ISC license. */
+
+#ifndef S6_AUTO_H
+#define S6_AUTO_H
+
+#include <skalibs/uint64.h>
+#include <skalibs/stralloc.h>
+
+int s6_auto_write_logrun (char const *, char const *, char const *, unsigned int, unsigned int, uint64_t, uint64_t, stralloc *) ;
+
+#endif
diff --git a/src/include/s6/s6.h b/src/include/s6/s6.h
index 5b32a86..ef521bb 100644
--- a/src/include/s6/s6.h
+++ b/src/include/s6/s6.h
@@ -9,5 +9,6 @@
#include <s6/ftrigw.h>
#include <s6/accessrules.h>
#include <s6/lock.h>
+#include <s6/auto.h>
#endif
diff --git a/src/libs6/deps-lib/s6auto b/src/libs6/deps-lib/s6auto
new file mode 100644
index 0000000..a9fc8c9
--- /dev/null
+++ b/src/libs6/deps-lib/s6auto
@@ -0,0 +1 @@
+s6_auto_write_logrun.o
diff --git a/src/libs6/s6_auto_write_logrun.c b/src/libs6/s6_auto_write_logrun.c
new file mode 100644
index 0000000..f5c4baf
--- /dev/null
+++ b/src/libs6/s6_auto_write_logrun.c
@@ -0,0 +1,62 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/uint64.h>
+#include <skalibs/types.h>
+#include <skalibs/buffer.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/skamisc.h>
+
+#include <execline/config.h>
+
+#include <s6/config.h>
+#include <s6/auto.h>
+
+int s6_auto_write_logrun (char const *runfile, char const *loguser, char const *logdir, unsigned int stamptype, unsigned int nfiles, uint64_t filesize, uint64_t maxsize, stralloc *sa)
+{
+ buffer b ;
+ char buf[1024] ;
+ char fmt[UINT64_FMT] ;
+ int fd = open_trunc(runfile) ;
+ if (fd < 0) return 0 ;
+ buffer_init(&b, &buffer_write, fd, buf, 1024) ;
+ if (buffer_puts(&b, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n") < 0) goto err ;
+ if (loguser)
+ {
+ if (buffer_puts(&b, S6_EXTBINPREFIX "s6-setuidgid ") < 0
+ || !string_quote(sa, loguser, strlen(loguser))
+ || buffer_put(&b, sa->s, sa->len) < 0
+ || buffer_put(&b, "\n", 1) < 0) goto err ;
+ sa->len = 0 ;
+ }
+ if (buffer_puts(&b, S6_EXTBINPREFIX "s6-log -bd3 -- ") < 0
+ || (stamptype & 1 && buffer_put(&b, "t ", 2) < 0)
+ || (stamptype & 2 && buffer_put(&b, "T ", 2) < 0)
+ || buffer_put(&b, "n", 1) < 0
+ || buffer_put(&b, fmt, uint_fmt(fmt, nfiles)) < 0
+ || buffer_put(&b, " s", 2) < 0
+ || buffer_put(&b, fmt, uint64_fmt(fmt, filesize)) < 0
+ || buffer_put(&b, " ", 1) < 0) goto err ;
+ if (maxsize)
+ {
+ if (buffer_put(&b, "S", 1) < 0
+ || buffer_put(&b, fmt, uint64_fmt(fmt, maxsize)) < 0
+ || buffer_put(&b, " ", 1) < 0) goto err ;
+ }
+ if (!string_quote(sa, logdir, strlen(logdir))
+ || buffer_put(&b, sa->s, sa->len) < 0
+ || buffer_put(&b, "\n", 1) < 0) goto err ;
+ sa->len = 0 ;
+
+ if (!buffer_flush(&b)) goto err ;
+ fd_close(fd) ;
+ return 1 ;
+
+ err:
+ fd_close(fd) ;
+ unlink_void(runfile) ;
+ return 0 ;
+}
diff --git a/src/usertree/deps-exe/s6-usertree-maker b/src/usertree/deps-exe/s6-usertree-maker
index e7187fe..750e758 100644
--- a/src/usertree/deps-exe/s6-usertree-maker
+++ b/src/usertree/deps-exe/s6-usertree-maker
@@ -1 +1,2 @@
+libs6auto.a.xyzzy
-lskarnet
diff --git a/src/usertree/s6-usertree-maker.c b/src/usertree/s6-usertree-maker.c
index 0b4c440..9f65b77 100644
--- a/src/usertree/s6-usertree-maker.c
+++ b/src/usertree/s6-usertree-maker.c
@@ -20,6 +20,7 @@
#include <execline/config.h>
#include <s6/config.h>
+#include <s6/auto.h>
#define USAGE "s6-usertree-maker [ -d userscandir ] [ -p path ] [ -E envdir [ -e var ... ] ] [ -r service/logger[/pipeline] ] [ -l loguser ] [ -t stamptype ] [ -n nfiles ] [ -s filesize ] [ -S maxsize ] user logdir dir"
#define dieusage() strerr_dieusage(100, USAGE)
@@ -112,47 +113,6 @@ static inline void write_run (char const *runfile, char const *user, char const
strerr_diefu1sys(111, "quote string") ;
}
-static inline void write_logrun (char const *runfile, char const *loguser, char const *logdir, unsigned int stamptype, unsigned int nfiles, uint64_t filesize, uint64_t maxsize)
-{
- buffer b ;
- char buf[1024] ;
- char fmt[UINT64_FMT] ;
- int fd = open_trunc(runfile) ;
- if (fd < 0) strerr_diefu3sys(111, "open ", runfile, " for writing") ;
- buffer_init(&b, &buffer_write, fd, buf, 1024) ;
- if (buffer_puts(&b, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n") < 0) goto err ;
- if (loguser)
- {
- if (buffer_puts(&b, S6_EXTBINPREFIX "s6-setuidgid ") < 0) goto err ;
- if (!string_quote(&sa, loguser, strlen(loguser))) strerr_diefu1sys(111, "quote string") ;
- if (buffer_put(&b, sa.s, sa.len) < 0 || buffer_put(&b, "\n", 1) < 0) goto err ;
- sa.len = 0 ;
- }
- if (buffer_puts(&b, S6_EXTBINPREFIX "s6-log -bd3 -- ") < 0) goto err ;
- if (stamptype & 1 && buffer_put(&b, "t ", 2) < 0) goto err ;
- if (stamptype & 2 && buffer_put(&b, "T ", 2) < 0) goto err ;
- if (buffer_put(&b, "n", 1) < 0
- || buffer_put(&b, fmt, uint_fmt(fmt, nfiles)) < 0
- || buffer_put(&b, " s", 2) < 0
- || buffer_put(&b, fmt, uint64_fmt(fmt, filesize)) < 0
- || buffer_put(&b, " ", 1) < 0) goto err ;
- if (maxsize)
- {
- if (buffer_put(&b, "S", 1) < 0
- || buffer_put(&b, fmt, uint64_fmt(fmt, maxsize)) < 0
- || buffer_put(&b, " ", 1) < 0) goto err ;
- }
- if (!string_quote(&sa, logdir, strlen(logdir))) strerr_diefu1sys(111, "quote string") ;
- if (buffer_put(&b, sa.s, sa.len) < 0 || buffer_put(&b, "\n", 1) < 0) goto err ;
- sa.len = 0 ;
-
- if (!buffer_flush(&b)) goto err ;
- fd_close(fd) ;
- return ;
- err:
- strerr_diefu2sys(111, "write to ", runfile) ;
-}
-
static void write_service (char const *dir, char const *user, char const *sc, char const *logger, char const *path, char const *userenvdir, char const *const *vars, size_t varlen)
{
size_t dirlen = strlen(dir) ;
@@ -185,7 +145,7 @@ static void write_logger (char const *dir, char const *user, char const *logdir,
memcpy(fn + dirlen, "/notification-fd", 17) ;
if (!openwritenclose_unsafe(fn, "3\n", 2)) goto err ;
memcpy(fn + dirlen + 1, "run", 4) ;
- write_logrun(fn, user, logdir, stamptype, nfiles, filesize, maxsize) ;
+ if (!s6_auto_write_logrun(fn, user, logdir, stamptype, nfiles, filesize, maxsize, &sa)) goto err ;
if (service)
{
struct iovec v[2] = { { .iov_base = (char *)service, .iov_len = strlen(service) }, { .iov_base = "\n", .iov_len = 1 } } ;
diff --git a/tools/gen-deps.sh b/tools/gen-deps.sh
index cff90ad..befe021 100755
--- a/tools/gen-deps.sh
+++ b/tools/gen-deps.sh
@@ -72,7 +72,7 @@ for dir in $(ls -1 src | grep -v ^include) ; do
echo else
echo "lib${file}.a.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')"
echo endif
- if grep -F "LIB_DEFS :=" package/targets.mak | grep -qF "$file" ; then
+ if grep -E "^LIB_DEFS [+:]=" package/targets.mak | grep -qF "$file" ; then
echo "lib${file}.so.xyzzy: EXTRA_LIBS :=$libs"
echo "lib${file}.so.xyzzy:$(echo "$deps" | sed 's/\.o/.lo/g')"
else