projects
/
project
/
firewall3.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
utils: implement fw3_lock_path() & fw3_unlock_path()
[project/firewall3.git]
/
utils.c
diff --git
a/utils.c
b/utils.c
index b465878a71f2bfc4cb3f872fbf23b5d28aec4766..5aa7d5531727ec5b6d37e01b07ebd9ebd71712f7 100644
(file)
--- a/
utils.c
+++ b/
utils.c
@@
-28,7
+28,7
@@
#include "ipsets.h"
#include "ipsets.h"
-static int lock_fd = -1;
+static int
fw3_
lock_fd = -1;
static pid_t pipe_pid = -1;
static FILE *pipe_fd = NULL;
static pid_t pipe_pid = -1;
static FILE *pipe_fd = NULL;
@@
-346,13
+346,13
@@
fw3_has_table(bool ipv6, const char *table)
bool
bool
-fw3_lock
(void
)
+fw3_lock
_path(int *fd, const char *path
)
{
{
-
lock_fd = open(FW3_LOCKFILE
, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
+
int lock_fd = open(path
, O_CREAT|O_WRONLY, S_IRUSR|S_IWUSR);
if (lock_fd < 0)
{
if (lock_fd < 0)
{
- warn("Cannot create lock file %s: %s",
FW3_LOCKFILE
, strerror(errno));
+ warn("Cannot create lock file %s: %s",
path
, strerror(errno));
return false;
}
return false;
}
@@
-362,22
+362,38
@@
fw3_lock(void)
return false;
}
return false;
}
+ *fd = lock_fd;
+
return true;
}
return true;
}
+bool
+fw3_lock()
+{
+ return fw3_lock_path(&fw3_lock_fd, FW3_LOCKFILE);
+}
+
+
void
void
-fw3_unlock
(void
)
+fw3_unlock
_path(int *fd, const char *lockpath
)
{
{
- if (
lock_
fd < 0)
+ if (
*
fd < 0)
return;
return;
- if (flock(
lock_
fd, LOCK_UN))
+ if (flock(
*
fd, LOCK_UN))
warn("Cannot release exclusive lock: %s", strerror(errno));
warn("Cannot release exclusive lock: %s", strerror(errno));
- close(
lock_
fd);
+ close(
*
fd);
unlink(FW3_LOCKFILE);
unlink(FW3_LOCKFILE);
- lock_fd = -1;
+ *fd = -1;
+}
+
+
+void
+fw3_unlock(void)
+{
+ fw3_unlock_path(&fw3_lock_fd, FW3_LOCKFILE);
}
}