ret = pthread_mutex_lock(l);
if (ret != 0) {
- fprintf(stderr, "%s - Failed acquire mutex", strerror(ret));
+ SYSERROR("Failed to acquire mutex");
dump_stacktrace();
_exit(EXIT_FAILURE);
}
ret = pthread_mutex_unlock(l);
if (ret != 0) {
- fprintf(stderr, "%s - Failed to release mutex", strerror(ret));
+ SYSERROR("Failed to release mutex");
dump_stacktrace();
_exit(EXIT_FAILURE);
}
rundir = get_rundir();
if (!rundir)
return NULL;
+
len += strlen(rundir);
if ((dest = malloc(len)) == NULL) {
free(rundir);
return NULL;
}
+
ret = mkdir_p(dest, 0755);
if (ret < 0) {
free(dest);
free(dest);
return NULL;
}
+
return dest;
}
s = malloc(sizeof(*s));
if (!s)
return NULL;
+
ret = sem_init(s, 0, 1);
if (ret) {
free(s);
return NULL;
}
+
return s;
}
free(l);
l = NULL;
}
+
goto out;
}
l = NULL;
goto out;
}
+
l->u.f.fd = -1;
out:
saved_errno = errno;
} else {
struct timespec ts;
+
if (clock_gettime(CLOCK_REALTIME, &ts) == -1) {
ret = -2;
goto out;
}
+
ts.tv_sec += timeout;
ret = sem_timedwait(l->u.sem, &ts);
if (ret < 0)
ERROR("Error: timeout not supported with flock");
goto out;
}
+
if (!l->u.f.fname) {
ERROR("Error: filename not set for flock");
goto out;
}
+
if (l->u.f.fd == -1) {
l->u.f.fd = open(l->u.f.fname, O_CREAT | O_RDWR | O_NOFOLLOW | O_CLOEXEC | O_NOCTTY, S_IWUSR | S_IRUSR);
if (l->u.f.fd == -1) {
goto out;
}
}
+
memset(&lk, 0, sizeof(struct flock));
+
lk.l_type = F_WRLCK;
lk.l_whence = SEEK_SET;
+
ret = fcntl(l->u.f.fd, F_OFD_SETLKW, &lk);
if (ret < 0) {
if (errno == EINVAL)
case LXC_LOCK_FLOCK:
if (l->u.f.fd != -1) {
memset(&lk, 0, sizeof(struct flock));
+
lk.l_type = F_UNLCK;
lk.l_whence = SEEK_SET;
+
ret = fcntl(l->u.f.fd, F_OFD_SETLK, &lk);
if (ret < 0) {
if (errno == EINVAL)
ret = flock(l->u.f.fd, LOCK_EX | LOCK_NB);
saved_errno = errno;
}
+
close(l->u.f.fd);
l->u.f.fd = -1;
} else
{
if (!l)
return;
+
switch(l->type) {
case LXC_LOCK_ANON_SEM:
if (l->u.sem) {
close(l->u.f.fd);
l->u.f.fd = -1;
}
+
free(l->u.f.fname);
l->u.f.fname = NULL;
break;
if ((ret = lxclock(c->privlock, 0)))
return ret;
+
if ((ret = lxclock(c->slock, 0))) {
lxcunlock(c->privlock);
return ret;
}
+
return 0;
}