diff options
author | Gluster Ant <bugzilla-bot@gluster.org> | 2018-09-12 17:52:45 +0530 |
---|---|---|
committer | Nigel Babu <nigelb@redhat.com> | 2018-09-12 17:52:45 +0530 |
commit | e16868dede6455cab644805af6fe1ac312775e13 (patch) | |
tree | 15aebdb4fff2d87cf8a72f836816b3aa634da58d /tests/basic/tier | |
parent | 45a71c0548b6fd2c757aa2e7b7671a1411948894 (diff) |
Land part 2 of clang-format changes
Change-Id: Ia84cc24c8924e6d22d02ac15f611c10e26db99b4
Signed-off-by: Nigel Babu <nigelb@redhat.com>
Diffstat (limited to 'tests/basic/tier')
-rw-r--r-- | tests/basic/tier/file_lock.c | 127 |
1 files changed, 62 insertions, 65 deletions
diff --git a/tests/basic/tier/file_lock.c b/tests/basic/tier/file_lock.c index 730cca92e42..20fdbc0f668 100644 --- a/tests/basic/tier/file_lock.c +++ b/tests/basic/tier/file_lock.c @@ -3,73 +3,70 @@ #include <unistd.h> #include <fcntl.h> - -void usage (void) +void +usage(void) { - - printf ("Usage: testlock <filepath> [R|W]\n"); - return; + printf("Usage: testlock <filepath> [R|W]\n"); + return; } - -int main (int argc, char *argv[]) +int +main(int argc, char *argv[]) { - char *file_path = NULL; - int fd = -1; - struct flock lock = {0}; - int ret = -1; - int c = 0; - - if (argc != 3) { - usage (); - exit (1); - } - - file_path = argv[1]; - fd = open (file_path, O_RDWR); - - if (-1 == fd) { - printf ("Failed to open file %s. %m\n", file_path); - exit (1); - } - - /* TODO: Check for invalid input*/ - - if (!strcmp (argv[2], "W")) { - lock.l_type = F_WRLCK; - printf("Taking write lock\n"); - - } else { - lock.l_type = F_RDLCK; - printf("Taking read lock\n"); - } - - lock.l_whence = SEEK_SET; - lock.l_start = 0; - lock.l_len = 0; - lock.l_pid = getpid (); - - - printf ("Acquiring lock on %s\n", file_path); - ret = fcntl (fd, F_SETLK, &lock); - if (ret) { - printf ("Failed to acquire lock on %s (%m)\n", file_path); - close (fd); - exit (1); - } - - sleep(10); - - /*Unlock*/ - - printf ("Releasing lock on %s\n", file_path); - lock.l_type = F_UNLCK; - ret = fcntl (fd, F_SETLK, &lock); - if (ret) { - printf ("Failed to release lock on %s (%m)\n", file_path); - } - - close (fd); - return ret; - + char *file_path = NULL; + int fd = -1; + struct flock lock = {0}; + int ret = -1; + int c = 0; + + if (argc != 3) { + usage(); + exit(1); + } + + file_path = argv[1]; + fd = open(file_path, O_RDWR); + + if (-1 == fd) { + printf("Failed to open file %s. %m\n", file_path); + exit(1); + } + + /* TODO: Check for invalid input*/ + + if (!strcmp(argv[2], "W")) { + lock.l_type = F_WRLCK; + printf("Taking write lock\n"); + + } else { + lock.l_type = F_RDLCK; + printf("Taking read lock\n"); + } + + lock.l_whence = SEEK_SET; + lock.l_start = 0; + lock.l_len = 0; + lock.l_pid = getpid(); + + printf("Acquiring lock on %s\n", file_path); + ret = fcntl(fd, F_SETLK, &lock); + if (ret) { + printf("Failed to acquire lock on %s (%m)\n", file_path); + close(fd); + exit(1); + } + + sleep(10); + + /*Unlock*/ + + printf("Releasing lock on %s\n", file_path); + lock.l_type = F_UNLCK; + ret = fcntl(fd, F_SETLK, &lock); + if (ret) { + printf("Failed to release lock on %s (%m)\n", file_path); + } + + close(fd); + return ret; } |