diff options
| author | Laurent Bercot <ska-skaware@skarnet.org> | 2021-06-29 00:16:10 +0000 |
|---|---|---|
| committer | Laurent Bercot <ska@appnovation.com> | 2021-06-29 00:16:10 +0000 |
| commit | 4c1d58b509c83ff788fe1ad6b5bdd1073977622c (patch) | |
| tree | 2788fa5a734ec40a0a3690846189090ff629ecba /src/libs6rcd/s6rc_service_resolve.c | |
| parent | 4b057ce275a2761656b62a3fa1e57ebf934c3af8 (diff) | |
| download | s6-rc-4c1d58b509c83ff788fe1ad6b5bdd1073977622c.tar.gz | |
Some work on the db representation
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rcd/s6rc_service_resolve.c')
| -rw-r--r-- | src/libs6rcd/s6rc_service_resolve.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libs6rcd/s6rc_service_resolve.c b/src/libs6rcd/s6rc_service_resolve.c new file mode 100644 index 0000000..a786542 --- /dev/null +++ b/src/libs6rcd/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 "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 ; +} |
