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
d04e77c3
Unverified
Commit
d04e77c3
authored
Aug 26, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-user-nic: non-functional changes
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
92c590ae
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
26 deletions
+23
-26
lxc_user_nic.c
src/lxc/lxc_user_nic.c
+23
-26
No files found.
src/lxc/lxc_user_nic.c
View file @
d04e77c3
...
@@ -914,31 +914,28 @@ static bool may_access_netns(int pid)
...
@@ -914,31 +914,28 @@ static bool may_access_netns(int pid)
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
n
,
fd
;
int
fd
,
n
,
pid
,
ret
;
char
*
me
;
char
*
me
;
char
*
nicname
;
char
nicname
[
100
];
int
pid
;
char
*
cnic
=
NULL
,
*
vethname
=
NULL
;
char
*
cnic
=
NULL
;
/* Created nic name in container is returned here. */
char
*
vethname
=
NULL
;
bool
gotone
=
false
;
bool
gotone
=
false
;
struct
alloted_s
*
alloted
=
NULL
;
struct
alloted_s
*
alloted
=
NULL
;
nicname
=
alloca
(
40
);
/* Set a sane env, because we are setuid-root. */
if
(
!
nicname
)
{
ret
=
clearenv
();
usernic_error
(
"Failed allocate memory: %s
\n
"
,
strerror
(
errno
));
if
(
ret
)
{
exit
(
EXIT_FAILURE
);
}
/* set a sane env, because we are setuid-root */
if
(
clearenv
()
<
0
)
{
usernic_error
(
"%s"
,
"Failed to clear environment
\n
"
);
usernic_error
(
"%s"
,
"Failed to clear environment
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
(
setenv
(
"PATH"
,
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
,
1
)
<
0
)
{
ret
=
setenv
(
"PATH"
,
"/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
,
1
);
if
(
ret
<
0
)
{
usernic_error
(
"%s"
,
"Failed to set PATH, exiting
\n
"
);
usernic_error
(
"%s"
,
"Failed to set PATH, exiting
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
((
me
=
get_username
())
==
NULL
)
{
me
=
get_username
();
if
(
!
me
)
{
usernic_error
(
"%s"
,
"Failed to get username
\n
"
);
usernic_error
(
"%s"
,
"Failed to get username
\n
"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -952,9 +949,8 @@ int main(int argc, char *argv[])
...
@@ -952,9 +949,8 @@ int main(int argc, char *argv[])
lxcpath
=
argv
[
1
];
lxcpath
=
argv
[
1
];
lxcname
=
argv
[
2
];
lxcname
=
argv
[
2
];
errno
=
0
;
ret
=
lxc_safe_int
(
argv
[
3
],
&
pid
);
pid
=
strtol
(
argv
[
3
],
NULL
,
10
);
if
(
ret
<
0
)
{
if
(
errno
)
{
usernic_error
(
"Could not read pid: %s
\n
"
,
argv
[
1
]);
usernic_error
(
"Could not read pid: %s
\n
"
,
argv
[
1
]);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -964,7 +960,8 @@ int main(int argc, char *argv[])
...
@@ -964,7 +960,8 @@ int main(int argc, char *argv[])
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
if
((
fd
=
open_and_lock
(
LXC_USERNIC_DB
))
<
0
)
{
fd
=
open_and_lock
(
LXC_USERNIC_DB
);
if
(
fd
<
0
)
{
usernic_error
(
"Failed to lock %s
\n
"
,
LXC_USERNIC_DB
);
usernic_error
(
"Failed to lock %s
\n
"
,
LXC_USERNIC_DB
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -976,7 +973,7 @@ int main(int argc, char *argv[])
...
@@ -976,7 +973,7 @@ int main(int argc, char *argv[])
n
=
get_alloted
(
me
,
argv
[
4
],
argv
[
5
],
&
alloted
);
n
=
get_alloted
(
me
,
argv
[
4
],
argv
[
5
],
&
alloted
);
if
(
n
>
0
)
if
(
n
>
0
)
gotone
=
get_nic_if_avail
(
fd
,
alloted
,
pid
,
argv
[
4
],
argv
[
5
],
n
,
&
nicname
,
&
cnic
);
gotone
=
get_nic_if_avail
(
fd
,
alloted
,
pid
,
argv
[
4
],
argv
[
5
],
n
,
(
char
**
)
&
nicname
,
&
cnic
);
close
(
fd
);
close
(
fd
);
free_alloted
(
&
alloted
);
free_alloted
(
&
alloted
);
...
@@ -986,16 +983,16 @@ int main(int argc, char *argv[])
...
@@ -986,16 +983,16 @@ int main(int argc, char *argv[])
}
}
/* Now rename the link. */
/* Now rename the link. */
if
(
rename_in_ns
(
pid
,
cnic
,
&
vethname
)
<
0
)
{
ret
=
rename_in_ns
(
pid
,
cnic
,
&
vethname
);
if
(
ret
<
0
)
{
usernic_error
(
"%s"
,
"Failed to rename the link
\n
"
);
usernic_error
(
"%s"
,
"Failed to rename the link
\n
"
);
if
(
lxc_netdev_delete_by_name
(
cnic
)
<
0
)
ret
=
lxc_netdev_delete_by_name
(
cnic
);
usernic_error
(
"Failed to delete link
\"
%s
\"
the link. Manual cleanup needed
\n
"
,
cnic
);
if
(
ret
<
0
)
usernic_error
(
"Failed to delete
\"
%s
\"\n
"
,
cnic
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
/* Write the name of the interface pair to the stdout - like
/* Write the name of the interface pair to the stdout: eth0:veth9MT2L4 */
* eth0:veth9MT2L4.
*/
fprintf
(
stdout
,
"%s:%s
\n
"
,
vethname
,
nicname
);
fprintf
(
stdout
,
"%s:%s
\n
"
,
vethname
,
nicname
);
exit
(
EXIT_SUCCESS
);
exit
(
EXIT_SUCCESS
);
}
}
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