5dce37d6fd2f5aa7f5ad1bc763dad987957eb117
2 * Copyright (C) 2012 David Goulet <dgoulet@efficios.com>
3 * Copyright (C) 2013 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * SPDX-License-Identifier: LGPL-2.1-only
9 #include <common/error.hpp>
10 #include <common/lockfile.hpp>
11 #include <common/macros.hpp>
15 #else /* HAVE_FLOCK */
19 int utils_create_lock_file(const char *filepath
)
25 LTTNG_ASSERT(filepath
);
27 memset(&lock
, 0, sizeof(lock
));
28 fd
= open(filepath
, O_CREAT
| O_WRONLY
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
30 PERROR("open lock file %s", filepath
);
36 * Attempt to lock the file. If this fails, there is
37 * already a process using the same lock file running
40 lock
.l_whence
= SEEK_SET
;
41 lock
.l_type
= F_WRLCK
;
43 ret
= fcntl(fd
, F_SETLK
, &lock
);
45 PERROR("fcntl lock file");
46 ERR("Could not get lock file %s, another instance is running.", filepath
);
48 PERROR("close lock file");
58 #endif /* HAVE_FLOCK */
This page took 0.04987 seconds and 4 git commands to generate.