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
02b4f2e1
Commit
02b4f2e1
authored
Nov 11, 2013
by
Marek Majkowski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow specifying a container by name or pid in --share-net option.
parent
9f30a190
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
47 additions
and
14 deletions
+47
-14
lxc_start.c
src/lxc/lxc_start.c
+47
-14
No files found.
src/lxc/lxc_start.c
View file @
02b4f2e1
...
...
@@ -93,6 +93,48 @@ err:
return
err
;
}
static
int
pid_from_lxcname
(
const
char
*
lxcname_or_pid
,
const
char
*
lxcpath
)
{
char
*
eptr
;
int
pid
=
strtol
(
lxcname_or_pid
,
&
eptr
,
10
);
if
(
*
eptr
!=
'\0'
||
pid
<
1
)
{
struct
lxc_container
*
s
;
s
=
lxc_container_new
(
lxcname_or_pid
,
lxcpath
);
if
(
!
s
)
{
SYSERROR
(
"'%s' is not a valid pid nor a container name"
,
lxcname_or_pid
);
return
-
1
;
}
if
(
!
s
->
may_control
(
s
))
{
SYSERROR
(
"Insufficient privileges to control container '%s'"
,
s
->
name
);
return
-
1
;
}
pid
=
s
->
init_pid
(
s
);
if
(
pid
<
1
)
{
SYSERROR
(
"Is container '%s' running?"
,
s
->
name
);
return
-
1
;
}
}
if
(
kill
(
pid
,
0
)
<
0
)
{
SYSERROR
(
"Can't send signal to pid %d"
,
pid
);
return
-
1
;
}
return
pid
;
}
static
int
open_ns
(
int
pid
,
const
char
*
ns_proc_name
)
{
int
fd
;
char
path
[
MAXPATHLEN
];
snprintf
(
path
,
MAXPATHLEN
,
"/proc/%d/ns/net"
,
pid
);
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
<
0
)
{
SYSERROR
(
"failed to open %s"
,
path
);
return
-
1
;
}
return
fd
;
}
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
switch
(
c
)
{
...
...
@@ -138,7 +180,7 @@ Options :\n\
If not specified, exit with failure instead
\n
\
Note: --daemon implies --close-all-fds
\n
\
-s, --define KEY=VAL Assign VAL to configuration variable KEY
\n
\
--share-net=
PID Share a network namespace with another container
\n
\
--share-net=
NAME Share a network namespace with another container or pid
\n
\
"
,
.
options
=
my_longopts
,
.
parser
=
my_parser
,
...
...
@@ -256,23 +298,14 @@ int main(int argc, char *argv[])
}
if
(
my_args
.
share_net
!=
NULL
)
{
char
*
eptr
;
int
fd
;
int
pid
=
strtol
(
my_args
.
share_net
,
&
eptr
,
10
);
if
(
*
eptr
!=
'\0'
)
{
SYSERROR
(
"'%s' is not a valid pid number"
,
my_args
.
share_net
);
goto
out
;
}
char
path
[
MAXPATHLEN
];
int
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/proc/%d/ns/net"
,
pid
);
if
(
ret
<
0
||
ret
>=
MAXPATHLEN
)
int
pid
=
pid_from_lxcname
(
my_args
.
share_net
,
lxcpath
);
if
(
pid
<
1
)
goto
out
;
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
<
0
)
{
SYSERROR
(
"failed to open %s"
,
path
);
fd
=
open_ns
(
pid
,
"net"
);
if
(
fd
<
0
)
goto
out
;
}
conf
->
inherit_ns_fd
[
LXC_NS_NET
]
=
fd
;
}
...
...
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