blob: 03f3755c3ea1c8ed0622a55102e100f54f64b73e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <stdlib.h>
#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 */
}
|