summaryrefslogtreecommitdiff
path: root/src
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 /src
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>
Diffstat (limited to 'src')
-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
6 files changed, 78 insertions, 42 deletions
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 } } ;