From 724fc63f4736d620173e733a3b35c003a0d82ff8 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Mon, 9 Jan 2023 14:35:54 +0000 Subject: First batch of fixes, more to come >.> Signed-off-by: Laurent Bercot --- src/instance/s6-instance-control.c | 2 +- src/instance/s6-instance-create.c | 4 ++-- src/instance/s6-instance-delete.c | 2 +- src/instance/s6-instance-maker.c | 16 +++++++++------- 4 files changed, 13 insertions(+), 11 deletions(-) (limited to 'src/instance') diff --git a/src/instance/s6-instance-control.c b/src/instance/s6-instance-control.c index 899ab89..badb8b2 100644 --- 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 index 2e97618..40b8a83 100644 --- 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 index fc1337a..37c345c 100644 --- 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 index e70e569..8a82157 100644 --- 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] ; -- cgit 1.4.1