From: Michael Jeanson Date: Wed, 14 Oct 2015 20:11:48 +0000 (-0400) Subject: Port: Replace flock with fnctl X-Git-Tag: v2.8.0-rc1~273 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=77e7fddf47ca285c4d4d161745ddaf2bca6b46b2;hp=e4107a103bf91707d46bca4f657ee94017cd97bc Port: Replace flock with fnctl Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- diff --git a/src/common/utils.c b/src/common/utils.c index ca4eb4448..52fb25dbe 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -504,11 +504,13 @@ int utils_create_lock_file(const char *filepath) { int ret; int fd; + struct flock lock; assert(filepath); - fd = open(filepath, O_CREAT, - O_WRONLY | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP); + memset(&lock, 0, sizeof(lock)); + fd = open(filepath, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | + S_IRGRP | S_IWGRP); if (fd < 0) { PERROR("open lock file %s", filepath); ret = -1; @@ -520,8 +522,12 @@ int utils_create_lock_file(const char *filepath) * already a process using the same lock file running * and we should exit. */ - ret = flock(fd, LOCK_EX | LOCK_NB); - if (ret) { + lock.l_whence = SEEK_SET; + lock.l_type = F_WRLCK; + + ret = fcntl(fd, F_SETLK, &lock); + if (ret == -1) { + PERROR("fcntl lock file"); ERR("Could not get lock file %s, another instance is running.", filepath); if (close(fd)) {