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
c38d860c
Commit
c38d860c
authored
Oct 05, 2017
by
Christian Brauner
Committed by
GitHub
Oct 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1844 from hallyn/2017-10-04/quote
implement lxc_string_split_quoted
parents
fe0fe85d
3dca1af0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
5 deletions
+71
-5
lxc_execute.c
src/lxc/tools/lxc_execute.c
+1
-4
utils.c
src/lxc/utils.c
+68
-0
utils.h
src/lxc/utils.h
+1
-0
lxc-oci.in
templates/lxc-oci.in
+1
-1
No files found.
src/lxc/tools/lxc_execute.c
View file @
c38d860c
...
...
@@ -99,10 +99,7 @@ static bool set_argv(struct lxc_conf *conf, struct lxc_arguments *args)
if
(
!
conf
->
execute_cmd
)
return
false
;
/* TODO -
we should honor '"' etc; This seems worth a new helper in utils.c.
*/
components
=
lxc_string_split
(
conf
->
execute_cmd
,
' '
);
components
=
lxc_string_split_quoted
(
conf
->
execute_cmd
);
if
(
!
components
)
return
false
;
...
...
src/lxc/utils.c
View file @
c38d860c
...
...
@@ -816,6 +816,74 @@ error_out:
return
NULL
;
}
static
bool
complete_word
(
char
***
result
,
char
*
start
,
char
*
end
,
size_t
*
cap
,
size_t
*
cnt
)
{
int
r
;
r
=
lxc_grow_array
((
void
***
)
result
,
cap
,
2
+
*
cnt
,
16
);
if
(
r
<
0
)
return
false
;
(
*
result
)[
*
cnt
]
=
strndup
(
start
,
end
-
start
);
if
(
!
(
*
result
)[
*
cnt
])
return
false
;
(
*
cnt
)
++
;
return
true
;
}
/*
* Given a a string 'one two "three four"', split into three words,
* one, two, and "three four"
*/
char
**
lxc_string_split_quoted
(
char
*
string
)
{
char
*
nextword
=
string
,
*
p
,
state
;
char
**
result
=
NULL
;
size_t
result_capacity
=
0
;
size_t
result_count
=
0
;
if
(
!
string
||
!*
string
)
return
calloc
(
1
,
sizeof
(
char
*
));
// TODO I'm *not* handling escaped quote
state
=
' '
;
for
(
p
=
string
;
*
p
;
p
++
)
{
switch
(
state
)
{
case
' '
:
if
(
isspace
(
*
p
))
continue
;
else
if
(
*
p
==
'"'
||
*
p
==
'\''
)
{
nextword
=
p
;
state
=
*
p
;
continue
;
}
nextword
=
p
;
state
=
'a'
;
continue
;
case
'a'
:
if
(
isspace
(
*
p
))
{
complete_word
(
&
result
,
nextword
,
p
,
&
result_capacity
,
&
result_count
);
state
=
' '
;
continue
;
}
continue
;
case
'"'
:
case
'\''
:
if
(
*
p
==
state
)
{
complete_word
(
&
result
,
nextword
+
1
,
p
,
&
result_capacity
,
&
result_count
);
state
=
' '
;
continue
;
}
continue
;
}
}
if
(
state
==
'a'
)
complete_word
(
&
result
,
nextword
,
p
,
&
result_capacity
,
&
result_count
);
return
realloc
(
result
,
(
result_count
+
1
)
*
sizeof
(
char
*
));
}
char
**
lxc_string_split_and_trim
(
const
char
*
string
,
char
_sep
)
{
char
*
token
,
*
str
,
*
saveptr
=
NULL
;
...
...
src/lxc/utils.h
View file @
c38d860c
...
...
@@ -292,6 +292,7 @@ extern bool lxc_string_in_list(const char *needle, const char *haystack,
char
sep
);
extern
char
**
lxc_string_split
(
const
char
*
string
,
char
sep
);
extern
char
**
lxc_string_split_and_trim
(
const
char
*
string
,
char
sep
);
extern
char
**
lxc_string_split_quoted
(
char
*
string
);
/* Append string to NULL-terminated string array. */
extern
int
lxc_append_string
(
char
***
list
,
char
*
entry
);
...
...
templates/lxc-oci.in
View file @
c38d860c
...
...
@@ -197,7 +197,7 @@ entrypoint=$(getep ${DOWNLOAD_TEMP} latest)
rm
-rf
"
${
LXC_ROOTFS
}
.tmp"
LXC_CONF_FILE
=
"
${
LXC_PATH
}
/config"
echo
"lxc.execute.cmd =
${
entrypoint
}
"
>>
"
${
LXC_CONF_FILE
}
"
echo
"lxc.execute.cmd =
'
${
entrypoint
}
'
"
>>
"
${
LXC_CONF_FILE
}
"
echo
"lxc.mount.auto = proc:mixed sys:mixed cgroup:mixed"
>>
"
${
LXC_CONF_FILE
}
"
echo
"lxc.uts.name =
${
LXC_NAME
}
"
>>
${
LXC_PATH
}
/config
...
...
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