diff options
Diffstat (limited to 'lock.c')
-rw-r--r-- | lock.c | 26 |
1 files changed, 7 insertions, 19 deletions
@@ -6,31 +6,19 @@ #include <sys/stat.h> #include <stdlib.h> -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){ + if(argc != 2) { fprintf(stderr, "Please supply one argument: the lock directory.\n"); return EXIT_FAILURE; } - /* create lock */ - if(try_mkdir(argv[1])){ + 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(; try_mkdir(argv[1]); ){ + for(; mkdir(argv[1], S_IRUSR); ) { sleep(1); } } |