summaryrefslogtreecommitdiff
path: root/src/libs6rc
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-02-08 05:51:44 +0000
committerLaurent Bercot <ska@appnovation.com>2023-02-08 05:51:44 +0000
commit949964fa25c8b4cd088f34ccad636e185a878da5 (patch)
treed62ce0dc0ee013f97763d6f2686b4ec86be828f8 /src/libs6rc
parent5dfb72231ff7ccde35d33d992bfd589ce7bbb367 (diff)
downloads6-rc-949964fa25c8b4cd088f34ccad636e185a878da5.tar.xz
Add instance support to s6-rc-update
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rc')
-rw-r--r--src/libs6rc/s6rc_servicedir_copy_online.c60
1 files changed, 59 insertions, 1 deletions
diff --git a/src/libs6rc/s6rc_servicedir_copy_online.c b/src/libs6rc/s6rc_servicedir_copy_online.c
index 62d7c87..a3fa1f7 100644
--- a/src/libs6rc/s6rc_servicedir_copy_online.c
+++ b/src/libs6rc/s6rc_servicedir_copy_online.c
@@ -6,12 +6,14 @@
#include <unistd.h>
#include <stdio.h>
+#include <skalibs/direntry.h>
#include <skalibs/djbunix.h>
+
#include <s6/servicedir.h>
#include <s6-rc/s6rc-utils.h>
-#include "s6rc-servicedir-internal.h"
#include <s6-rc/s6rc-servicedir.h>
+#include "s6rc-servicedir-internal.h"
int s6rc_servicedir_copy_online (char const *src, char const *dst)
{
@@ -21,6 +23,8 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst)
unsigned int i = 0 ;
int wantup = 0 ;
int e ;
+ struct stat st ;
+ DIR *dir ;
char srcfn[srclen + S6_SERVICEDIR_FILE_MAXLEN + 6] ;
char dstfn[dstlen + S6_SERVICEDIR_FILE_MAXLEN + 6] ;
char oldfn[dstlen + S6_SERVICEDIR_FILE_MAXLEN + 6] ;
@@ -63,6 +67,51 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst)
}
oldfn[dstlen + 4] = 0 ;
rm_rf(oldfn) ;
+
+ /* New files copied, now let's update the instances with the new template */
+
+ memcpy(oldfn + dstlen + 1, "template", 9) ;
+ if (stat(oldfn, &st) == 0)
+ {
+ if (!S_ISDIR(st.st_mode)) { errno = EINVAL ; goto erri ; }
+ memcpy(dstfn + dstlen + 1, "instances", 10) ;
+ dir = opendir(dstfn) ;
+ if (!dir)
+ {
+ mode_t m ;
+ if (errno != ENOENT) goto erri ;
+ m = umask(0) ;
+ if (mkdir(dstfn, 0755) == -1) { umask(m) ; goto erri ; }
+ dstfn[dstlen + 9] = 0 ;
+ if (mkdir(dstfn, 0755) == -1) { umask(m) ; goto erri ; }
+ umask(m) ;
+ }
+ else
+ {
+ dstfn[dstlen + 10] = '/' ;
+ for (;;)
+ {
+ direntry *d ;
+ errno = 0 ;
+ d = readdir(dir) ;
+ if (!d) break ;
+ if (d->d_name[0] == '.')
+ if (((d->d_name[1] == '.') && !d->d_name[2]) || !d->d_name[1])
+ continue ;
+ {
+ size_t len = strlen(d->d_name) ;
+ char ifn[dstlen + 12 + len] ;
+ memcpy(ifn, dstfn, dstlen + 11) ;
+ memcpy(ifn + dstlen + 11, d->d_name, len + 1) ;
+ if (!s6rc_servicedir_copy_online(oldfn, ifn)) goto errd ;
+ }
+ }
+ dir_close(dir) ;
+ if (errno) goto erri ;
+ }
+ }
+ else if (errno != ENOENT) goto erri ;
+
s6rc_servicedir_unblock(dst, wantup) ;
return 1 ;
@@ -80,9 +129,18 @@ int s6rc_servicedir_copy_online (char const *src, char const *dst)
strcpy(oldfn + dstlen + 5, s6rc_servicedir_file_list[i].name) ;
rename(oldfn, dstfn) ;
}
+ s6rc_servicedir_unblock(dst, wantup) ;
errdir:
oldfn[dstlen + 4] = 0 ;
rmdir(oldfn) ;
errno = e ;
return 0 ;
+
+ errd:
+ dir_close(dir) ;
+ erri:
+ e = errno ;
+ s6rc_servicedir_unblock(dst, wantup) ;
+ errno = e ;
+ return 0 ;
}