s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 724fc63f4736d620173e733a3b35c003a0d82ff8
parent 09750ce3525129a676dec4f579aea3ad2eca1b19
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Mon,  9 Jan 2023 14:35:54 +0000

 First batch of fixes, more to come >.>

Signed-off-by: Laurent Bercot <ska@appnovation.com>

Diffstat:
Msrc/instance/s6-instance-control.c | 2+-
Msrc/instance/s6-instance-create.c | 4++--
Msrc/instance/s6-instance-delete.c | 2+-
Msrc/instance/s6-instance-maker.c | 16+++++++++-------
Msrc/libs6/s6_auto_write_service.c | 19+++++++++----------
5 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/src/instance/s6-instance-control.c b/src/instance/s6-instance-control.c @@ -62,7 +62,7 @@ int main (int argc, char const **argv) if (argc < 2) dieusage() ; namelen = strlen(argv[1]) ; if (!argv[0][0]) strerr_dief1x(100, "invalid service name") ; - if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], namelen, " \t\f\r\n", 5) < 5) + if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], namelen, " \t\f\r\n", 5) < namelen) strerr_dief1x(100, "invalid instance name") ; { diff --git a/src/instance/s6-instance-create.c b/src/instance/s6-instance-create.c @@ -71,7 +71,7 @@ int main (int argc, char const *const *argv) namelen = strlen(argv[1]) ; if (!argv[0][0]) strerr_dief1x(100, "invalid service path") ; - if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], namelen, " \t\f\r\n", 5) < 5) + if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], namelen, " \t\f\r\n", 5) < namelen) strerr_dief1x(100, "invalid instance name") ; checkinstanced(argv[0]) ; @@ -90,7 +90,7 @@ int main (int argc, char const *const *argv) if (s6_supervise_link_names_g(".", (char const *const *)&sv, argv + 1, 1, options, &tto) == -1) { cleanup(sv) ; - strerr_diefu4sys(errno == ETIMEDOUT ? 99 : 111, "creatre instance of ", argv[0], " named ", argv[1]) ; + strerr_diefu4sys(errno == ETIMEDOUT ? 99 : 111, "create instance of ", argv[0], " named ", argv[1]) ; } } return 0 ; diff --git a/src/instance/s6-instance-delete.c b/src/instance/s6-instance-delete.c @@ -42,7 +42,7 @@ int main (int argc, char const *const *argv) } if (argc < 2) dieusage() ; if (!argv[0][0]) strerr_dief1x(100, "invalid service path") ; - if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], strlen(argv[1]), " \t\f\r\n", 5) < 5) + if (!argv[1][0] || argv[1][0] == '.' || byte_in(argv[1], strlen(argv[1]), " \t\f\r\n", 5) < strlen(argv[1])) strerr_dief1x(100, "invalid instance name") ; tain_now_set_stopwatch_g() ; diff --git a/src/instance/s6-instance-maker.c b/src/instance/s6-instance-maker.c @@ -37,9 +37,9 @@ static int write_run (buffer *b, void *data) size_t l ; char fmt[UINT_FMT] ; l = uint_fmt(fmt, t->maxinstances) ; - if (buffer_puts(b, EXECLINE_EXTBINPREFIX "execlineb -P\n\n" + if (buffer_puts(b, "#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n\n" EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n") < 0) return 0 ; - if (t->user) + if (t->user[0]) { if (!string_quote(&sa, t->user, strlen(t->user))) return 0 ; if (buffer_puts(b, S6_EXTBINPREFIX "s6-setuidgid ") < 0 @@ -61,8 +61,9 @@ static void write_service (char const *dir, char const *template, char const *us { svinfo data = { .user = user, .maxinstances = maxinstances } ; size_t dirlen = strlen(dir) ; - mode_t m = umask(0) ; + mode_t m ; char fn[dirlen + 21] ; + s6_auto_write_service(dir, 3, &write_run, &data, logger) ; memcpy(fn, dir, dirlen) ; memcpy(fn + dirlen, "/instance", 10) ; m = umask(0) ; @@ -73,7 +74,6 @@ static void write_service (char const *dir, char const *template, char const *us memcpy(fn + dirlen + 10, "/.template", 11) ; if (!hiercopy_tmp(template, fn, &sa)) strerr_diefu4sys(111, "copy file hierarchy from ", template, " to ", fn) ; - s6_auto_write_service(dir, 3, &write_run, &data, logger) ; } int main (int argc, char const *const *argv) @@ -151,15 +151,17 @@ int main (int argc, char const *const *argv) dirlen = strlen(argv[1]) ; if (rcinfo[0]) { + mode_t m = umask(0) ; size_t svclen = strlen(rcinfo[0]) ; size_t loglen = rcinfo[1] ? strlen(rcinfo[1]) : 0 ; char dir[dirlen + 2 + (svclen > loglen ? svclen : loglen)] ; memcpy(dir, argv[1], dirlen) ; dir[dirlen] = '/' ; if (mkdir(argv[1], 0755) < 0 && errno != EEXIST) - strerr_diefu2sys(111, "mkdir ", argv[2]) ; + strerr_diefu2sys(111, "mkdir ", argv[1]) ; + umask(m) ; memcpy(dir + dirlen + 1, rcinfo[0], svclen + 1) ; - write_service(dir, user, argv[0], maxinstances, rcinfo[1] ? rcinfo[1] : "") ; + write_service(dir, argv[0], user, maxinstances, rcinfo[1] ? rcinfo[1] : "") ; if (rcinfo[1]) { memcpy(dir + dirlen + 1, rcinfo[1], loglen + 1) ; @@ -168,7 +170,7 @@ int main (int argc, char const *const *argv) } else { - write_service(argv[1], user, argv[0], maxinstances, 0) ; + write_service(argv[1], argv[0], user, maxinstances, 0) ; if (logdir) { char dir[dirlen + 5] ; diff --git a/src/libs6/s6_auto_write_service.c b/src/libs6/s6_auto_write_service.c @@ -22,22 +22,21 @@ void s6_auto_write_service (char const *dir, unsigned int nfd, s6_buffer_writer_ char fn[dirlen + 17] ; if (mkdir(dir, 0755) == -1) strerr_diefu2sys(111, "mkdir ", dir) ; umask(m) ; - m = ~m & 0666 ; memcpy(fn, dir, dirlen) ; - memcpy(fn + dirlen, "/run", 5) ; - fd = open_trunc(fn) ; - if (fd == -1) strerr_diefu2sys(111, "open ", fn) ; - buffer_init(&b, &buffer_write, fd, buf, 4096) ; - if (!(*f)(&b, data)) strerr_diefu2sys(111, "write to ", fn) ; - fd_close(fd) ; if (nfd) { char fmt[UINT_FMT] ; size_t l = uint_fmt(fmt, nfd) ; fmt[l++] = '\n' ; - memcpy(fn + dirlen + 1, "notification-fd", 16) ; + memcpy(fn + dirlen, "/notification-fd", 17) ; if (!openwritenclose_unsafe(fn, fmt, l)) strerr_diefu2sys(111, "write to ", fn) ; } + memcpy(fn + dirlen, "/run", 5) ; + fd = open_trunc(fn) ; + if (fd == -1) strerr_diefu2sys(111, "open ", fn) ; + buffer_init(&b, &buffer_write, fd, buf, 4096) ; + if (!(*f)(&b, data)) strerr_diefu2sys(111, "write to ", fn) ; + fd_close(fd) ; if (logger) { memcpy(fn + dirlen + 1, "type", 5) ; @@ -51,9 +50,9 @@ void s6_auto_write_service (char const *dir, unsigned int nfd, s6_buffer_writer_ } else { - if (chmod(fn, m | ((m >> 2) & 0111)) < 0) + if (chmod(fn, (~m & 0666) | ((~m >> 2) & 0111)) < 0) strerr_diefu2sys(111, "chmod ", fn) ; - if (!(m & 0400)) + if (!(~m & 0400)) strerr_warnw2x("weird umask, check permissions manually on ", fn) ; } }