summaryrefslogtreecommitdiff
path: root/src/libs6rc
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2021-06-28 17:26:47 +0000
committerLaurent Bercot <ska@appnovation.com>2021-06-28 17:26:47 +0000
commitae1a76cad535a04f0c059e8dae9c8a27a84222a4 (patch)
tree91648546a5c588a5f0e68ef530d311e594440f4e /src/libs6rc
parentc26824e1f078b8de0d38cb87d3f291235ab5cf76 (diff)
downloads6-rc-ae1a76cad535a04f0c059e8dae9c8a27a84222a4.tar.xz
Some more code around state
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rc')
-rw-r--r--src/libs6rc/s6rc_service_common.c19
-rw-r--r--src/libs6rc/s6rc_service_resolve.c33
2 files changed, 52 insertions, 0 deletions
diff --git a/src/libs6rc/s6rc_service_common.c b/src/libs6rc/s6rc_service_common.c
new file mode 100644
index 0000000..f3146be
--- /dev/null
+++ b/src/libs6rc/s6rc_service_common.c
@@ -0,0 +1,19 @@
+/* ISC license. */
+
+#include <stdint.h>
+
+#include <s6-rc/db.h>
+
+s6rc_common_t const *s6rc_service_common (s6rc_db_t const *db, s6rc_sid_t const *id)
+{
+ uint32_t i = id->i + (id->param ? db->n[id->stype] : 0) ;
+ switch (id->stype)
+ {
+ case STYPE_LONGRUN : return &db->longruns[i].common ;
+ case STYPE_ONESHOT : return &db->oneshots[i].common ;
+ case STYPE_EXTERNAL : return &db->externals[i].common ;
+ case STYPE_BUNDLE : return &db->bundles[i].common ;
+ case STYPE_VIRTUAL : return &db->virtuals[i].common ;
+ default : return 0 ;
+ }
+}
diff --git a/src/libs6rc/s6rc_service_resolve.c b/src/libs6rc/s6rc_service_resolve.c
new file mode 100644
index 0000000..858f67c
--- /dev/null
+++ b/src/libs6rc/s6rc_service_resolve.c
@@ -0,0 +1,33 @@
+/* ISC license. */
+
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/uint32.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/cdb.h>
+
+#include <s6-rc/db.h>
+
+int s6rc_service_resolve (cdb_t *c, s6rc_sid_t *id, char const *s)
+{
+ size_t len = strlen(s) ;
+ char const *param = 0 ;
+ char pack[5] ;
+ int r = cdb_find(c, s, len) ;
+ if (r < 0) return r ;
+ if (!r)
+ {
+ size_t at = byte_chr(s, len, '@') ;
+ if (at == len) return 0 ;
+ if (at == len - 1) return (errno = EINVAL, -1) ;
+ r = cdb_find(c, s, at + 1) ;
+ if (r <= 0) return r ;
+ param = s + at + 1 ;
+ }
+ if (cdb_read(c, pack, 5, cdb_datapos(c)) < 0) return -1 ;
+ id->stype = pack[0] ;
+ uint32_unpack_big(pack + 1, &id->i) ;
+ id->param = param ;
+ return 1 ;
+}