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
03c2eb15
Commit
03c2eb15
authored
Nov 19, 2013
by
Serge Hallyn
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-user-nic: improve cull_entries
Signed-off-by:
Serge Hallyn
<
serge.hallyn@ubuntu.com
>
Acked-by:
Stéphane Graber
<
stgraber@ubuntu.com
>
parent
82160e6f
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
32 additions
and
10 deletions
+32
-10
lxc_user_nic.c
src/lxc/lxc_user_nic.c
+32
-10
No files found.
src/lxc/lxc_user_nic.c
View file @
03c2eb15
...
@@ -622,11 +622,19 @@ static bool get_nic_from_line(char *p, char **nic)
...
@@ -622,11 +622,19 @@ static bool get_nic_from_line(char *p, char **nic)
return
true
;
return
true
;
}
}
struct
entry_line
{
char
*
start
;
int
len
;
bool
keep
;
};
static
bool
cull_entries
(
int
fd
,
char
*
me
,
char
*
t
,
char
*
br
)
static
bool
cull_entries
(
int
fd
,
char
*
me
,
char
*
t
,
char
*
br
)
{
{
struct
stat
sb
;
struct
stat
sb
;
char
*
buf
,
*
p
,
*
e
,
*
nic
;
char
*
buf
,
*
p
,
*
e
,
*
nic
;
off_t
len
;
off_t
len
;
struct
entry_line
*
entry_lines
=
NULL
;
int
i
,
n
=
0
;
nic
=
alloca
(
100
);
nic
=
alloca
(
100
);
...
@@ -643,22 +651,36 @@ static bool cull_entries(int fd, char *me, char *t, char *br)
...
@@ -643,22 +651,36 @@ static bool cull_entries(int fd, char *me, char *t, char *br)
p
=
buf
;
p
=
buf
;
e
=
buf
+
len
;
e
=
buf
+
len
;
while
((
p
=
find_line
(
p
,
e
,
me
,
t
,
br
))
!=
NULL
)
{
while
((
p
=
find_line
(
p
,
e
,
me
,
t
,
br
))
!=
NULL
)
{
struct
entry_line
*
newe
=
realloc
(
entry_lines
,
n
+
1
);
if
(
!
newe
)
{
free
(
entry_lines
);
return
false
;
}
entry_lines
=
newe
;
entry_lines
[
n
].
start
=
p
;
entry_lines
[
n
].
len
=
get_eol
(
p
)
-
entry_lines
[
n
].
start
;
entry_lines
[
n
].
keep
=
true
;
n
++
;
if
(
!
get_nic_from_line
(
p
,
&
nic
))
if
(
!
get_nic_from_line
(
p
,
&
nic
))
continue
;
continue
;
if
(
nic
&&
!
nic_exists
(
nic
))
{
if
(
nic
&&
!
nic_exists
(
nic
))
// copy from eol(p)+1..e to p
entry_lines
[
n
-
1
].
keep
=
false
;
char
*
src
=
get_eol
(
p
)
+
1
,
*
dest
=
p
;
p
+=
entry_lines
[
n
-
1
].
len
+
1
;
int
diff
=
src
-
p
;
while
(
src
<
e
)
*
(
dest
++
)
=
*
(
src
)
++
;
e
-=
diff
;
}
else
p
=
get_eol
(
p
)
+
1
;
if
(
p
>=
e
)
if
(
p
>=
e
)
break
;
break
;
}
}
p
=
buf
;
for
(
i
=
0
;
i
<
n
;
i
++
)
{
if
(
!
entry_lines
[
i
].
keep
)
continue
;
memcpy
(
p
,
entry_lines
[
i
].
start
,
entry_lines
[
i
].
len
);
p
+=
entry_lines
[
i
].
len
;
*
p
=
'\n'
;
p
++
;
}
free
(
entry_lines
);
munmap
(
buf
,
sb
.
st_size
);
munmap
(
buf
,
sb
.
st_size
);
if
(
ftruncate
(
fd
,
e
-
buf
))
if
(
ftruncate
(
fd
,
p
-
buf
))
fprintf
(
stderr
,
"Failed to set new file size
\n
"
);
fprintf
(
stderr
,
"Failed to set new file size
\n
"
);
return
true
;
return
true
;
}
}
...
...
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