lxclock: change error log using strerror to SYSERROR

Signed-off-by: 2xsec <dh48.jeong@samsung.com>
This commit is contained in:
2xsec 2018-07-13 21:33:09 +09:00
parent 7437036726
commit 79cda71dc9
No known key found for this signature in database
GPG Key ID: 0BE2750EE612F372

View File

@ -75,7 +75,7 @@ static void lock_mutex(pthread_mutex_t *l)
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);
}
@ -87,7 +87,7 @@ static void unlock_mutex(pthread_mutex_t *l)
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);
}
@ -111,6 +111,7 @@ static char *lxclock_name(const char *p, const char *n)
rundir = get_rundir();
if (!rundir)
return NULL;
len += strlen(rundir);
if ((dest = malloc(len)) == NULL) {
@ -124,6 +125,7 @@ static char *lxclock_name(const char *p, const char *n)
free(rundir);
return NULL;
}
ret = mkdir_p(dest, 0755);
if (ret < 0) {
free(dest);
@ -137,6 +139,7 @@ static char *lxclock_name(const char *p, const char *n)
free(dest);
return NULL;
}
return dest;
}
@ -148,11 +151,13 @@ static sem_t *lxc_new_unnamed_sem(void)
s = malloc(sizeof(*s));
if (!s)
return NULL;
ret = sem_init(s, 0, 1);
if (ret) {
free(s);
return NULL;
}
return s;
}
@ -171,6 +176,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
free(l);
l = NULL;
}
goto out;
}
@ -181,6 +187,7 @@ struct lxc_lock *lxc_newlock(const char *lxcpath, const char *name)
l = NULL;
goto out;
}
l->u.f.fd = -1;
out:
@ -200,10 +207,12 @@ int lxclock(struct lxc_lock *l, int timeout)
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)
@ -216,10 +225,12 @@ int lxclock(struct lxc_lock *l, int timeout)
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) {
@ -228,9 +239,12 @@ int lxclock(struct lxc_lock *l, int timeout)
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)
@ -262,14 +276,17 @@ int lxcunlock(struct lxc_lock *l)
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
@ -292,6 +309,7 @@ void lxc_putlock(struct lxc_lock *l)
{
if (!l)
return;
switch(l->type) {
case LXC_LOCK_ANON_SEM:
if (l->u.sem) {
@ -305,6 +323,7 @@ void lxc_putlock(struct lxc_lock *l)
close(l->u.f.fd);
l->u.f.fd = -1;
}
free(l->u.f.fname);
l->u.f.fname = NULL;
break;
@ -338,10 +357,12 @@ int container_disk_lock(struct lxc_container *c)
if ((ret = lxclock(c->privlock, 0)))
return ret;
if ((ret = lxclock(c->slock, 0))) {
lxcunlock(c->privlock);
return ret;
}
return 0;
}