lxclock: cleanup lxcunlock()

parent 952d8f4f
...@@ -221,42 +221,34 @@ int lxclock(struct lxc_lock *l, int timeout) ...@@ -221,42 +221,34 @@ int lxclock(struct lxc_lock *l, int timeout)
int lxcunlock(struct lxc_lock *l) int lxcunlock(struct lxc_lock *l)
{ {
struct flock lk; struct flock lk;
int ret = 0, saved_errno = errno; int ret = 0;
switch (l->type) { switch (l->type) {
case LXC_LOCK_ANON_SEM: case LXC_LOCK_ANON_SEM:
if (!l->u.sem) { if (!l->u.sem)
ret = -2; return -2;
} else {
ret = sem_post(l->u.sem);
saved_errno = errno;
}
ret = sem_post(l->u.sem);
break; break;
case LXC_LOCK_FLOCK: case LXC_LOCK_FLOCK:
if (l->u.f.fd >= 0) { if (l->u.f.fd < 0)
memset(&lk, 0, sizeof(struct flock)); return -2;
lk.l_type = F_UNLCK; memset(&lk, 0, sizeof(struct flock));
lk.l_whence = SEEK_SET;
ret = fcntl(l->u.f.fd, F_OFD_SETLK, &lk); lk.l_type = F_UNLCK;
if (ret < 0) { lk.l_whence = SEEK_SET;
if (errno == EINVAL)
ret = flock(l->u.f.fd, LOCK_EX | LOCK_NB);
saved_errno = errno;
}
close(l->u.f.fd); ret = fcntl(l->u.f.fd, F_OFD_SETLK, &lk);
l->u.f.fd = -1; if (ret < 0 && errno == EINVAL)
} else { ret = flock(l->u.f.fd, LOCK_EX | LOCK_NB);
ret = -2;
}
close_prot_errno_disarm(l->u.f.fd);
break; break;
default:
return ret_set_errno(-1, EINVAL);
} }
errno = saved_errno;
return ret; return ret;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment