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
d75c14e2
Unverified
Commit
d75c14e2
authored
Sep 03, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: add lxc_nic_exists()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
32311345
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
21 deletions
+23
-21
lxc_user_nic.c
src/lxc/lxc_user_nic.c
+1
-21
utils.c
src/lxc/utils.c
+21
-0
utils.h
src/lxc/utils.h
+1
-0
No files found.
src/lxc/lxc_user_nic.c
View file @
d75c14e2
...
@@ -397,26 +397,6 @@ static char *find_line(char *p, char *e, char *u, char *t, char *l)
...
@@ -397,26 +397,6 @@ static char *find_line(char *p, char *e, char *u, char *t, char *l)
return
NULL
;
return
NULL
;
}
}
static
bool
nic_exists
(
char
*
nic
)
{
char
path
[
MAXPATHLEN
];
int
ret
;
struct
stat
sb
;
if
(
!
strcmp
(
nic
,
"none"
))
return
true
;
ret
=
snprintf
(
path
,
MAXPATHLEN
,
"/sys/class/net/%s"
,
nic
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
MAXPATHLEN
)
return
false
;
ret
=
stat
(
path
,
&
sb
);
if
(
ret
<
0
)
return
false
;
return
true
;
}
static
int
instantiate_veth
(
char
*
n1
,
char
**
n2
)
static
int
instantiate_veth
(
char
*
n1
,
char
**
n2
)
{
{
int
err
;
int
err
;
...
@@ -625,7 +605,7 @@ static bool cull_entries(int fd, char *me, char *t, char *br, char *nicname,
...
@@ -625,7 +605,7 @@ static bool cull_entries(int fd, char *me, char *t, char *br, char *nicname,
continue
;
continue
;
if
(
nic
[
0
]
!=
'\0'
)
if
(
nic
[
0
]
!=
'\0'
)
exists
=
nic_exists
(
nic
);
exists
=
lxc_
nic_exists
(
nic
);
if
(
!
exists
)
if
(
!
exists
)
entry_lines
[
n
-
1
].
keep
=
false
;
entry_lines
[
n
-
1
].
keep
=
false
;
...
...
src/lxc/utils.c
View file @
d75c14e2
...
@@ -2409,3 +2409,24 @@ bool has_fs_type(const char *path, fs_type_magic magic_val)
...
@@ -2409,3 +2409,24 @@ bool has_fs_type(const char *path, fs_type_magic magic_val)
return
has_type
;
return
has_type
;
}
}
bool
lxc_nic_exists
(
char
*
nic
)
{
#define __LXC_SYS_CLASS_NET_LEN 15 + IFNAMSIZ + 1
char
path
[
__LXC_SYS_CLASS_NET_LEN
];
int
ret
;
struct
stat
sb
;
if
(
!
strcmp
(
nic
,
"none"
))
return
true
;
ret
=
snprintf
(
path
,
__LXC_SYS_CLASS_NET_LEN
,
"/sys/class/net/%s"
,
nic
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
__LXC_SYS_CLASS_NET_LEN
)
return
false
;
ret
=
stat
(
path
,
&
sb
);
if
(
ret
<
0
)
return
false
;
return
true
;
}
src/lxc/utils.h
View file @
d75c14e2
...
@@ -402,5 +402,6 @@ extern void *must_realloc(void *orig, size_t sz);
...
@@ -402,5 +402,6 @@ extern void *must_realloc(void *orig, size_t sz);
typedef
__typeof__
(((
struct
statfs
*
)
NULL
)
->
f_type
)
fs_type_magic
;
typedef
__typeof__
(((
struct
statfs
*
)
NULL
)
->
f_type
)
fs_type_magic
;
extern
bool
has_fs_type
(
const
char
*
path
,
fs_type_magic
magic_val
);
extern
bool
has_fs_type
(
const
char
*
path
,
fs_type_magic
magic_val
);
extern
bool
is_fs_type
(
const
struct
statfs
*
fs
,
fs_type_magic
magic_val
);
extern
bool
is_fs_type
(
const
struct
statfs
*
fs
,
fs_type_magic
magic_val
);
extern
bool
lxc_nic_exists
(
char
*
nic
);
#endif
/* __LXC_UTILS_H */
#endif
/* __LXC_UTILS_H */
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