a34838c553f13f795b8127d3d83947c95900b9be
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.h>
10 #include <common/lockfile.h>
11 #include <common/macros.h>
17 #else /* HAVE_FLOCK */
21 int utils_create_lock_file(const char *filepath
)
29 memset(&lock
, 0, sizeof(lock
));
30 fd
= open(filepath
, O_CREAT
| O_WRONLY
, S_IRUSR
| S_IWUSR
| S_IRGRP
| S_IWGRP
);
32 PERROR("open lock file %s", filepath
);
38 * Attempt to lock the file. If this fails, there is
39 * already a process using the same lock file running
42 lock
.l_whence
= SEEK_SET
;
43 lock
.l_type
= F_WRLCK
;
45 ret
= fcntl(fd
, F_SETLK
, &lock
);
47 PERROR("fcntl lock file");
48 ERR("Could not get lock file %s, another instance is running.", filepath
);
50 PERROR("close lock file");
60 #endif /* HAVE_FLOCK */
This page took 0.030469 seconds and 3 git commands to generate.