s6

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

commit f72709512d2412c417c15d2a513d3ac1ec342718
parent 370e78d9230d18b260df395e6d437c241b02c93c
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed,  8 Feb 2023 06:40:00 +0000

 Copy the new template, not the old one!

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

Diffstat:
Msrc/libs6/s6_servicedir_instances_recreate_offline_tmp.c | 25+++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)

diff --git a/src/libs6/s6_servicedir_instances_recreate_offline_tmp.c b/src/libs6/s6_servicedir_instances_recreate_offline_tmp.c @@ -18,21 +18,26 @@ int s6_servicedir_instances_recreate_offline_tmp (char const *old, char const *n size_t sabase = sa->len ; size_t oldlen = strlen(old) ; size_t newlen = strlen(new) ; - char templatedir[oldlen + 11] ; - memcpy(templatedir, old, oldlen) ; - memcpy(templatedir + oldlen, "/instances", 11) ; - n = sals(templatedir, sa, &maxlen) ; + + { + char olddir[oldlen + 11] ; + memcpy(olddir, old, oldlen) ; + memcpy(olddir + oldlen, "/instances", 11) ; + n = sals(olddir, sa, &maxlen) ; + } if (n == -1) return errno == ENOENT ? 0 : -1 ; { size_t pos = sabase ; - char olddir[oldlen + 16 + maxlen] ; + char olddir[oldlen + 17 + maxlen] ; + char templatedir[newlen + 10] ; char newsd[newlen + 11 + maxlen] ; char newdir[newlen + 17 + maxlen] ; char lnk[14 + maxlen] ; - memcpy(olddir, templatedir, oldlen + 10) ; - olddir[oldlen + 10] = '/' ; - memcpy(templatedir + oldlen + 1, "template", 9) ; + memcpy(olddir, old, oldlen) ; + memcpy(olddir + oldlen, "/instances/", 11) ; + memcpy(templatedir, new, newlen) ; + memcpy(templatedir + newlen, "/template", 10) ; memcpy(newsd, new, newlen) ; memcpy(newsd + newlen, "/instance", 10) ; memcpy(newdir, newsd, newlen + 9) ; @@ -47,8 +52,8 @@ int s6_servicedir_instances_recreate_offline_tmp (char const *old, char const *n while (pos < sa->len) { size_t len = strlen(sa->s + pos) ; - memcpy(olddir + oldlen + 10, sa->s + pos, len) ; - memcpy(olddir + oldlen + 10 + len, "/down", 6) ; + memcpy(olddir + oldlen + 11, sa->s + pos, len) ; + memcpy(olddir + oldlen + 11 + len, "/down", 6) ; memcpy(newsd + newlen + 10, sa->s + pos, len + 1) ; memcpy(newdir + newlen + 11, sa->s + pos, len + 1) ; memcpy(lnk + 13, sa->s + pos, len + 1) ;