From 0a3ec350143c95031e5d96fe4a033cfb0772d27f Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Mon, 22 Mar 2010 11:08:34 +0100 Subject: [PATCH] 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: Daniel Lezcano Signed-off-by: Michel Normand --- src/lxc/commands.c | 11 +++++++---- src/lxc/lxc_attach.c | 2 +- src/lxc/start.c | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/lxc/commands.c b/src/lxc/commands.c index fe055ed10..54e182603 100644 --- a/src/lxc/commands.c +++ b/src/lxc/commands.c @@ -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); diff --git a/src/lxc/lxc_attach.c b/src/lxc/lxc_attach.c index 1d3233299..a012c2c6e 100644 --- a/src/lxc/lxc_attach.c +++ b/src/lxc/lxc_attach.c @@ -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; } diff --git a/src/lxc/start.c b/src/lxc/start.c index 4a4755d05..ec084493b 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -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; -- 2.47.2