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
a9cb0fb8
Commit
a9cb0fb8
authored
Jun 29, 2018
by
2xsec
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tools: lxc-device: share internal API symbols
Signed-off-by:
2xsec
<
dh48.jeong@samsung.com
>
parent
75e607ba
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
28 deletions
+37
-28
Makefile.am
src/lxc/Makefile.am
+1
-1
lxc_device.c
src/lxc/tools/lxc_device.c
+34
-25
utils.c
src/lxc/utils.c
+2
-2
No files found.
src/lxc/Makefile.am
View file @
a9cb0fb8
...
@@ -271,7 +271,7 @@ lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
...
@@ -271,7 +271,7 @@ lxc_cgroup_SOURCES = tools/lxc_cgroup.c tools/arguments.c
lxc_config_SOURCES
=
tools/lxc_config.c tools/arguments.c
lxc_config_SOURCES
=
tools/lxc_config.c tools/arguments.c
lxc_console_SOURCES
=
tools/lxc_console.c tools/arguments.c
lxc_console_SOURCES
=
tools/lxc_console.c tools/arguments.c
lxc_destroy_SOURCES
=
tools/lxc_destroy.c tools/arguments.c
lxc_destroy_SOURCES
=
tools/lxc_destroy.c tools/arguments.c
lxc_device_SOURCES
=
tools/lxc_device.c tools/arguments.c
tools/tool_utils.c
lxc_device_SOURCES
=
tools/lxc_device.c tools/arguments.c
lxc_execute_SOURCES
=
tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
lxc_execute_SOURCES
=
tools/lxc_execute.c tools/arguments.c tools/tool_utils.c
lxc_freeze_SOURCES
=
tools/lxc_freeze.c tools/arguments.c
lxc_freeze_SOURCES
=
tools/lxc_freeze.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
lxc_info_SOURCES
=
tools/lxc_info.c tools/arguments.c
...
...
src/lxc/tools/lxc_device.c
View file @
a9cb0fb8
...
@@ -30,7 +30,10 @@
...
@@ -30,7 +30,10 @@
#include <lxc/lxccontainer.h>
#include <lxc/lxccontainer.h>
#include "arguments.h"
#include "arguments.h"
#include "tool_utils.h"
#include "log.h"
#include "utils.h"
lxc_log_define
(
lxc_device
,
lxc
);
#if HAVE_IFADDRS_H
#if HAVE_IFADDRS_H
#include <ifaddrs.h>
#include <ifaddrs.h>
...
@@ -57,12 +60,11 @@ Options :\n\
...
@@ -57,12 +60,11 @@ Options :\n\
.
checker
=
NULL
,
.
checker
=
NULL
,
};
};
static
bool
is_interface
(
const
char
*
dev_name
,
pid_t
pid
)
static
bool
is_interface
(
const
char
*
dev_name
,
pid_t
pid
)
{
{
pid_t
p
=
fork
();
pid_t
p
=
fork
();
if
(
p
<
0
)
{
if
(
p
<
0
)
{
fprintf
(
stderr
,
"failed to fork task.
\n
"
);
ERROR
(
"Failed to fork task.
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -70,28 +72,28 @@ static bool is_interface(const char* dev_name, pid_t pid)
...
@@ -70,28 +72,28 @@ static bool is_interface(const char* dev_name, pid_t pid)
struct
ifaddrs
*
interfaceArray
=
NULL
,
*
tempIfAddr
=
NULL
;
struct
ifaddrs
*
interfaceArray
=
NULL
,
*
tempIfAddr
=
NULL
;
if
(
!
switch_to_ns
(
pid
,
"net"
))
{
if
(
!
switch_to_ns
(
pid
,
"net"
))
{
fprintf
(
stderr
,
"failed to enter netns of container.
\n
"
);
ERROR
(
"Failed to enter netns of container.
"
);
exit
(
-
1
);
_
exit
(
-
1
);
}
}
/* Grab the list of interfaces */
/* Grab the list of interfaces */
if
(
getifaddrs
(
&
interfaceArray
))
{
if
(
getifaddrs
(
&
interfaceArray
))
{
fprintf
(
stderr
,
"failed to get interfaces list
\n
"
);
ERROR
(
"Failed to get interfaces list
"
);
exit
(
-
1
);
_
exit
(
-
1
);
}
}
/* Iterate through the interfaces */
/* Iterate through the interfaces */
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
!=
NULL
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
for
(
tempIfAddr
=
interfaceArray
;
tempIfAddr
!=
NULL
;
tempIfAddr
=
tempIfAddr
->
ifa_next
)
{
if
(
strcmp
(
tempIfAddr
->
ifa_name
,
dev_name
)
==
0
)
{
if
(
!
strncmp
(
tempIfAddr
->
ifa_name
,
dev_name
,
strlen
(
tempIfAddr
->
ifa_name
)))
exit
(
EXIT_SUCCESS
);
_exit
(
EXIT_SUCCESS
);
}
}
}
exit
(
EXIT_FAILURE
);
_exit
(
EXIT_FAILURE
);
}
}
if
(
wait_for_pid
(
p
)
==
0
)
{
if
(
wait_for_pid
(
p
)
==
0
)
return
true
;
return
true
;
}
return
false
;
return
false
;
}
}
...
@@ -103,7 +105,7 @@ int main(int argc, char *argv[])
...
@@ -103,7 +105,7 @@ int main(int argc, char *argv[])
bool
ret
=
false
;
bool
ret
=
false
;
if
(
geteuid
()
!=
0
)
{
if
(
geteuid
()
!=
0
)
{
fprintf
(
stderr
,
"%s must be run as root
\n
"
,
argv
[
0
]);
ERROR
(
"%s must be run as root
"
,
argv
[
0
]);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -125,30 +127,32 @@ int main(int argc, char *argv[])
...
@@ -125,30 +127,32 @@ int main(int argc, char *argv[])
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
c
=
lxc_container_new
(
my_args
.
name
,
my_args
.
lxcpath
[
0
]);
if
(
!
c
)
{
if
(
!
c
)
{
fprintf
(
stderr
,
"%s doesn't exist
\n
"
,
my_args
.
name
);
ERROR
(
"%s doesn't exist
"
,
my_args
.
name
);
goto
err
;
goto
err
;
}
}
if
(
my_args
.
rcfile
)
{
if
(
my_args
.
rcfile
)
{
c
->
clear_config
(
c
);
c
->
clear_config
(
c
);
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
if
(
!
c
->
load_config
(
c
,
my_args
.
rcfile
))
{
fprintf
(
stderr
,
"Failed to load rcfile
\n
"
);
ERROR
(
"Failed to load rcfile
"
);
goto
err1
;
goto
err1
;
}
}
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
c
->
configfile
=
strdup
(
my_args
.
rcfile
);
if
(
!
c
->
configfile
)
{
if
(
!
c
->
configfile
)
{
fprintf
(
stderr
,
"Out of memory setting new config filename
\n
"
);
ERROR
(
"Out of memory setting new config filename
"
);
goto
err1
;
goto
err1
;
}
}
}
}
if
(
!
c
->
is_running
(
c
))
{
if
(
!
c
->
is_running
(
c
))
{
fprintf
(
stderr
,
"Container %s is not running.
\n
"
,
c
->
name
);
ERROR
(
"Container %s is not running.
"
,
c
->
name
);
goto
err1
;
goto
err1
;
}
}
if
(
my_args
.
argc
<
2
)
{
if
(
my_args
.
argc
<
2
)
{
fprintf
(
stderr
,
"Error: no command given (Please see --help output)
\n
"
);
ERROR
(
"Error: no command given (Please see --help output)
"
);
goto
err1
;
goto
err1
;
}
}
...
@@ -159,33 +163,38 @@ int main(int argc, char *argv[])
...
@@ -159,33 +163,38 @@ int main(int argc, char *argv[])
else
else
dst_name
=
my_args
.
argv
[
2
];
dst_name
=
my_args
.
argv
[
2
];
if
(
strcmp
(
cmd
,
"add"
)
==
0
)
{
if
(
!
strncmp
(
cmd
,
"add"
,
strlen
(
cmd
))
)
{
if
(
is_interface
(
dev_name
,
1
))
{
if
(
is_interface
(
dev_name
,
1
))
{
ret
=
c
->
attach_interface
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
attach_interface
(
c
,
dev_name
,
dst_name
);
}
else
{
}
else
{
ret
=
c
->
add_device_node
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
add_device_node
(
c
,
dev_name
,
dst_name
);
}
}
if
(
ret
!=
true
)
{
if
(
ret
!=
true
)
{
fprintf
(
stderr
,
"Failed to add %s to %s.
\n
"
,
dev_name
,
c
->
name
);
ERROR
(
"Failed to add %s to %s.
"
,
dev_name
,
c
->
name
);
goto
err1
;
goto
err1
;
}
}
}
else
if
(
strcmp
(
cmd
,
"del"
)
==
0
)
{
}
else
if
(
!
strncmp
(
cmd
,
"del"
,
strlen
(
cmd
))
)
{
if
(
is_interface
(
dev_name
,
c
->
init_pid
(
c
)))
{
if
(
is_interface
(
dev_name
,
c
->
init_pid
(
c
)))
{
ret
=
c
->
detach_interface
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
detach_interface
(
c
,
dev_name
,
dst_name
);
}
else
{
}
else
{
ret
=
c
->
remove_device_node
(
c
,
dev_name
,
dst_name
);
ret
=
c
->
remove_device_node
(
c
,
dev_name
,
dst_name
);
}
}
if
(
ret
!=
true
)
{
if
(
ret
!=
true
)
{
fprintf
(
stderr
,
"Failed to del %s from %s.
\n
"
,
dev_name
,
c
->
name
);
ERROR
(
"Failed to del %s from %s.
"
,
dev_name
,
c
->
name
);
goto
err1
;
goto
err1
;
}
}
}
else
{
}
else
{
fprintf
(
stderr
,
"Error: Please use add or del (Please see --help output)
\n
"
);
ERROR
(
"Error: Please use add or del (Please see --help output)
"
);
goto
err1
;
goto
err1
;
}
}
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
err1:
err1:
lxc_container_put
(
c
);
lxc_container_put
(
c
);
err:
err:
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
src/lxc/utils.c
View file @
a9cb0fb8
...
@@ -1273,13 +1273,13 @@ bool switch_to_ns(pid_t pid, const char *ns) {
...
@@ -1273,13 +1273,13 @@ bool switch_to_ns(pid_t pid, const char *ns) {
fd
=
open
(
nspath
,
O_RDONLY
);
fd
=
open
(
nspath
,
O_RDONLY
);
if
(
fd
<
0
)
{
if
(
fd
<
0
)
{
SYSERROR
(
"
f
ailed to open %s"
,
nspath
);
SYSERROR
(
"
F
ailed to open %s"
,
nspath
);
return
false
;
return
false
;
}
}
ret
=
setns
(
fd
,
0
);
ret
=
setns
(
fd
,
0
);
if
(
ret
)
{
if
(
ret
)
{
SYSERROR
(
"
f
ailed to set process %d to %s of %d."
,
pid
,
ns
,
fd
);
SYSERROR
(
"
F
ailed to set process %d to %s of %d."
,
pid
,
ns
,
fd
);
close
(
fd
);
close
(
fd
);
return
false
;
return
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