From 3d908585178fb8e8b9201931e0d8385a98a78d5c Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Thu, 20 Aug 2020 17:33:39 +0000 Subject: Make flags work on bundles too --- doc/s6-rc-compile.html | 13 +++++++------ src/s6-rc/s6-rc-compile.c | 13 ++++++++++++- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/doc/s6-rc-compile.html b/doc/s6-rc-compile.html index b429e8e..048f6cb 100644 --- a/doc/s6-rc-compile.html +++ b/doc/s6-rc-compile.html @@ -104,6 +104,12 @@ definition directory service is expected to contain the following files oneshot, longrun or bundle, and a terminating newline. This file declares the type of service defined by the directory. +
  • An optional regular file named flag-essential. The contents of this +file are irrelevant, only its presence is tested. If this file exists, the service +will be marked as essential, which means that a s6-rc -d change foo +command will not stop the service. Only a s6-rc -D change foo +command will. If the service is a bundle, the flag will be propagated to all its +contents, i.e. all the services it represents will be marked as essential.
  • For bundles

    @@ -113,7 +119,7 @@ directory. of service names, one per line. Whitespace at the beginning of a line is ignored, but trailing whitespace is not. Lines starting with a # character are ignored. The file defines the services that will be -represented by the bundle named service. +represented by the bundle named service.

    @@ -143,11 +149,6 @@ is ignored, but trailing whitespace is not. Lines starting with a # character are ignored. The file defines the direct dependencies of service, i.e. the services that must be up in order for service to work properly. -

  • An optional regular file named flag-essential. The contents of this -file are irrelevant, only its presence is tested. If this file exists, the service -will be marked as essential, which means that a s6-rc -d change foo -command will not stop the service. Only a s6-rc -D change foo -command will.
  • diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c index f2b6a84..4414ded 100644 --- a/src/s6-rc/s6-rc-compile.c +++ b/src/s6-rc/s6-rc-compile.c @@ -116,6 +116,7 @@ struct bundle_s unsigned int name ; /* pos in data */ unsigned int n ; unsigned int listindex ; /* pos in indices */ + uint32_t annotation_flags ; } ; typedef struct before_s before_t, *before_t_ref ; @@ -351,7 +352,7 @@ static uint32_t read_timeout (int dfd, char const *srcdir, char const *name, cha return timeout ; } -static inline uint32_t read_flags (int dfd, char const *srcdir, char const *name) +static uint32_t read_flags (int dfd, char const *srcdir, char const *name) { static char const *files[32] = { @@ -490,6 +491,7 @@ static inline void add_bundle (before_t *be, int dfd, char const *srcdir, char c add_name(be, srcdir, name, SVTYPE_BUNDLE, &bundle.name, &dummy) ; if (!add_namelist(be, dfd, srcdir, name, "contents", &bundle.listindex, &bundle.n)) strerr_diefu5sys(111, "open ", srcdir, "/", name, "/contents") ; + bundle.annotation_flags = read_flags(dfd, srcdir, name) ; if (!genalloc_append(bundle_t, &be->bundles, &bundle)) dienomem() ; } @@ -689,6 +691,7 @@ static inline unsigned int resolve_bundles (bundle_t const *oldb, bundle_t *newb for (; i < nbundles ; i++) { newb[i].name = oldb[i].name ; + newb[i].annotation_flags = oldb[i].annotation_flags ; recinfo.source = i ; resolve_bundle_rec(&recinfo, i) ; } @@ -899,6 +902,13 @@ static inline void flatlist_services (s6rc_db_t *db, unsigned char const *sarray } } +static inline void propagate_bundle_flags (s6rc_db_t *db, bundle_t const *bundles, unsigned int nbundles, uint32_t const *bdeps) +{ + for (unsigned int i = 0 ; i < nbundles ; i++) + for (unsigned int j = 0 ; j < bundles[i].n ; j++) + db->services[bdeps[bundles[i].listindex + j]].flags |= bundles[i].annotation_flags ; +} + /* Write the compiled database */ @@ -1517,6 +1527,7 @@ int main (int argc, char const *const *argv) uint32_t deps[db.ndeps << 1] ; db.deps = deps ; flatlist_services(&db, sarray) ; + propagate_bundle_flags(&db, bundles, nbundles, bdeps) ; write_compiled(compiled, &db, srcdirs, bundles, nbundles, bdeps, fdhuser, blocking) ; } } -- cgit v1.2.3