nl: save errno on lxc_netns_set_nsid()

parent 7fbb15ec
...@@ -3203,6 +3203,7 @@ int lxc_netns_set_nsid(int fd) ...@@ -3203,6 +3203,7 @@ int lxc_netns_set_nsid(int fd)
struct nl_handler nlh; struct nl_handler nlh;
struct nlmsghdr *hdr; struct nlmsghdr *hdr;
struct rtgenmsg *msg; struct rtgenmsg *msg;
int saved_errno;
__s32 ns_id = -1; __s32 ns_id = -1;
__u32 netns_fd = fd; __u32 netns_fd = fd;
...@@ -3225,7 +3226,9 @@ int lxc_netns_set_nsid(int fd) ...@@ -3225,7 +3226,9 @@ int lxc_netns_set_nsid(int fd)
addattr(hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id)); addattr(hdr, 1024, __LXC_NETNSA_NSID, &ns_id, sizeof(ns_id));
ret = __netlink_transaction(&nlh, hdr, hdr); ret = __netlink_transaction(&nlh, hdr, hdr);
saved_errno = errno;
netlink_close(&nlh); netlink_close(&nlh);
errno = saved_errno;
if (ret < 0) if (ret < 0)
return -1; return -1;
......
...@@ -20,6 +20,9 @@ ...@@ -20,6 +20,9 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include "config.h"
#include <sys/socket.h> #include <sys/socket.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
...@@ -30,8 +33,11 @@ ...@@ -30,8 +33,11 @@
#include <linux/netlink.h> #include <linux/netlink.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
#include "log.h"
#include "nl.h" #include "nl.h"
lxc_log_define(nl, lxc);
extern size_t nlmsg_len(const struct nlmsg *nlmsg) extern size_t nlmsg_len(const struct nlmsg *nlmsg)
{ {
return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN; return nlmsg->nlmsghdr->nlmsg_len - NLMSG_HDRLEN;
...@@ -201,8 +207,10 @@ again: ...@@ -201,8 +207,10 @@ again:
if (!ret) if (!ret)
return 0; return 0;
if (msg.msg_flags & MSG_TRUNC && (ret == nlmsghdr->nlmsg_len)) if (msg.msg_flags & MSG_TRUNC && (ret == nlmsghdr->nlmsg_len)) {
return -EMSGSIZE; errno = EMSGSIZE;
ret = -1;
}
return ret; return ret;
} }
...@@ -252,18 +260,21 @@ extern int __netlink_transaction(struct nl_handler *handler, ...@@ -252,18 +260,21 @@ extern int __netlink_transaction(struct nl_handler *handler,
ret = __netlink_send(handler, request); ret = __netlink_send(handler, request);
if (ret < 0) if (ret < 0)
return ret; return -1;
ret = __netlink_recv(handler, answer); ret = __netlink_recv(handler, answer);
if (ret < 0) if (ret < 0)
return ret; return -1;
ret = 0;
if (answer->nlmsg_type == NLMSG_ERROR) { if (answer->nlmsg_type == NLMSG_ERROR) {
struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(answer); struct nlmsgerr *err = (struct nlmsgerr *)NLMSG_DATA(answer);
return err->error; errno = -err->error;
if (err->error < 0)
ret = -1;
} }
return 0; return ret;
} }
extern int netlink_transaction(struct nl_handler *handler, extern int netlink_transaction(struct nl_handler *handler,
......
...@@ -1789,13 +1789,11 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1789,13 +1789,11 @@ static int lxc_spawn(struct lxc_handler *handler)
DEBUG("Preserved net namespace via fd %d", ret); DEBUG("Preserved net namespace via fd %d", ret);
ret = lxc_netns_set_nsid(handler->nsfd[LXC_NS_NET]); ret = lxc_netns_set_nsid(handler->nsfd[LXC_NS_NET]);
if (ret < 0) { if (ret < 0)
errno = -ret;
SYSERROR("Failed to allocate new network namespace id"); SYSERROR("Failed to allocate new network namespace id");
} else { else
TRACE("Allocated new network namespace id"); TRACE("Allocated new network namespace id");
} }
}
/* Create the network configuration. */ /* Create the network configuration. */
if (handler->ns_clone_flags & CLONE_NEWNET) { if (handler->ns_clone_flags & CLONE_NEWNET) {
......
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