Commit | Line | Data |
---|---|---|
a0c21c7b C |
1 | /* lock.c 4.3 81/11/29 */ |
2 | #include "tip.h" | |
3 | ||
4 | #ifdef ACULOG | |
5 | /* | |
6 | * Locking mechanism for files | |
7 | */ | |
8 | ||
9 | static int fd = -1; | |
10 | ||
11 | lock(f) | |
12 | char *f; | |
13 | { | |
14 | int timeout = 0; | |
15 | ||
16 | while ((fd = creat(f, 0444)) < 0) { | |
17 | if (++timeout == 6) | |
18 | break; | |
19 | sleep(5); | |
20 | } | |
21 | if (timeout == 6 && fd >= 0) | |
22 | unlock(); | |
23 | else | |
24 | unlink(f); | |
25 | return (fd >= 0); | |
26 | } | |
27 | ||
28 | unlock() | |
29 | { | |
30 | if (fd != -1) | |
31 | close(fd); | |
32 | fd = -1; | |
33 | } | |
34 | #endif |