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
988c11f7
Unverified
Commit
988c11f7
authored
Jul 29, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxccontainer: cleanup do_lxcapi_get_interfaces()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
705f5735
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
15 deletions
+13
-15
lxccontainer.c
src/lxc/lxccontainer.c
+13
-15
No files found.
src/lxc/lxccontainer.c
View file @
988c11f7
...
@@ -2043,21 +2043,19 @@ static bool remove_from_array(char ***names, char *cname, int size)
...
@@ -2043,21 +2043,19 @@ static bool remove_from_array(char ***names, char *cname, int size)
return
false
;
return
false
;
}
}
static
char
**
do_lxcapi_get_interfaces
(
struct
lxc_container
*
c
)
static
char
**
do_lxcapi_get_interfaces
(
struct
lxc_container
*
c
)
{
{
pid_t
pid
;
pid_t
pid
;
int
i
,
count
=
0
,
pipefd
[
2
];
int
i
,
count
=
0
,
pipefd
[
2
];
char
**
interfaces
=
NULL
;
char
**
interfaces
=
NULL
;
char
interface
[
IFNAMSIZ
];
char
interface
[
IFNAMSIZ
];
if
(
pipe
(
pipefd
)
<
0
)
{
if
(
pipe
(
pipefd
)
<
0
)
SYSERROR
(
"pipe failed"
);
return
NULL
;
return
NULL
;
}
pid
=
fork
();
pid
=
fork
();
if
(
pid
<
0
)
{
if
(
pid
<
0
)
{
SYSERROR
(
"
f
ailed to fork task to get interfaces information"
);
SYSERROR
(
"
F
ailed to fork task to get interfaces information"
);
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
close
(
pipefd
[
1
]);
close
(
pipefd
[
1
]);
return
NULL
;
return
NULL
;
...
@@ -2071,23 +2069,23 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
...
@@ -2071,23 +2069,23 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
if
(
!
enter_net_ns
(
c
))
{
if
(
!
enter_net_ns
(
c
))
{
SYSERROR
(
"
failed to enter
namespace"
);
SYSERROR
(
"
Failed to enter network
namespace"
);
goto
out
;
goto
out
;
}
}
/* Grab the list of interfaces */
/* Grab the list of interfaces */
if
(
getifaddrs
(
&
interfaceArray
))
{
if
(
getifaddrs
(
&
interfaceArray
))
{
SYSERROR
(
"
f
ailed to get interfaces list"
);
SYSERROR
(
"
F
ailed to get interfaces list"
);
goto
out
;
goto
out
;
}
}
/* 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
)
{
nbytes
=
write
(
pipefd
[
1
],
tempIfAddr
->
ifa_name
,
IFNAMSIZ
);
nbytes
=
write
(
pipefd
[
1
],
tempIfAddr
->
ifa_name
,
IFNAMSIZ
);
if
(
nbytes
<
0
)
{
if
(
nbytes
<
0
)
ERROR
(
"write failed"
);
goto
out
;
goto
out
;
}
count
++
;
count
++
;
}
}
ret
=
0
;
ret
=
0
;
...
@@ -2108,16 +2106,16 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
...
@@ -2108,16 +2106,16 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
interface
[
IFNAMSIZ
-
1
]
=
'\0'
;
interface
[
IFNAMSIZ
-
1
]
=
'\0'
;
if
(
array_contains
(
&
interfaces
,
interface
,
count
))
if
(
array_contains
(
&
interfaces
,
interface
,
count
))
continue
;
continue
;
if
(
!
add_to_array
(
&
interfaces
,
interface
,
count
))
if
(
!
add_to_array
(
&
interfaces
,
interface
,
count
))
ERROR
(
"Failed to add
\"
%s
\"
to array"
,
interface
);
ERROR
(
"Failed to add
\"
%s
\"
to array"
,
interface
);
count
++
;
count
++
;
}
}
if
(
wait_for_pid
(
pid
)
!=
0
)
{
if
(
wait_for_pid
(
pid
)
!=
0
)
{
for
(
i
=
0
;
i
<
count
;
i
++
)
for
(
i
=
0
;
i
<
count
;
i
++
)
free
(
interfaces
[
i
]);
free
(
interfaces
[
i
]);
free
(
interfaces
);
free
(
interfaces
);
interfaces
=
NULL
;
interfaces
=
NULL
;
...
@@ -2127,7 +2125,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
...
@@ -2127,7 +2125,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
/* Append NULL to the array */
/* Append NULL to the array */
if
(
interfaces
)
if
(
interfaces
)
interfaces
=
(
char
**
)
lxc_append_null_to_array
((
void
**
)
interfaces
,
count
);
interfaces
=
(
char
**
)
lxc_append_null_to_array
((
void
**
)
interfaces
,
count
);
return
interfaces
;
return
interfaces
;
...
...
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