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
859ce011
Unverified
Commit
859ce011
authored
Mar 05, 2019
by
Stéphane Graber
Committed by
GitHub
Mar 05, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2893 from brauner/2019-03-04/minor_tweaks
minor tweaks
parents
8690bff1
f7662514
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
85 deletions
+83
-85
confile.c
src/lxc/confile.c
+55
-1
confile_utils.c
src/lxc/confile_utils.c
+21
-75
confile_utils.h
src/lxc/confile_utils.h
+1
-3
lxc-test-utils.c
src/tests/lxc-test-utils.c
+6
-6
No files found.
src/lxc/confile.c
View file @
859ce011
...
@@ -1450,6 +1450,26 @@ static int set_config_cgroup_relative(const char *key, const char *value,
...
@@ -1450,6 +1450,26 @@ static int set_config_cgroup_relative(const char *key, const char *value,
return
-
EINVAL
;
return
-
EINVAL
;
}
}
static
bool
parse_limit_value
(
const
char
**
value
,
rlim_t
*
res
)
{
char
*
endptr
=
NULL
;
if
(
strncmp
(
*
value
,
"unlimited"
,
STRLITERALLEN
(
"unlimited"
))
==
0
)
{
*
res
=
RLIM_INFINITY
;
*
value
+=
STRLITERALLEN
(
"unlimited"
);
return
true
;
}
errno
=
0
;
*
res
=
strtoull
(
*
value
,
&
endptr
,
10
);
if
(
errno
||
!
endptr
)
return
false
;
*
value
=
endptr
;
return
true
;
}
static
int
set_config_prlimit
(
const
char
*
key
,
const
char
*
value
,
static
int
set_config_prlimit
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
...
@@ -2081,6 +2101,40 @@ static int set_config_console_size(const char *key, const char *value,
...
@@ -2081,6 +2101,40 @@ static int set_config_console_size(const char *key, const char *value,
return
0
;
return
0
;
}
}
/*
* If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
* file, we expand it in the unexpanded_config, so that after a save_config we
* store the hwaddr for re-use.
* This is only called when reading the config file, not when executing a
* lxc.include.
* 'x' and 'X' are substituted in-place.
*/
static
void
update_hwaddr
(
const
char
*
line
)
{
char
*
p
;
line
+=
lxc_char_left_gc
(
line
,
strlen
(
line
));
if
(
line
[
0
]
==
'#'
)
return
;
if
(
!
lxc_config_net_is_hwaddr
(
line
))
return
;
/* Let config_net_hwaddr raise the error. */
p
=
strchr
(
line
,
'='
);
if
(
!
p
)
return
;
p
++
;
while
(
isblank
(
*
p
))
p
++
;
if
(
!*
p
)
return
;
rand_complete_hwaddr
(
p
);
}
int
append_unexp_config_line
(
const
char
*
line
,
struct
lxc_conf
*
conf
)
int
append_unexp_config_line
(
const
char
*
line
,
struct
lxc_conf
*
conf
)
{
{
size_t
linelen
;
size_t
linelen
;
...
@@ -3014,7 +3068,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
...
@@ -3014,7 +3068,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
else
else
lend
++
;
lend
++
;
if
(
!
lxc_config_net_hwaddr
(
lstart
))
{
if
(
!
lxc_config_net_
is_
hwaddr
(
lstart
))
{
lstart
=
lend
;
lstart
=
lend
;
continue
;
continue
;
}
}
...
...
src/lxc/confile_utils.c
View file @
859ce011
...
@@ -548,6 +548,27 @@ int network_ifname(char *valuep, const char *value, size_t size)
...
@@ -548,6 +548,27 @@ int network_ifname(char *valuep, const char *value, size_t size)
return
0
;
return
0
;
}
}
bool
lxc_config_net_is_hwaddr
(
const
char
*
line
)
{
unsigned
index
;
char
tmp
[
7
];
if
(
strncmp
(
line
,
"lxc.net"
,
7
)
!=
0
)
return
false
;
if
(
strncmp
(
line
,
"lxc.net.hwaddr"
,
14
)
==
0
)
return
true
;
if
(
strncmp
(
line
,
"lxc.network.hwaddr"
,
18
)
==
0
)
return
true
;
if
(
sscanf
(
line
,
"lxc.net.%u.%6s"
,
&
index
,
tmp
)
==
2
||
sscanf
(
line
,
"lxc.network.%u.%6s"
,
&
index
,
tmp
)
==
2
)
return
strncmp
(
tmp
,
"hwaddr"
,
6
)
==
0
;
return
false
;
}
void
rand_complete_hwaddr
(
char
*
hwaddr
)
void
rand_complete_hwaddr
(
char
*
hwaddr
)
{
{
const
char
hex
[]
=
"0123456789abcdef"
;
const
char
hex
[]
=
"0123456789abcdef"
;
...
@@ -580,61 +601,6 @@ void rand_complete_hwaddr(char *hwaddr)
...
@@ -580,61 +601,6 @@ void rand_complete_hwaddr(char *hwaddr)
}
}
}
}
bool
lxc_config_net_hwaddr
(
const
char
*
line
)
{
unsigned
index
;
char
tmp
[
7
];
if
(
strncmp
(
line
,
"lxc.net"
,
7
)
!=
0
)
return
false
;
if
(
strncmp
(
line
,
"lxc.net.hwaddr"
,
14
)
==
0
)
return
true
;
if
(
strncmp
(
line
,
"lxc.network.hwaddr"
,
18
)
==
0
)
return
true
;
if
(
sscanf
(
line
,
"lxc.net.%u.%6s"
,
&
index
,
tmp
)
==
2
||
sscanf
(
line
,
"lxc.network.%u.%6s"
,
&
index
,
tmp
)
==
2
)
return
strncmp
(
tmp
,
"hwaddr"
,
6
)
==
0
;
return
false
;
}
/*
* If we find a lxc.net.[i].hwaddr or lxc.network.hwaddr in the original config
* file, we expand it in the unexpanded_config, so that after a save_config we
* store the hwaddr for re-use.
* This is only called when reading the config file, not when executing a
* lxc.include.
* 'x' and 'X' are substituted in-place.
*/
void
update_hwaddr
(
const
char
*
line
)
{
char
*
p
;
line
+=
lxc_char_left_gc
(
line
,
strlen
(
line
));
if
(
line
[
0
]
==
'#'
)
return
;
if
(
!
lxc_config_net_hwaddr
(
line
))
return
;
/* Let config_net_hwaddr raise the error. */
p
=
strchr
(
line
,
'='
);
if
(
!
p
)
return
;
p
++
;
while
(
isblank
(
*
p
))
p
++
;
if
(
!*
p
)
return
;
rand_complete_hwaddr
(
p
);
}
bool
new_hwaddr
(
char
*
hwaddr
)
bool
new_hwaddr
(
char
*
hwaddr
)
{
{
int
ret
;
int
ret
;
...
@@ -734,26 +700,6 @@ int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v)
...
@@ -734,26 +700,6 @@ int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v)
return
fulllen
;
return
fulllen
;
}
}
bool
parse_limit_value
(
const
char
**
value
,
rlim_t
*
res
)
{
char
*
endptr
=
NULL
;
if
(
strncmp
(
*
value
,
"unlimited"
,
STRLITERALLEN
(
"unlimited"
))
==
0
)
{
*
res
=
RLIM_INFINITY
;
*
value
+=
STRLITERALLEN
(
"unlimited"
);
return
true
;
}
errno
=
0
;
*
res
=
strtoull
(
*
value
,
&
endptr
,
10
);
if
(
errno
||
!
endptr
)
return
false
;
*
value
=
endptr
;
return
true
;
}
static
int
lxc_container_name_to_pid
(
const
char
*
lxcname_or_pid
,
static
int
lxc_container_name_to_pid
(
const
char
*
lxcname_or_pid
,
const
char
*
lxcpath
)
const
char
*
lxcpath
)
{
{
...
...
src/lxc/confile_utils.h
View file @
859ce011
...
@@ -66,15 +66,13 @@ extern int set_config_path_item(char **conf_item, const char *value);
...
@@ -66,15 +66,13 @@ extern int set_config_path_item(char **conf_item, const char *value);
extern
int
config_ip_prefix
(
struct
in_addr
*
addr
);
extern
int
config_ip_prefix
(
struct
in_addr
*
addr
);
extern
int
network_ifname
(
char
*
valuep
,
const
char
*
value
,
size_t
size
);
extern
int
network_ifname
(
char
*
valuep
,
const
char
*
value
,
size_t
size
);
extern
void
rand_complete_hwaddr
(
char
*
hwaddr
);
extern
void
rand_complete_hwaddr
(
char
*
hwaddr
);
extern
bool
lxc_config_net_hwaddr
(
const
char
*
line
);
extern
bool
lxc_config_net_is_hwaddr
(
const
char
*
line
);
extern
void
update_hwaddr
(
const
char
*
line
);
extern
bool
new_hwaddr
(
char
*
hwaddr
);
extern
bool
new_hwaddr
(
char
*
hwaddr
);
extern
int
lxc_get_conf_str
(
char
*
retv
,
int
inlen
,
const
char
*
value
);
extern
int
lxc_get_conf_str
(
char
*
retv
,
int
inlen
,
const
char
*
value
);
extern
int
lxc_get_conf_bool
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
bool
v
);
extern
int
lxc_get_conf_bool
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
bool
v
);
extern
int
lxc_get_conf_int
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
int
v
);
extern
int
lxc_get_conf_int
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
int
v
);
extern
int
lxc_get_conf_size_t
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
size_t
v
);
extern
int
lxc_get_conf_size_t
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
size_t
v
);
extern
int
lxc_get_conf_uint64
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
uint64_t
v
);
extern
int
lxc_get_conf_uint64
(
struct
lxc_conf
*
c
,
char
*
retv
,
int
inlen
,
uint64_t
v
);
extern
bool
parse_limit_value
(
const
char
**
value
,
rlim_t
*
res
);
extern
int
lxc_inherit_namespace
(
const
char
*
lxcname_or_pid
,
extern
int
lxc_inherit_namespace
(
const
char
*
lxcname_or_pid
,
const
char
*
lxcpath
,
const
char
*
namespace
);
const
char
*
lxcpath
,
const
char
*
namespace
);
extern
int
sig_parse
(
const
char
*
signame
);
extern
int
sig_parse
(
const
char
*
signame
);
...
...
src/tests/lxc-test-utils.c
View file @
859ce011
...
@@ -518,18 +518,18 @@ void test_parse_byte_size_string(void)
...
@@ -518,18 +518,18 @@ void test_parse_byte_size_string(void)
}
}
}
}
void
test_lxc_config_net_hwaddr
(
void
)
void
test_lxc_config_net_
is_
hwaddr
(
void
)
{
{
if
(
!
lxc_config_net_hwaddr
(
"lxc.net.0.hwaddr = 00:16:3e:04:65:b8
\n
"
))
if
(
!
lxc_config_net_
is_
hwaddr
(
"lxc.net.0.hwaddr = 00:16:3e:04:65:b8
\n
"
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net"
))
if
(
lxc_config_net_
is_
hwaddr
(
"lxc.net"
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net."
))
if
(
lxc_config_net_
is_
hwaddr
(
"lxc.net."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
if
(
lxc_config_net_hwaddr
(
"lxc.net.0."
))
if
(
lxc_config_net_
is_
hwaddr
(
"lxc.net.0."
))
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
}
...
@@ -604,7 +604,7 @@ int main(int argc, char *argv[])
...
@@ -604,7 +604,7 @@ int main(int argc, char *argv[])
test_lxc_safe_int
();
test_lxc_safe_int
();
test_lxc_safe_long
();
test_lxc_safe_long
();
test_parse_byte_size_string
();
test_parse_byte_size_string
();
test_lxc_config_net_hwaddr
();
test_lxc_config_net_
is_
hwaddr
();
test_task_blocks_signal
();
test_task_blocks_signal
();
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