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
5d04eb33
Unverified
Commit
5d04eb33
authored
Jul 29, 2017
by
Christian Brauner
Committed by
Stéphane Graber
Aug 15, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: rework lxc_deslashify()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
0e8e6386
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
49 deletions
+56
-49
criu.c
src/lxc/criu.c
+7
-3
utils.c
src/lxc/utils.c
+24
-25
utils.h
src/lxc/utils.h
+1
-1
lxc-test-utils.c
src/tests/lxc-test-utils.c
+24
-20
No files found.
src/lxc/criu.c
View file @
5d04eb33
...
...
@@ -263,7 +263,7 @@ static void exec_criu(struct criu_opts *opts)
for
(
i
=
0
;
i
<
cgroup_num_hierarchies
();
i
++
)
{
char
**
controllers
=
NULL
,
*
fullname
;
char
*
path
;
char
*
path
,
*
tmp
;
if
(
!
cgroup_get_hierarchies
(
i
,
&
controllers
))
{
ERROR
(
"failed to get hierarchy %d"
,
i
);
...
...
@@ -296,11 +296,15 @@ static void exec_criu(struct criu_opts *opts)
}
}
if
(
!
lxc_deslashify
(
&
path
))
{
ERROR
(
"failed to deslashify %s"
,
path
);
tmp
=
lxc_deslashify
(
path
);
if
(
!
tmp
)
{
ERROR
(
"Failed to remove extraneous slashes from
\"
%s
\"
"
,
path
);
free
(
path
);
goto
err
;
}
free
(
path
);
path
=
tmp
;
fullname
=
lxc_string_join
(
","
,
(
const
char
**
)
controllers
,
false
);
if
(
!
fullname
)
{
...
...
src/lxc/utils.c
View file @
5d04eb33
...
...
@@ -728,47 +728,46 @@ char **lxc_normalize_path(const char *path)
return
components
;
}
bool
lxc_deslashify
(
char
*
*
path
)
char
*
lxc_deslashify
(
const
char
*
path
)
{
bool
ret
=
false
;
char
*
p
;
char
*
dup
,
*
p
;
char
**
parts
=
NULL
;
size_t
n
,
len
;
parts
=
lxc_normalize_path
(
*
path
);
if
(
!
parts
)
return
false
;
dup
=
strdup
(
path
);
if
(
!
dup
)
return
NULL
;
parts
=
lxc_normalize_path
(
dup
);
if
(
!
parts
)
{
free
(
dup
);
return
NULL
;
}
/* We'll end up here if path == "///" or path == "". */
if
(
!*
parts
)
{
len
=
strlen
(
*
path
);
len
=
strlen
(
dup
);
if
(
!
len
)
{
ret
=
true
;
goto
out
;
lxc_free_array
((
void
**
)
parts
,
free
)
;
return
dup
;
}
n
=
strcspn
(
*
path
,
"/"
);
n
=
strcspn
(
dup
,
"/"
);
if
(
n
==
len
)
{
free
(
dup
);
lxc_free_array
((
void
**
)
parts
,
free
);
p
=
strdup
(
"/"
);
if
(
!
p
)
goto
out
;
free
(
*
path
);
*
path
=
p
;
ret
=
true
;
goto
out
;
return
NULL
;
return
p
;
}
}
p
=
lxc_string_join
(
"/"
,
(
const
char
**
)
parts
,
**
path
==
'/'
);
if
(
!
p
)
goto
out
;
free
(
*
path
);
*
path
=
p
;
ret
=
true
;
out
:
p
=
lxc_string_join
(
"/"
,
(
const
char
**
)
parts
,
*
dup
==
'/'
);
free
(
dup
);
lxc_free_array
((
void
**
)
parts
,
free
);
return
ret
;
return
p
;
}
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
)
...
...
src/lxc/utils.h
View file @
5d04eb33
...
...
@@ -273,7 +273,7 @@ extern char *lxc_string_join(const char *sep, const char **parts, bool use_as_pr
*/
extern
char
**
lxc_normalize_path
(
const
char
*
path
);
/* remove multiple slashes from the path, e.g. ///foo//bar -> /foo/bar */
extern
bool
lxc_deslashify
(
char
*
*
path
);
extern
char
*
lxc_deslashify
(
const
char
*
path
);
extern
char
*
lxc_append_paths
(
const
char
*
first
,
const
char
*
second
);
/* Note: the following two functions use strtok(), so they will never
* consider an empty element, even if two delimiters are next to
...
...
src/tests/lxc-test-utils.c
View file @
5d04eb33
...
...
@@ -41,33 +41,37 @@
void
test_lxc_deslashify
(
void
)
{
char
*
s
=
strdup
(
"/A///B//C/D/E/"
);
if
(
!
s
)
char
*
s
=
"/A///B//C/D/E/"
;
char
*
t
;
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/A/B/C/D/E"
)
==
0
);
free
(
s
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A/B/C/D/E"
)
==
0
);
free
(
t
);
s
=
strdup
(
"/A"
);
if
(
!
s
)
s
=
"/A"
;
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/A"
)
==
0
);
free
(
s
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/A"
)
==
0
);
free
(
t
);
s
=
strdup
(
""
);
if
(
!
s
)
s
=
""
;
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
""
)
==
0
);
free
(
s
);
lxc_test_assert_abort
(
strcmp
(
t
,
""
)
==
0
);
free
(
t
);
s
=
"//"
;
s
=
strdup
(
"//"
);
if
(
!
s
)
t
=
lxc_deslashify
(
s
);
if
(
!
t
)
exit
(
EXIT_FAILURE
);
lxc_test_assert_abort
(
lxc_deslashify
(
&
s
));
lxc_test_assert_abort
(
strcmp
(
s
,
"/"
)
==
0
);
free
(
s
);
lxc_test_assert_abort
(
strcmp
(
t
,
"/"
)
==
0
);
free
(
t
);
}
/* /proc/int_as_str/ns/mnt\0 = (5 + 21 + 7 + 1) */
...
...
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