* Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#define _GNU_SOURCE
#define _LGPL_SOURCE
#include <assert.h>
#include <ctype.h>
#include <grp.h>
#include <pwd.h>
#include <sys/file.h>
-#include <dirent.h>
#include <common/common.h>
#include <common/runas.h>
#include <common/compat/getenv.h>
#include <common/compat/string.h>
+#include <common/compat/dirent.h>
#include "utils.h"
#include "defaults.h"
{
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;
* 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)) {
PERROR("Cannot open '%s' path", path);
return -1;
}
- dir_fd = dirfd(dir);
+ dir_fd = lttng_dirfd(dir);
if (dir_fd < 0) {
- PERROR("dirfd");
+ PERROR("lttng_dirfd");
return -1;
}