Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
bfcedc7e
Unverified
Commit
bfcedc7e
authored
Sep 03, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nl: save errno on lxc_netns_set_nsid()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
7fbb15ec
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
10 deletions
+22
-10
network.c
src/lxc/network.c
+3
-0
nl.c
src/lxc/nl.c
+17
-6
start.c
src/lxc/start.c
+2
-4
No files found.
src/lxc/network.c
View file @
bfcedc7e
...
@@ -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
;
...
...
src/lxc/nl.c
View file @
bfcedc7e
...
@@ -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
,
...
...
src/lxc/start.c
View file @
bfcedc7e
...
@@ -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
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment