Commit 0a3ec350 by Daniel Lezcano Committed by Daniel Lezcano

fix lxc-attach returned error

When we try to attach to a container belonging to another user than us, the command fails as expected but the return code is wrong, so we have an "unknown error" instead of "permission denied". The culprit is: - strerror(command.answer.ret)); + strerror(-command.answer.ret)); The rest of the code is indentation without code impact. Signed-off-by: 's avatarDaniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: 's avatarMichel Normand <normand@fr.ibm.com>
parent 81c75799
......@@ -149,7 +149,7 @@ static int command_handler(int fd, void *data, struct lxc_epoll_descr *descr)
struct lxc_handler *handler = data;
ret = lxc_af_unix_rcv_credential(fd, &request, sizeof(request));
if (ret < 0 && ret == -EACCES) {
if (ret == -EACCES) {
/* we don't care for the peer, just send and close */
struct lxc_answer answer = { .ret = ret };
send(fd, &answer, sizeof(answer), 0);
......@@ -196,7 +196,8 @@ static int incoming_command_handler(int fd, void *data,
return -1;
}
if (setsockopt(connection, SOL_SOCKET, SO_PASSCRED, &opt, sizeof(opt))) {
if (setsockopt(connection, SOL_SOCKET,
SO_PASSCRED, &opt, sizeof(opt))) {
SYSERROR("failed to enable credential on socket");
goto out_close;
}
......@@ -215,7 +216,8 @@ out_close:
goto out;
}
extern int lxc_command_mainloop_add(const char *name, struct lxc_epoll_descr *descr,
extern int lxc_command_mainloop_add(const char *name,
struct lxc_epoll_descr *descr,
struct lxc_handler *handler)
{
int ret, fd;
......@@ -230,7 +232,8 @@ extern int lxc_command_mainloop_add(const char *name, struct lxc_epoll_descr *de
return -1;
}
ret = lxc_mainloop_add_handler(descr, fd, incoming_command_handler, handler);
ret = lxc_mainloop_add_handler(descr, fd, incoming_command_handler,
handler);
if (ret) {
ERROR("failed to add handler for command socket");
close(fd);
......
......@@ -71,7 +71,7 @@ pid_t get_init_pid(const char *name)
if (command.answer.ret) {
ERROR("failed to retrieve the init pid: %s",
strerror(command.answer.ret));
strerror(-command.answer.ret));
return -1;
}
......
......@@ -204,7 +204,8 @@ static int sigchld_handler(int fd, void *data,
return 1;
}
int lxc_pid_callback(int fd, struct lxc_request *request, struct lxc_handler *handler)
int lxc_pid_callback(int fd, struct lxc_request *request,
struct lxc_handler *handler)
{
struct lxc_answer answer;
int 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