aboutsummaryrefslogtreecommitdiffstats
path: root/src/repo/s6rc_repo_lock.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/repo/s6rc_repo_lock.c')
-rw-r--r--src/repo/s6rc_repo_lock.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/repo/s6rc_repo_lock.c b/src/repo/s6rc_repo_lock.c
new file mode 100644
index 0000000..472ff15
--- /dev/null
+++ b/src/repo/s6rc_repo_lock.c
@@ -0,0 +1,20 @@
+/* ISC license. */
+
+#include <string.h>
+
+#include <skalibs/djbunix.h>
+
+#include <s6-rc/repo.h>
+
+int s6rc_repo_lock (char const *repo, int w)
+{
+ int fd ;
+ size_t repolen = strlen(repo) ;
+ char fn[repolen + 13] ;
+ memcpy(fn, repo, repolen) ;
+ memcpy(fn + repolen, "/lock", 6) ;
+ fd = openc_write(fn) ;
+ if (fd == -1) return -1 ;
+ if (fd_lock(fd, w, 0) < 1) return -1 ;
+ return fd ;
+}