/* See LICENSE for licence details. */ #include #include #include #include #include #include int try_mkdir(const char *dn) { int ret; errno = 0; ret = 0; ret = mkdir(dn, S_IRUSR); if(errno && errno != EEXIST) { fprintf(stderr, "Failed to create lock %s.\n", dn); exit(EXIT_FAILURE); } return ret; } int main(int argc, char **argv){ if(argc != 2){ fprintf(stderr, "Please supply one argument: the lock directory.\n"); return EXIT_FAILURE; } /* create lock */ if(try_mkdir(argv[1])){ /* lock exists */ for(; try_mkdir(argv[1]); ){ sleep(1); } } return EXIT_SUCCESS; }