diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-04 22:35:08 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-12-04 22:35:08 +0000 |
commit | ce6f2000cee65d8cf3875a746815b725d4597c62 (patch) | |
tree | 7ba8615aab45ba45b792be349d730c284b0d9aff /src/libs6/s6_supervise_unlink.c | |
parent | df753171561929de4aa1a6383f01655464e459ae (diff) | |
download | s6-ce6f2000cee65d8cf3875a746815b725d4597c62.tar.xz |
Add s6_supervise_link and s6_supervise_unlink for future s6-rc change
Diffstat (limited to 'src/libs6/s6_supervise_unlink.c')
-rw-r--r-- | src/libs6/s6_supervise_unlink.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libs6/s6_supervise_unlink.c b/src/libs6/s6_supervise_unlink.c new file mode 100644 index 0000000..d4bbe73 --- /dev/null +++ b/src/libs6/s6_supervise_unlink.c @@ -0,0 +1,45 @@ +/* ISC license. */ + +#include <errno.h> +#include <string.h> +#include <unistd.h> +#include <limits.h> + +#include <skalibs/posixplz.h> +#include <skalibs/allreadwrite.h> +#include <skalibs/djbunix.h> + +#include <s6/s6-supervise.h> + +#ifdef PATH_MAX +# define S6_PATH_MAX PATH_MAX +#else +# define S6_PATH_MAX 4096 +#endif + +void s6_supervise_unlink (char const *scandir, char const *name, uint32_t options) +{ + int e = errno ; + int fd = -1 ; + size_t scandirlen = strlen(scandir) ; + size_t namelen = strlen(name) ; + char fn[scandirlen + namelen + sizeof(S6_SUPERVISE_CTLDIR) + 10] ; + memcpy(fn, scandir, scandirlen) ; + fn[scandirlen] = '/' ; + memcpy(fn + scandirlen + 1, name, namelen) ; + if (options & 1) + { + fn[scandirlen + 1 + namelen] = '/' ; + memcpy(fn + scandirlen + 1 + namelen + 1, S6_SUPERVISE_CTLDIR, sizeof(S6_SUPERVISE_CTLDIR) - 1) ; + memcpy(fn + scandirlen + 1 + namelen + sizeof(S6_SUPERVISE_CTLDIR), "/control", 9) ; + fd = open_write(fn) ; + } + fn[scandirlen + 1 + namelen] = 0 ; + unlink_void(fn) ; + if (fd >= 0) + { + fd_write(fd, "xd", 1 + !!(options & 2)) ; + fd_close(fd) ; + } + errno = e ; +} |