aboutsummaryrefslogtreecommitdiff
path: root/lock.c
blob: 9f6ceede690f3581422bebc92a0f72f4fb5119df (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
/* See LICENSE for licence details. */
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdlib.h>

int main(int argc, char **argv){
	if(argc != 2) {
		fprintf(stderr, "Please supply one argument: the lock directory.\n");
		return EXIT_FAILURE;
	}

	if(mkdir(argv[1], S_IRUSR)) {
		if(errno && errno != EEXIST) {
			fprintf(stderr, "Failed to create lock %s.\n", argv[1]);
			return EXIT_FAILURE;
		}
		/* lock exists */
		for(; mkdir(argv[1], S_IRUSR); ) {
			sleep(1);
		}
	}
	return EXIT_SUCCESS;
}