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
dea1cfbd
Commit
dea1cfbd
authored
Nov 22, 2016
by
Stéphane Graber
Committed by
GitHub
Nov 22, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1312 from brauner/2016-11-22/fix_lxc_unshare_parsing
tools: replace non-standard namespace identifiers
parents
70c9390e
9420e0c2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
4 deletions
+52
-4
lxc_attach.c
src/lxc/tools/lxc_attach.c
+26
-0
lxc_unshare.c
src/lxc/tools/lxc_unshare.c
+26
-4
No files found.
src/lxc/tools/lxc_attach.c
View file @
dea1cfbd
...
@@ -107,6 +107,8 @@ static int add_to_simple_array(char ***array, ssize_t *capacity, char *value)
...
@@ -107,6 +107,8 @@ static int add_to_simple_array(char ***array, ssize_t *capacity, char *value)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
static
int
my_parser
(
struct
lxc_arguments
*
args
,
int
c
,
char
*
arg
)
{
{
char
**
it
;
char
*
del
;
int
ret
;
int
ret
;
switch
(
c
)
{
switch
(
c
)
{
...
@@ -125,6 +127,30 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
...
@@ -125,6 +127,30 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
break
;
break
;
case
's'
:
case
's'
:
namespace_flags
=
0
;
namespace_flags
=
0
;
/* The identifiers for namespaces used with lxc-attach as given
* on the manpage do not align with the standard identifiers.
* This affects network, mount, and uts namespaces. The standard
* identifiers are: "mnt", "uts", and "net" whereas lxc-attach
* uses "MOUNT", "UTSNAME", and "NETWORK". So let's use some
* cheap memmove()s to replace them by their standard
* identifiers. Let's illustrate this with an example:
* Assume the string:
*
* "IPC|MOUNT|PID"
*
* then we memmove()
*
* dest: del + 1 == ONT|PID
* src: del + 3 == NT|PID
*/
while
((
del
=
strstr
(
arg
,
"MOUNT"
)))
memmove
(
del
+
1
,
del
+
3
,
strlen
(
del
)
-
2
);
for
(
it
=
(
char
*
[]){
"NETWORK"
,
"UTSNAME"
,
NULL
};
it
&&
*
it
;
it
++
)
while
((
del
=
strstr
(
arg
,
*
it
)))
memmove
(
del
+
3
,
del
+
7
,
strlen
(
del
)
-
6
);
ret
=
lxc_fill_namespace_flags
(
arg
,
&
namespace_flags
);
ret
=
lxc_fill_namespace_flags
(
arg
,
&
namespace_flags
);
if
(
ret
)
if
(
ret
)
return
-
1
;
return
-
1
;
...
...
src/lxc/tools/lxc_unshare.c
View file @
dea1cfbd
...
@@ -76,7 +76,7 @@ static void usage(char *cmd)
...
@@ -76,7 +76,7 @@ static void usage(char *cmd)
fprintf
(
stderr
,
"
\t
-i <iface> : Interface name to be moved into container (presumably with NETWORK unsharing set)
\n
"
);
fprintf
(
stderr
,
"
\t
-i <iface> : Interface name to be moved into container (presumably with NETWORK unsharing set)
\n
"
);
fprintf
(
stderr
,
"
\t
-H <hostname>: Set the hostname in the container
\n
"
);
fprintf
(
stderr
,
"
\t
-H <hostname>: Set the hostname in the container
\n
"
);
fprintf
(
stderr
,
"
\t
-d : Daemonize (do not wait for container to exit)
\n
"
);
fprintf
(
stderr
,
"
\t
-d : Daemonize (do not wait for container to exit)
\n
"
);
fprintf
(
stderr
,
"
\t
-M :
reM
ount default fs inside container (/proc /dev/shm /dev/mqueue)
\n
"
);
fprintf
(
stderr
,
"
\t
-M :
Rem
ount default fs inside container (/proc /dev/shm /dev/mqueue)
\n
"
);
_exit
(
EXIT_SUCCESS
);
_exit
(
EXIT_SUCCESS
);
}
}
...
@@ -151,12 +151,12 @@ static int do_start(void *arg)
...
@@ -151,12 +151,12 @@ static int do_start(void *arg)
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
char
*
del
;
char
**
it
,
**
args
;
int
opt
,
status
;
int
opt
,
status
;
int
ret
;
int
ret
;
char
*
namespaces
=
NULL
;
char
*
namespaces
=
NULL
;
char
**
args
;
int
flags
=
0
,
daemonize
=
0
;
int
flags
=
0
;
int
daemonize
=
0
;
uid_t
uid
=
0
;
/* valid only if (flags & CLONE_NEWUSER) */
uid_t
uid
=
0
;
/* valid only if (flags & CLONE_NEWUSER) */
pid_t
pid
;
pid_t
pid
;
struct
my_iflist
*
tmpif
,
*
my_iflist
=
NULL
;
struct
my_iflist
*
tmpif
,
*
my_iflist
=
NULL
;
...
@@ -213,6 +213,28 @@ int main(int argc, char *argv[])
...
@@ -213,6 +213,28 @@ int main(int argc, char *argv[])
if
(
ret
)
if
(
ret
)
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
/* The identifiers for namespaces used with lxc-unshare as given on the
* manpage do not align with the standard identifiers. This affects
* network, mount, and uts namespaces. The standard identifiers are:
* "mnt", "uts", and "net" whereas lxc-unshare uses "MOUNT", "UTSNAME",
* and "NETWORK". So let's use some cheap memmove()s to replace them by
* their standard identifiers. Let's illustrate this with an example:
* Assume the string:
*
* "IPC|MOUNT|PID"
*
* then we memmove()
*
* dest: del + 1 == ONT|PID
* src: del + 3 == NT|PID
*/
while
((
del
=
strstr
(
namespaces
,
"MOUNT"
)))
memmove
(
del
+
1
,
del
+
3
,
strlen
(
del
)
-
2
);
for
(
it
=
(
char
*
[]){
"NETWORK"
,
"UTSNAME"
,
NULL
};
it
&&
*
it
;
it
++
)
while
((
del
=
strstr
(
namespaces
,
*
it
)))
memmove
(
del
+
3
,
del
+
7
,
strlen
(
del
)
-
6
);
ret
=
lxc_fill_namespace_flags
(
namespaces
,
&
flags
);
ret
=
lxc_fill_namespace_flags
(
namespaces
,
&
flags
);
if
(
ret
)
if
(
ret
)
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
...
...
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