about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-02-08 06:40:00 +0000
committerLaurent Bercot <ska@appnovation.com>2023-02-08 06:40:00 +0000
commitf72709512d2412c417c15d2a513d3ac1ec342718 (patch)
tree28702ea2d2483eb35a31bc2e00e3bacbe31e2067 /src
parent370e78d9230d18b260df395e6d437c241b02c93c (diff)
downloads6-f72709512d2412c417c15d2a513d3ac1ec342718.tar.gz
s6-f72709512d2412c417c15d2a513d3ac1ec342718.tar.xz
s6-f72709512d2412c417c15d2a513d3ac1ec342718.zip
Copy the new template, not the old one!
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs6/s6_servicedir_instances_recreate_offline_tmp.c25
1 files 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
index b6a7ddb..0379dad 100644
--- 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) ;