aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs6rc/s6rc_live_state_read.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs6rc/s6rc_live_state_read.c')
-rw-r--r--src/libs6rc/s6rc_live_state_read.c23
1 files changed, 23 insertions, 0 deletions
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 ;
+}