From e560b1d1dcf6cbcd75e6bebad55d818e2ea00dbe Mon Sep 17 00:00:00 2001 From: Marius Halden Date: Wed, 2 Dec 2015 23:26:13 +0100 Subject: Initial svcok --- .gitignore | 3 +++ svcok.c | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/.gitignore b/.gitignore index 5394ff2..9d030c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ svcscan svcsupervise +svcok +svcstat +svctl *.o svc diff --git a/svcok.c b/svcok.c index e69de29..9919f80 100644 --- a/svcok.c +++ b/svcok.c @@ -0,0 +1,36 @@ +#include +#include +#include +#include + +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 */ +} -- cgit v1.2.3