lockfile: Remove force parameter from hold_lock()
If user wants to 'force' a lock, he/she will have to remove the file manually. some wierd race conditions may happen if different processes optains the same lock at any given time (thats why lockfile is implemented in the first place) So lockfile API should not in any circumstances directly provide a way to force taking a lock.
This commit is contained in:
parent
c731173b49
commit
697d512ea6
5 changed files with 9 additions and 16 deletions
|
|
@ -109,13 +109,10 @@ static double get_lock_time(const char *path) {
|
|||
return difftime(time(NULL), st.st_ctime);
|
||||
}
|
||||
|
||||
static int open_lock(const char *path, int force) {
|
||||
static int open_lock(const char *path) {
|
||||
|
||||
int fd, mask = O_WRONLY | O_TRUNC | O_CREAT | O_EXCL;
|
||||
|
||||
if (force)
|
||||
mask &= ~O_EXCL;
|
||||
|
||||
fd = open(path, mask, 0600);
|
||||
if (fd < 0) {
|
||||
/* Force open if lockfile exists
|
||||
|
|
@ -130,7 +127,7 @@ static int open_lock(const char *path, int force) {
|
|||
return fd;
|
||||
}
|
||||
|
||||
int hold_lock(struct lockfile *lock, const char *filename, int force) {
|
||||
int hold_lock(struct lockfile *lock, const char *filename) {
|
||||
|
||||
int rc;
|
||||
|
||||
|
|
@ -143,7 +140,7 @@ int hold_lock(struct lockfile *lock, const char *filename, int force) {
|
|||
if (rc > sizeof(lock->name))
|
||||
return -1;
|
||||
|
||||
lock->fd = open_lock(lock->name, force);
|
||||
lock->fd = open_lock(lock->name);
|
||||
if (lock->fd < 0) {
|
||||
if (errno == EEXIST)
|
||||
return error("'%s' is locked", filename);
|
||||
|
|
|
|||
Reference in a new issue