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
4be48327
Commit
4be48327
authored
Dec 06, 2017
by
Tycho Andersen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add --share-$NS= support to lxc-execute
Signed-off-by:
Tycho Andersen
<
tycho@tycho.ws
>
parent
fb398f07
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
27 deletions
+55
-27
arguments.c
src/lxc/tools/arguments.c
+32
-0
arguments.h
src/lxc/tools/arguments.h
+8
-0
lxc_execute.c
src/lxc/tools/lxc_execute.c
+13
-0
lxc_start.c
src/lxc/tools/lxc_start.c
+2
-27
No files found.
src/lxc/tools/arguments.c
View file @
4be48327
...
...
@@ -35,6 +35,7 @@
#include "arguments.h"
#include "utils.h"
#include "version.h"
#include "namespace.h"
static
int
build_shortopts
(
const
struct
option
*
a_options
,
char
*
a_shortopts
,
size_t
a_size
)
...
...
@@ -289,3 +290,34 @@ int lxc_arguments_str_to_int(struct lxc_arguments *args, const char *str)
return
(
int
)
val
;
}
bool
lxc_setup_shared_ns
(
struct
lxc_arguments
*
args
,
struct
lxc_container
*
c
)
{
int
i
;
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
const
char
*
key
,
*
value
;
value
=
args
->
share_ns
[
i
];
if
(
!
value
)
continue
;
if
(
i
==
LXC_NS_NET
)
key
=
"lxc.namespace.net"
;
else
if
(
i
==
LXC_NS_IPC
)
key
=
"lxc.namespace.ipc"
;
else
if
(
i
==
LXC_NS_UTS
)
key
=
"lxc.namespace.uts"
;
else
if
(
i
==
LXC_NS_PID
)
key
=
"lxc.namespace.pid"
;
else
continue
;
if
(
!
c
->
set_config_item
(
c
,
key
,
value
))
{
fprintf
(
stderr
,
"failed to set %s
\n
"
,
key
);
return
false
;
}
}
return
true
;
}
src/lxc/tools/arguments.h
View file @
4be48327
...
...
@@ -29,6 +29,7 @@
#include <stdbool.h>
#include <stdint.h>
#include <sys/types.h>
#include <lxc/lxccontainer.h>
struct
lxc_arguments
;
...
...
@@ -160,6 +161,11 @@ struct lxc_arguments {
#define OPT_VERSION OPT_USAGE - 1
#define OPT_RCFILE OPT_USAGE - 2
#define OPT_SHARE_NET OPT_USAGE + 1
#define OPT_SHARE_IPC OPT_USAGE + 2
#define OPT_SHARE_UTS OPT_USAGE + 3
#define OPT_SHARE_PID OPT_USAGE + 4
extern
int
lxc_arguments_parse
(
struct
lxc_arguments
*
args
,
int
argc
,
char
*
const
argv
[]);
...
...
@@ -170,4 +176,6 @@ extern int lxc_arguments_str_to_int(struct lxc_arguments *args,
if (!(arg)->quiet) \
fprintf(stderr, "%s: " fmt "\n", (arg)->progname, ##args)
extern
bool
lxc_setup_shared_ns
(
struct
lxc_arguments
*
args
,
struct
lxc_container
*
c
);
#endif
/* __LXC_ARGUMENTS_H */
src/lxc/tools/lxc_execute.c
View file @
4be48327
...
...
@@ -63,6 +63,10 @@ static int my_parser(struct lxc_arguments* args, int c, char* arg)
case
'g'
:
if
(
lxc_safe_uint
(
arg
,
&
args
->
gid
)
<
0
)
return
-
1
;
case
OPT_SHARE_NET
:
args
->
share_ns
[
LXC_NS_NET
]
=
arg
;
break
;
case
OPT_SHARE_IPC
:
args
->
share_ns
[
LXC_NS_IPC
]
=
arg
;
break
;
case
OPT_SHARE_UTS
:
args
->
share_ns
[
LXC_NS_UTS
]
=
arg
;
break
;
case
OPT_SHARE_PID
:
args
->
share_ns
[
LXC_NS_PID
]
=
arg
;
break
;
}
return
0
;
}
...
...
@@ -73,6 +77,10 @@ static const struct option my_longopts[] = {
{
"define"
,
required_argument
,
0
,
's'
},
{
"uid"
,
required_argument
,
0
,
'u'
},
{
"gid"
,
required_argument
,
0
,
'g'
},
{
"share-net"
,
required_argument
,
0
,
OPT_SHARE_NET
},
{
"share-ipc"
,
required_argument
,
0
,
OPT_SHARE_IPC
},
{
"share-uts"
,
required_argument
,
0
,
OPT_SHARE_UTS
},
{
"share-pid"
,
required_argument
,
0
,
OPT_SHARE_PID
},
LXC_COMMON_OPTIONS
};
...
...
@@ -183,6 +191,11 @@ int main(int argc, char *argv[])
if
(
my_args
.
gid
)
c
->
lxc_conf
->
init_gid
=
my_args
.
gid
;
if
(
!
lxc_setup_shared_ns
(
&
my_args
,
c
))
{
lxc_container_put
(
c
);
exit
(
EXIT_FAILURE
);
}
c
->
daemonize
=
my_args
.
daemonize
==
1
;
bret
=
c
->
start
(
c
,
1
,
my_args
.
argv
);
ret
=
c
->
error_num
;
...
...
src/lxc/tools/lxc_start.c
View file @
4be48327
...
...
@@ -50,11 +50,6 @@
#include "confile.h"
#include "arguments.h"
#define OPT_SHARE_NET OPT_USAGE + 1
#define OPT_SHARE_IPC OPT_USAGE + 2
#define OPT_SHARE_UTS OPT_USAGE + 3
#define OPT_SHARE_PID OPT_USAGE + 4
static
struct
lxc_list
defines
;
static
int
ensure_path
(
char
**
confpath
,
const
char
*
path
)
...
...
@@ -152,7 +147,6 @@ Options :\n\
int
main
(
int
argc
,
char
*
argv
[])
{
int
i
;
struct
lxc_conf
*
conf
;
struct
lxc_log
log
;
const
char
*
lxcpath
;
...
...
@@ -284,27 +278,8 @@ int main(int argc, char *argv[])
}
}
for
(
i
=
0
;
i
<
LXC_NS_MAX
;
i
++
)
{
const
char
*
key
,
*
value
;
value
=
my_args
.
share_ns
[
i
];
if
(
!
value
)
continue
;
if
(
i
==
LXC_NS_NET
)
key
=
"lxc.namespace.net"
;
else
if
(
i
==
LXC_NS_IPC
)
key
=
"lxc.namespace.ipc"
;
else
if
(
i
==
LXC_NS_UTS
)
key
=
"lxc.namespace.uts"
;
else
if
(
i
==
LXC_NS_PID
)
key
=
"lxc.namespace.pid"
;
else
continue
;
if
(
!
c
->
set_config_item
(
c
,
key
,
value
))
goto
out
;
}
if
(
!
lxc_setup_shared_ns
(
&
my_args
,
c
))
goto
out
;
if
(
!
my_args
.
daemonize
)
{
c
->
want_daemonize
(
c
,
false
);
...
...
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