aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6rc
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2025-06-18 15:50:50 +0000
committerLaurent Bercot <ska@appnovation.com>2025-06-18 15:50:50 +0000
commit4fca7a92b9eeaba9c327ca8b257b224c5c03e79b (patch)
treeac1cfe138b00bcc9ad8e6c806ca37109a42f3f54 /src/libs6rc
parent04cf7b22ae8b071287f70579a712d4fa17c3dabb (diff)
downloads6-rc-4fca7a92b9eeaba9c327ca8b257b224c5c03e79b.tar.gz
Add s6rc_live_state functions
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/libs6rc')
-rw-r--r--src/libs6rc/deps-lib/s6rc2
-rw-r--r--src/libs6rc/s6rc_live_state_read.c23
-rw-r--r--src/libs6rc/s6rc_live_state_size.c30
3 files changed, 55 insertions, 0 deletions
diff --git a/src/libs6rc/deps-lib/s6rc b/src/libs6rc/deps-lib/s6rc
index 5dbb4de..3b0bf75 100644
--- a/src/libs6rc/deps-lib/s6rc
+++ b/src/libs6rc/deps-lib/s6rc
@@ -5,6 +5,8 @@ s6rc_db_read.o
s6rc_db_read_sizes.o
s6rc_db_read_uint32.o
s6rc_graph_closure.o
+s6rc_live_state_size.o
+s6rc_live_state_read.o
s6rc_livedir_canon.o
s6rc_livedir_create.o
s6rc_livedir_prefix.o
diff --git a/src/libs6rc/s6rc_live_state_read.c b/src/libs6rc/s6rc_live_state_read.c
new file mode 100644
index 0000000..592d08b
--- /dev/null
+++ b/src/libs6rc/s6rc_live_state_read.c
@@ -0,0 +1,23 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+#include <errno.h>
+
+#include <skalibs/djbunix.h>
+
+#include <s6-rc/s6rc-db.h>
+#include <s6-rc/s6rc-utils.h>
+
+int s6rc_live_state_read (char const *live, unsigned char *state, uint32_t n)
+{
+ size_t livelen = strlen(live) ;
+ char fn[livelen + 7] ;
+ memcpy(fn, live, livelen) ;
+ memcpy(fn + livelen, "/state", n) ;
+ ssize_t r = openreadnclose(fn, (char *)state, n) ;
+ if (r == -1) return 0 ;
+ if (r < n) return (errno = EINVAL, 0) ;
+ for (uint32_t i = 0 ; i < n ; i++) state[i] &= 1 ;
+ return 1 ;
+}
diff --git a/src/libs6rc/s6rc_live_state_size.c b/src/libs6rc/s6rc_live_state_size.c
new file mode 100644
index 0000000..3dd8b67
--- /dev/null
+++ b/src/libs6rc/s6rc_live_state_size.c
@@ -0,0 +1,30 @@
+/* ISC license. */
+
+#include <stdint.h>
+#include <string.h>
+
+#include <skalibs/djbunix.h>
+
+#include <s6-rc/s6rc-db.h>
+#include <s6-rc/s6rc-utils.h>
+
+int s6rc_live_state_size (char const *live, uint32_t *nlong, uint32_t *nshort)
+{
+ s6rc_db_t db ;
+ int fd ;
+ size_t livelen = strlen(live) ;
+ char fn[livelen + 10] ;
+ memcpy(fn, live, livelen) ;
+ memcpy(fn + livelen, "/compiled", 10) ;
+ fd = openc_readb(fn) ;
+ if (fd == -1) return 0 ;
+ if (!s6rc_db_read_sizes(fd, &db))
+ {
+ fd_close(fd) ;
+ return 0 ;
+ }
+ fd_close(fd) ;
+ *nlong = db.nlong ;
+ *nshort = db.nshort ;
+ return 1 ;
+}