aboutsummaryrefslogtreecommitdiffstats
path: root/svcok.c
diff options
context:
space:
mode:
authorMarius Halden <marius.h@lden.org>2015-12-02 23:26:13 +0100
committerMarius Halden <marius.h@lden.org>2015-12-02 23:26:13 +0100
commite560b1d1dcf6cbcd75e6bebad55d818e2ea00dbe (patch)
treebf1b5e5d9f9bd8a843f17828f16cd14cc29c0318 /svcok.c
parentf4814a6fa4a9329734113ecadc1415de31bed7dd (diff)
downloadsvcmon-e560b1d1dcf6cbcd75e6bebad55d818e2ea00dbe.tar.gz
svcmon-e560b1d1dcf6cbcd75e6bebad55d818e2ea00dbe.tar.bz2
svcmon-e560b1d1dcf6cbcd75e6bebad55d818e2ea00dbe.tar.xz
Initial svcok
Diffstat (limited to 'svcok.c')
-rw-r--r--svcok.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/svcok.c b/svcok.c
index e69de29..9919f80 100644
--- a/svcok.c
+++ b/svcok.c
@@ -0,0 +1,36 @@
+#include <err.h>
+#include <errno.h>
+#include <sys/file.h>
+#include <unistd.h>
+
+char *dir = ".";
+
+int
+main(int argc, char **argv)
+{
+ int fd;
+
+ if (argc > 1)
+ dir = argv[1];
+
+ if (chdir(dir) == -1)
+ err(1, "chdir()");
+
+ fd = open("supervise/lock", O_RDONLY);
+ if (fd == -1) {
+ if (errno == ENOENT)
+ exit(100);
+ else
+ err(1, "open()");
+ }
+
+ if (flock(fd, LOCK_EX | LOCK_NB) == -1) {
+ if (errno == EWOULDBLOCK)
+ exit(0);
+ else
+ err(1, "flock()");
+ } else
+ exit(100);
+
+ return 0; /* Not reached */
+}