X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fcommon%2Futils.c;h=b9af7b9da4d9c189e204ad7c91c12cb08c67f4b0;hb=790c779e5d45e5ea024c221e60d3dd2277a7b7b9;hp=ca4eb44481c7d3e7fc90500c91112f50aaacef09;hpb=7a946bebe4a23b07f257906b90c88fed383835aa;p=lttng-tools.git diff --git a/src/common/utils.c b/src/common/utils.c index ca4eb4448..b9af7b9da 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -17,7 +17,6 @@ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ -#define _GNU_SOURCE #define _LGPL_SOURCE #include #include @@ -504,11 +503,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 +521,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)) {