mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-16 05:25:40 +00:00
Merge pull request #2893 from brauner/2019-03-04/minor_tweaks
minor tweaks
This commit is contained in:
commit
859ce01182
@ -1450,6 +1450,26 @@ static int set_config_cgroup_relative(const char *key, const char *value,
|
||||
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,
|
||||
struct lxc_conf *lxc_conf, void *data)
|
||||
{
|
||||
@ -2081,6 +2101,40 @@ static int set_config_console_size(const char *key, const char *value,
|
||||
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)
|
||||
{
|
||||
size_t linelen;
|
||||
@ -3014,7 +3068,7 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
|
||||
else
|
||||
lend++;
|
||||
|
||||
if (!lxc_config_net_hwaddr(lstart)) {
|
||||
if (!lxc_config_net_is_hwaddr(lstart)) {
|
||||
lstart = lend;
|
||||
continue;
|
||||
}
|
||||
|
@ -548,6 +548,27 @@ int network_ifname(char *valuep, const char *value, size_t size)
|
||||
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)
|
||||
{
|
||||
const char hex[] = "0123456789abcdef";
|
||||
@ -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)
|
||||
{
|
||||
int ret;
|
||||
@ -734,26 +700,6 @@ int lxc_get_conf_uint64(struct lxc_conf *c, char *retv, int inlen, uint64_t v)
|
||||
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,
|
||||
const char *lxcpath)
|
||||
{
|
||||
|
@ -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 network_ifname(char *valuep, const char *value, size_t size);
|
||||
extern void rand_complete_hwaddr(char *hwaddr);
|
||||
extern bool lxc_config_net_hwaddr(const char *line);
|
||||
extern void update_hwaddr(const char *line);
|
||||
extern bool lxc_config_net_is_hwaddr(const char *line);
|
||||
extern bool new_hwaddr(char *hwaddr);
|
||||
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_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_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,
|
||||
const char *lxcpath, const char *namespace);
|
||||
extern int sig_parse(const char *signame);
|
||||
|
@ -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);
|
||||
|
||||
if (lxc_config_net_hwaddr("lxc.net"))
|
||||
if (lxc_config_net_is_hwaddr("lxc.net"))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (lxc_config_net_hwaddr("lxc.net."))
|
||||
if (lxc_config_net_is_hwaddr("lxc.net."))
|
||||
exit(EXIT_FAILURE);
|
||||
|
||||
if (lxc_config_net_hwaddr("lxc.net.0."))
|
||||
if (lxc_config_net_is_hwaddr("lxc.net.0."))
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@ -604,7 +604,7 @@ int main(int argc, char *argv[])
|
||||
test_lxc_safe_int();
|
||||
test_lxc_safe_long();
|
||||
test_parse_byte_size_string();
|
||||
test_lxc_config_net_hwaddr();
|
||||
test_lxc_config_net_is_hwaddr();
|
||||
test_task_blocks_signal();
|
||||
|
||||
exit(EXIT_SUCCESS);
|
||||
|
Loading…
Reference in New Issue
Block a user