s6_svstatus_read.c (594B)
1 /* ISC license. */ 2 3 #include <errno.h> 4 #include <string.h> 5 6 #include <skalibs/djbunix.h> 7 #include <s6/supervise.h> 8 9 int s6_svstatus_read (char const *dir, s6_svstatus_t *status) 10 { 11 ssize_t r ; 12 size_t n = strlen(dir) ; 13 char pack[S6_SVSTATUS_SIZE] ; 14 char tmp[n + 1 + sizeof(S6_SVSTATUS_FILENAME)] ; 15 memcpy(tmp, dir, n) ; 16 memcpy(tmp + n, "/" S6_SVSTATUS_FILENAME, 1 + sizeof(S6_SVSTATUS_FILENAME)) ; 17 r = openreadnclose(tmp, pack, S6_SVSTATUS_SIZE) ; 18 if (r == -1) return 0 ; 19 if (r < S6_SVSTATUS_SIZE) return (errno = EPIPE, 0) ; 20 s6_svstatus_unpack(pack, status) ; 21 return 1 ; 22 }