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
240d4b74
Commit
240d4b74
authored
Jun 28, 2017
by
0x0916
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
confile: rename lxc.limit to lxc.prlimit
Signed-off-by:
0x0916
<
w@laoqinren.net
>
parent
86ccab2e
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
214 additions
and
38 deletions
+214
-38
lxc.container.conf.sgml.in
doc/ja/lxc.container.conf.sgml.in
+1
-1
lxc.container.conf.sgml.in
doc/lxc.container.conf.sgml.in
+1
-1
conf.c
src/lxc/conf.c
+5
-2
confile.c
src/lxc/confile.c
+19
-32
confile_legacy.c
src/lxc/confile_legacy.c
+156
-0
confile_legacy.h
src/lxc/confile_legacy.h
+1
-0
confile_utils.c
src/lxc/confile_utils.c
+20
-0
confile_utils.h
src/lxc/confile_utils.h
+1
-1
parse_config_file.c
src/tests/parse_config_file.c
+10
-1
No files found.
doc/ja/lxc.container.conf.sgml.in
View file @
240d4b74
...
@@ -1684,7 +1684,7 @@ by KATOH Yasufumi <karma at jazz.email.ne.jp>
...
@@ -1684,7 +1684,7 @@ by KATOH Yasufumi <karma at jazz.email.ne.jp>
<variablelist>
<variablelist>
<varlistentry>
<varlistentry>
<term>
<term>
<option>lxc.limit.[limit name]</option>
<option>lxc.
pr
limit.[limit name]</option>
</term>
</term>
<listitem>
<listitem>
<para>
<para>
...
...
doc/lxc.container.conf.sgml.in
View file @
240d4b74
...
@@ -1201,7 +1201,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
...
@@ -1201,7 +1201,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
<variablelist>
<variablelist>
<varlistentry>
<varlistentry>
<term>
<term>
<option>lxc.limit.[limit name]</option>
<option>lxc.
pr
limit.[limit name]</option>
</term>
</term>
<listitem>
<listitem>
<para>
<para>
...
...
src/lxc/conf.c
View file @
240d4b74
...
@@ -4350,10 +4350,13 @@ int lxc_clear_limits(struct lxc_conf *c, const char *key)
...
@@ -4350,10 +4350,13 @@ int lxc_clear_limits(struct lxc_conf *c, const char *key)
bool
all
=
false
;
bool
all
=
false
;
const
char
*
k
=
NULL
;
const
char
*
k
=
NULL
;
if
(
strcmp
(
key
,
"lxc.limit"
)
==
0
)
if
(
strcmp
(
key
,
"lxc.limit"
)
==
0
||
strcmp
(
key
,
"lxc.prlimit"
))
all
=
true
;
all
=
true
;
else
if
(
strncmp
(
key
,
"lxc.limit."
,
sizeof
(
"lxc.limit."
)
-
1
)
==
0
)
else
if
(
strncmp
(
key
,
"lxc.limit."
,
sizeof
(
"lxc.limit."
)
-
1
)
==
0
)
k
=
key
+
sizeof
(
"lxc.limit."
)
-
1
;
k
=
key
+
sizeof
(
"lxc.limit."
)
-
1
;
else
if
(
strncmp
(
key
,
"lxc.prlimit."
,
sizeof
(
"lxc.prlimit."
)
-
1
)
==
0
)
k
=
key
+
sizeof
(
"lxc.prlimit."
)
-
1
;
else
else
return
-
1
;
return
-
1
;
...
@@ -4515,7 +4518,7 @@ void lxc_conf_free(struct lxc_conf *conf)
...
@@ -4515,7 +4518,7 @@ void lxc_conf_free(struct lxc_conf *conf)
lxc_clear_includes
(
conf
);
lxc_clear_includes
(
conf
);
lxc_clear_aliens
(
conf
);
lxc_clear_aliens
(
conf
);
lxc_clear_environment
(
conf
);
lxc_clear_environment
(
conf
);
lxc_clear_limits
(
conf
,
"lxc.limit"
);
lxc_clear_limits
(
conf
,
"lxc.
pr
limit"
);
free
(
conf
);
free
(
conf
);
}
}
...
...
src/lxc/confile.c
View file @
240d4b74
...
@@ -131,7 +131,7 @@ lxc_config_define(init_gid);
...
@@ -131,7 +131,7 @@ lxc_config_define(init_gid);
lxc_config_define
(
ephemeral
);
lxc_config_define
(
ephemeral
);
lxc_config_define
(
syslog
);
lxc_config_define
(
syslog
);
lxc_config_define
(
no_new_privs
);
lxc_config_define
(
no_new_privs
);
lxc_config_define
(
limit
);
lxc_config_define
(
pr
limit
);
static
struct
lxc_config_t
config
[]
=
{
static
struct
lxc_config_t
config
[]
=
{
{
"lxc.arch"
,
set_config_personality
,
get_config_personality
,
clr_config_personality
,
},
{
"lxc.arch"
,
set_config_personality
,
get_config_personality
,
clr_config_personality
,
},
...
@@ -232,7 +232,13 @@ static struct lxc_config_t config[] = {
...
@@ -232,7 +232,13 @@ static struct lxc_config_t config[] = {
{
"lxc.ephemeral"
,
set_config_ephemeral
,
get_config_ephemeral
,
clr_config_ephemeral
,
},
{
"lxc.ephemeral"
,
set_config_ephemeral
,
get_config_ephemeral
,
clr_config_ephemeral
,
},
{
"lxc.syslog"
,
set_config_syslog
,
get_config_syslog
,
clr_config_syslog
,
},
{
"lxc.syslog"
,
set_config_syslog
,
get_config_syslog
,
clr_config_syslog
,
},
{
"lxc.no_new_privs"
,
set_config_no_new_privs
,
get_config_no_new_privs
,
clr_config_no_new_privs
,
},
{
"lxc.no_new_privs"
,
set_config_no_new_privs
,
get_config_no_new_privs
,
clr_config_no_new_privs
,
},
/* REMOVE IN LXC 3.0
legacy keys
*/
{
"lxc.limit"
,
set_config_limit
,
get_config_limit
,
clr_config_limit
,
},
{
"lxc.limit"
,
set_config_limit
,
get_config_limit
,
clr_config_limit
,
},
{
"lxc.prlimit"
,
set_config_prlimit
,
get_config_prlimit
,
clr_config_prlimit
,
},
};
};
struct
signame
{
struct
signame
{
...
@@ -1554,26 +1560,7 @@ out:
...
@@ -1554,26 +1560,7 @@ out:
return
-
1
;
return
-
1
;
}
}
static
bool
parse_limit_value
(
const
char
**
value
,
unsigned
long
*
res
)
static
int
set_config_prlimit
(
const
char
*
key
,
const
char
*
value
,
{
char
*
endptr
=
NULL
;
if
(
strncmp
(
*
value
,
"unlimited"
,
sizeof
(
"unlimited"
)
-
1
)
==
0
)
{
*
res
=
RLIM_INFINITY
;
*
value
+=
sizeof
(
"unlimited"
)
-
1
;
return
true
;
}
errno
=
0
;
*
res
=
strtoul
(
*
value
,
&
endptr
,
10
);
if
(
errno
||
!
endptr
)
return
false
;
*
value
=
endptr
;
return
true
;
}
static
int
set_config_limit
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
{
struct
lxc_list
*
iter
;
struct
lxc_list
*
iter
;
...
@@ -1585,10 +1572,10 @@ static int set_config_limit(const char *key, const char *value,
...
@@ -1585,10 +1572,10 @@ static int set_config_limit(const char *key, const char *value,
if
(
lxc_config_value_empty
(
value
))
if
(
lxc_config_value_empty
(
value
))
return
lxc_clear_limits
(
lxc_conf
,
key
);
return
lxc_clear_limits
(
lxc_conf
,
key
);
if
(
strncmp
(
key
,
"lxc.
limit."
,
sizeof
(
"lxc.
limit."
)
-
1
)
!=
0
)
if
(
strncmp
(
key
,
"lxc.
prlimit."
,
sizeof
(
"lxc.pr
limit."
)
-
1
)
!=
0
)
return
-
1
;
return
-
1
;
key
+=
sizeof
(
"lxc.limit."
)
-
1
;
key
+=
sizeof
(
"lxc.
pr
limit."
)
-
1
;
/* soft limit comes first in the value */
/* soft limit comes first in the value */
if
(
!
parse_limit_value
(
&
value
,
&
limit_value
))
if
(
!
parse_limit_value
(
&
value
,
&
limit_value
))
...
@@ -3275,11 +3262,11 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen,
...
@@ -3275,11 +3262,11 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen,
}
}
/*
/*
* If you ask for a specific value, i.e. lxc.limit.nofile, then just the value
* If you ask for a specific value, i.e. lxc.
pr
limit.nofile, then just the value
* will be printed. If you ask for 'lxc.limit', then all limit entries will be
* will be printed. If you ask for 'lxc.
pr
limit', then all limit entries will be
* printed, in 'lxc.limit.resource = value' format.
* printed, in 'lxc.
pr
limit.resource = value' format.
*/
*/
static
int
get_config_limit
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
static
int
get_config_
pr
limit
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
struct
lxc_conf
*
c
,
void
*
data
)
{
{
int
fulllen
=
0
,
len
;
int
fulllen
=
0
,
len
;
...
@@ -3291,10 +3278,10 @@ static int get_config_limit(const char *key, char *retv, int inlen,
...
@@ -3291,10 +3278,10 @@ static int get_config_limit(const char *key, char *retv, int inlen,
else
else
memset
(
retv
,
0
,
inlen
);
memset
(
retv
,
0
,
inlen
);
if
(
!
strcmp
(
key
,
"lxc.limit"
))
if
(
!
strcmp
(
key
,
"lxc.
pr
limit"
))
get_all
=
true
;
get_all
=
true
;
else
if
(
strncmp
(
key
,
"lxc.
limit."
,
10
)
==
0
)
else
if
(
strncmp
(
key
,
"lxc.
prlimit."
,
12
)
==
0
)
key
+=
1
0
;
key
+=
1
2
;
else
else
return
-
1
;
return
-
1
;
...
@@ -3323,7 +3310,7 @@ static int get_config_limit(const char *key, char *retv, int inlen,
...
@@ -3323,7 +3310,7 @@ static int get_config_limit(const char *key, char *retv, int inlen,
}
}
if
(
get_all
)
{
if
(
get_all
)
{
strprint
(
retv
,
inlen
,
"lxc.limit.%s = %s
\n
"
,
strprint
(
retv
,
inlen
,
"lxc.
pr
limit.%s = %s
\n
"
,
lim
->
resource
,
buf
);
lim
->
resource
,
buf
);
}
else
if
(
strcmp
(
lim
->
resource
,
key
)
==
0
)
{
}
else
if
(
strcmp
(
lim
->
resource
,
key
)
==
0
)
{
strprint
(
retv
,
inlen
,
"%s"
,
buf
);
strprint
(
retv
,
inlen
,
"%s"
,
buf
);
...
@@ -3628,7 +3615,7 @@ static inline int clr_config_no_new_privs(const char *key, struct lxc_conf *c,
...
@@ -3628,7 +3615,7 @@ static inline int clr_config_no_new_privs(const char *key, struct lxc_conf *c,
return
0
;
return
0
;
}
}
static
inline
int
clr_config_limit
(
const
char
*
key
,
struct
lxc_conf
*
c
,
static
inline
int
clr_config_
pr
limit
(
const
char
*
key
,
struct
lxc_conf
*
c
,
void
*
data
)
void
*
data
)
{
{
return
lxc_clear_limits
(
c
,
key
);
return
lxc_clear_limits
(
c
,
key
);
...
...
src/lxc/confile_legacy.c
View file @
240d4b74
...
@@ -1079,3 +1079,159 @@ inline int clr_config_lsm_se_context(const char *key, struct lxc_conf *c,
...
@@ -1079,3 +1079,159 @@ inline int clr_config_lsm_se_context(const char *key, struct lxc_conf *c,
c
->
lsm_se_context
=
NULL
;
c
->
lsm_se_context
=
NULL
;
return
0
;
return
0
;
}
}
extern
int
set_config_limit
(
const
char
*
key
,
const
char
*
value
,
struct
lxc_conf
*
lxc_conf
,
void
*
data
)
{
struct
lxc_list
*
iter
;
struct
rlimit
limit
;
unsigned
long
limit_value
;
struct
lxc_list
*
limlist
=
NULL
;
struct
lxc_limit
*
limelem
=
NULL
;
if
(
lxc_config_value_empty
(
value
))
return
lxc_clear_limits
(
lxc_conf
,
key
);
if
(
strncmp
(
key
,
"lxc.limit."
,
sizeof
(
"lxc.limit."
)
-
1
)
!=
0
)
return
-
1
;
key
+=
sizeof
(
"lxc.limit."
)
-
1
;
/* soft limit comes first in the value */
if
(
!
parse_limit_value
(
&
value
,
&
limit_value
))
return
-
1
;
limit
.
rlim_cur
=
limit_value
;
/* skip spaces and a colon */
while
(
isspace
(
*
value
))
++
value
;
if
(
*
value
==
':'
)
++
value
;
else
if
(
*
value
)
/* any other character is an error here */
return
-
1
;
while
(
isspace
(
*
value
))
++
value
;
/* optional hard limit */
if
(
*
value
)
{
if
(
!
parse_limit_value
(
&
value
,
&
limit_value
))
return
-
1
;
limit
.
rlim_max
=
limit_value
;
/* check for trailing garbage */
while
(
isspace
(
*
value
))
++
value
;
if
(
*
value
)
return
-
1
;
}
else
{
/* a single value sets both hard and soft limit */
limit
.
rlim_max
=
limit
.
rlim_cur
;
}
/* find existing list element */
lxc_list_for_each
(
iter
,
&
lxc_conf
->
limits
)
{
limelem
=
iter
->
elem
;
if
(
!
strcmp
(
key
,
limelem
->
resource
))
{
limelem
->
limit
=
limit
;
return
0
;
}
}
/* allocate list element */
limlist
=
malloc
(
sizeof
(
*
limlist
));
if
(
!
limlist
)
goto
out
;
limelem
=
malloc
(
sizeof
(
*
limelem
));
if
(
!
limelem
)
goto
out
;
memset
(
limelem
,
0
,
sizeof
(
*
limelem
));
limelem
->
resource
=
strdup
(
key
);
if
(
!
limelem
->
resource
)
goto
out
;
limelem
->
limit
=
limit
;
limlist
->
elem
=
limelem
;
lxc_list_add_tail
(
&
lxc_conf
->
limits
,
limlist
);
return
0
;
out:
free
(
limlist
);
if
(
limelem
)
{
free
(
limelem
->
resource
);
free
(
limelem
);
}
return
-
1
;
}
/*
* If you ask for a specific value, i.e. lxc.limit.nofile, then just the value
* will be printed. If you ask for 'lxc.limit', then all limit entries will be
* printed, in 'lxc.limit.resource = value' format.
*/
extern
int
get_config_limit
(
const
char
*
key
,
char
*
retv
,
int
inlen
,
struct
lxc_conf
*
c
,
void
*
data
)
{
int
fulllen
=
0
,
len
;
bool
get_all
=
false
;
struct
lxc_list
*
it
;
if
(
!
retv
)
inlen
=
0
;
else
memset
(
retv
,
0
,
inlen
);
if
(
!
strcmp
(
key
,
"lxc.limit"
))
get_all
=
true
;
else
if
(
strncmp
(
key
,
"lxc.limit."
,
10
)
==
0
)
key
+=
10
;
else
return
-
1
;
lxc_list_for_each
(
it
,
&
c
->
limits
)
{
char
buf
[
LXC_NUMSTRLEN64
*
2
+
2
];
/* 2 colon separated 64 bit
integers or the word
'unlimited' */
int
partlen
;
struct
lxc_limit
*
lim
=
it
->
elem
;
if
(
lim
->
limit
.
rlim_cur
==
RLIM_INFINITY
)
{
memcpy
(
buf
,
"unlimited"
,
sizeof
(
"unlimited"
));
partlen
=
sizeof
(
"unlimited"
)
-
1
;
}
else
{
partlen
=
sprintf
(
buf
,
"%"
PRIu64
,
(
uint64_t
)
lim
->
limit
.
rlim_cur
);
}
if
(
lim
->
limit
.
rlim_cur
!=
lim
->
limit
.
rlim_max
)
{
if
(
lim
->
limit
.
rlim_max
==
RLIM_INFINITY
)
{
memcpy
(
buf
+
partlen
,
":unlimited"
,
sizeof
(
":unlimited"
));
}
else
{
sprintf
(
buf
+
partlen
,
":%"
PRIu64
,
(
uint64_t
)
lim
->
limit
.
rlim_max
);
}
}
if
(
get_all
)
{
strprint
(
retv
,
inlen
,
"lxc.limit.%s = %s
\n
"
,
lim
->
resource
,
buf
);
}
else
if
(
strcmp
(
lim
->
resource
,
key
)
==
0
)
{
strprint
(
retv
,
inlen
,
"%s"
,
buf
);
}
}
return
fulllen
;
}
extern
int
clr_config_limit
(
const
char
*
key
,
struct
lxc_conf
*
c
,
void
*
data
)
{
return
lxc_clear_limits
(
c
,
key
);
}
src/lxc/confile_legacy.h
View file @
240d4b74
...
@@ -86,5 +86,6 @@ lxc_config_legacy_define(network_legacy);
...
@@ -86,5 +86,6 @@ lxc_config_legacy_define(network_legacy);
lxc_config_legacy_define
(
lsm_aa_profile
);
lxc_config_legacy_define
(
lsm_aa_profile
);
lxc_config_legacy_define
(
lsm_aa_incomplete
);
lxc_config_legacy_define
(
lsm_aa_incomplete
);
lxc_config_legacy_define
(
lsm_se_context
);
lxc_config_legacy_define
(
lsm_se_context
);
lxc_config_legacy_define
(
limit
);
#endif
/* __LXC_CONFILE_LEGACY_H */
#endif
/* __LXC_CONFILE_LEGACY_H */
src/lxc/confile_utils.c
View file @
240d4b74
...
@@ -661,3 +661,23 @@ int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v)
...
@@ -661,3 +661,23 @@ int lxc_get_conf_int(struct lxc_conf *c, char *retv, int inlen, int v)
return
snprintf
(
retv
,
inlen
,
"%d"
,
v
);
return
snprintf
(
retv
,
inlen
,
"%d"
,
v
);
}
}
bool
parse_limit_value
(
const
char
**
value
,
unsigned
long
*
res
)
{
char
*
endptr
=
NULL
;
if
(
strncmp
(
*
value
,
"unlimited"
,
sizeof
(
"unlimited"
)
-
1
)
==
0
)
{
*
res
=
RLIM_INFINITY
;
*
value
+=
sizeof
(
"unlimited"
)
-
1
;
return
true
;
}
errno
=
0
;
*
res
=
strtoul
(
*
value
,
&
endptr
,
10
);
if
(
errno
||
!
endptr
)
return
false
;
*
value
=
endptr
;
return
true
;
}
src/lxc/confile_utils.h
View file @
240d4b74
...
@@ -84,5 +84,5 @@ extern void update_hwaddr(const char *line);
...
@@ -84,5 +84,5 @@ 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_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
bool
parse_limit_value
(
const
char
**
value
,
unsigned
long
*
res
);
#endif
/* __LXC_CONFILE_UTILS_H */
#endif
/* __LXC_CONFILE_UTILS_H */
src/tests/parse_config_file.c
View file @
240d4b74
...
@@ -729,13 +729,22 @@ int main(int argc, char *argv[])
...
@@ -729,13 +729,22 @@ int main(int argc, char *argv[])
goto
non_test_error
;
goto
non_test_error
;
}
}
/* lxc.limit.nofile */
/* REMOVE IN LXC 3.0
legacy lxc.limit.* key
*/
if
(
set_get_compare_clear_save_load
(
c
,
"lxc.limit.nofile"
,
"65536"
,
if
(
set_get_compare_clear_save_load
(
c
,
"lxc.limit.nofile"
,
"65536"
,
tmpf
,
true
)
<
0
)
{
tmpf
,
true
)
<
0
)
{
lxc_error
(
"%s
\n
"
,
"lxc.limit.nofile"
);
lxc_error
(
"%s
\n
"
,
"lxc.limit.nofile"
);
goto
non_test_error
;
goto
non_test_error
;
}
}
/* lxc.prlimit.nofile */
if
(
set_get_compare_clear_save_load
(
c
,
"lxc.prlimit.nofile"
,
"65536"
,
tmpf
,
true
)
<
0
)
{
lxc_error
(
"%s
\n
"
,
"lxc.prlimit.nofile"
);
goto
non_test_error
;
}
if
(
test_idmap_parser
()
<
0
)
{
if
(
test_idmap_parser
()
<
0
)
{
lxc_error
(
"%s
\n
"
,
"failed to test parser for
\"
lxc.id_map
\"
"
);
lxc_error
(
"%s
\n
"
,
"failed to test parser for
\"
lxc.id_map
\"
"
);
goto
non_test_error
;
goto
non_test_error
;
...
...
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