From 7b4f739fa7c1cc5ab14a60cc96d418d599d9f609 Mon Sep 17 00:00:00 2001 From: Calvin Morrison Date: Sun, 13 Apr 2014 20:30:17 -0400 Subject: don't error check, that's up to the user, might actually be a feature --- lock.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'lock.c') diff --git a/lock.c b/lock.c index 871425d..9f6ceed 100644 --- a/lock.c +++ b/lock.c @@ -6,31 +6,19 @@ #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){ + 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); } } -- cgit v1.2.3