diff options
author | Calvin Morrison <mutantturkey@gmail.com> | 2014-04-13 20:30:17 -0400 |
---|---|---|
committer | Calvin Morrison <mutantturkey@gmail.com> | 2014-04-13 20:30:17 -0400 |
commit | 7b4f739fa7c1cc5ab14a60cc96d418d599d9f609 (patch) | |
tree | 57f0e48b137262935906875946be34aaee9b66aa | |
parent | 91ec2c60e80d4c2a81fc942185465954d91d5f7b (diff) |
-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); } } |