confile: non-functional changes

parent d5aba460
...@@ -732,16 +732,16 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -732,16 +732,16 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
netdev->ipv4_gateway = NULL; netdev->ipv4_gateway = NULL;
netdev->ipv4_gateway_auto = true; netdev->ipv4_gateway_auto = true;
} else { } else {
int ret;
struct in_addr *gw; struct in_addr *gw;
gw = malloc(sizeof(*gw)); gw = malloc(sizeof(*gw));
if (!gw) { if (!gw)
SYSERROR("failed to allocate ipv4 gateway address");
return -1; return -1;
}
if (!inet_pton(AF_INET, value, gw)) { ret = inet_pton(AF_INET, value, gw);
SYSERROR("invalid ipv4 gateway address: %s", value); if (!ret || ret < 0) {
SYSERROR("Invalid ipv4 gateway address \"%s\"", value);
free(gw); free(gw);
return -1; return -1;
} }
...@@ -756,6 +756,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value, ...@@ -756,6 +756,7 @@ static int set_config_net_ipv4_gateway(const char *key, const char *value,
static int set_config_net_ipv6_address(const char *key, const char *value, static int set_config_net_ipv6_address(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
int ret;
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev; struct lxc_inet6dev *inet6dev;
struct lxc_list *list; struct lxc_list *list;
...@@ -772,15 +773,13 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -772,15 +773,13 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
return -1; return -1;
inet6dev = malloc(sizeof(*inet6dev)); inet6dev = malloc(sizeof(*inet6dev));
if (!inet6dev) { if (!inet6dev)
SYSERROR("failed to allocate ipv6 address");
return -1; return -1;
}
memset(inet6dev, 0, sizeof(*inet6dev)); memset(inet6dev, 0, sizeof(*inet6dev));
list = malloc(sizeof(*list)); list = malloc(sizeof(*list));
if (!list) { if (!list) {
SYSERROR("failed to allocate memory");
free(inet6dev); free(inet6dev);
return -1; return -1;
} }
...@@ -790,7 +789,6 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -790,7 +789,6 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
valdup = strdup(value); valdup = strdup(value);
if (!valdup) { if (!valdup) {
ERROR("no address specified");
free(list); free(list);
free(inet6dev); free(inet6dev);
return -1; return -1;
...@@ -805,8 +803,9 @@ static int set_config_net_ipv6_address(const char *key, const char *value, ...@@ -805,8 +803,9 @@ static int set_config_net_ipv6_address(const char *key, const char *value,
return -1; return -1;
} }
if (!inet_pton(AF_INET6, valdup, &inet6dev->addr)) { ret = inet_pton(AF_INET6, valdup, &inet6dev->addr);
SYSERROR("invalid ipv6 address: %s", valdup); if (!ret || ret < 0) {
SYSERROR("Invalid ipv6 address \"%s\"", valdup);
free(list); free(list);
free(inet6dev); free(inet6dev);
free(valdup); free(valdup);
...@@ -840,16 +839,16 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value, ...@@ -840,16 +839,16 @@ static int set_config_net_ipv6_gateway(const char *key, const char *value,
netdev->ipv6_gateway = NULL; netdev->ipv6_gateway = NULL;
netdev->ipv6_gateway_auto = true; netdev->ipv6_gateway_auto = true;
} else { } else {
int ret;
struct in6_addr *gw; struct in6_addr *gw;
gw = malloc(sizeof(*gw)); gw = malloc(sizeof(*gw));
if (!gw) { if (!gw)
SYSERROR("failed to allocate ipv6 gateway address");
return -1; return -1;
}
if (!inet_pton(AF_INET6, value, gw)) { ret = inet_pton(AF_INET6, value, gw);
SYSERROR("invalid ipv6 gateway address: %s", value); if (!ret || ret < 0) {
SYSERROR("Invalid ipv6 gateway address \"%s\"", value);
free(gw); free(gw);
return -1; return -1;
} }
...@@ -929,15 +928,14 @@ static int set_config_init_uid(const char *key, const char *value, ...@@ -929,15 +928,14 @@ static int set_config_init_uid(const char *key, const char *value,
{ {
unsigned int init_uid; unsigned int init_uid;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_uid = 0; lxc_conf->init_uid = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &init_uid) < 0) if (lxc_safe_uint(value, &init_uid) < 0)
return -1; return -1;
lxc_conf->init_uid = init_uid; lxc_conf->init_uid = init_uid;
return 0; return 0;
...@@ -948,15 +946,14 @@ static int set_config_init_gid(const char *key, const char *value, ...@@ -948,15 +946,14 @@ static int set_config_init_gid(const char *key, const char *value,
{ {
unsigned int init_gid; unsigned int init_gid;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_gid = 0; lxc_conf->init_gid = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &init_gid) < 0) if (lxc_safe_uint(value, &init_gid) < 0)
return -1; return -1;
lxc_conf->init_gid = init_gid; lxc_conf->init_gid = init_gid;
return 0; return 0;
...@@ -971,14 +968,13 @@ static int set_config_hooks(const char *key, const char *value, ...@@ -971,14 +968,13 @@ static int set_config_hooks(const char *key, const char *value,
return lxc_clear_hooks(lxc_conf, key); return lxc_clear_hooks(lxc_conf, key);
if (strcmp(key + 4, "hook") == 0) { if (strcmp(key + 4, "hook") == 0) {
ERROR("lxc.hook cannot take a value"); ERROR("lxc.hook must not have a value");
return -1; return -1;
} }
copy = strdup(value); copy = strdup(value);
if (!copy) { if (!copy)
SYSERROR("failed to dup string '%s'", value);
return -1; return -1;
}
if (strcmp(key + 9, "pre-start") == 0) if (strcmp(key + 9, "pre-start") == 0)
return add_hook(lxc_conf, LXCHOOK_PRESTART, copy); return add_hook(lxc_conf, LXCHOOK_PRESTART, copy);
...@@ -999,7 +995,6 @@ static int set_config_hooks(const char *key, const char *value, ...@@ -999,7 +995,6 @@ static int set_config_hooks(const char *key, const char *value,
else if (strcmp(key + 9, "destroy") == 0) else if (strcmp(key + 9, "destroy") == 0)
return add_hook(lxc_conf, LXCHOOK_DESTROY, copy); return add_hook(lxc_conf, LXCHOOK_DESTROY, copy);
SYSERROR("Unknown key: %s", key);
free(copy); free(copy);
return -1; return -1;
} }
...@@ -1012,7 +1007,7 @@ static int set_config_personality(const char *key, const char *value, ...@@ -1012,7 +1007,7 @@ static int set_config_personality(const char *key, const char *value,
if (personality >= 0) if (personality >= 0)
lxc_conf->personality = personality; lxc_conf->personality = personality;
else else
WARN("unsupported personality '%s'", value); WARN("Unsupported personality \"%s\"", value);
return 0; return 0;
} }
...@@ -1020,13 +1015,11 @@ static int set_config_personality(const char *key, const char *value, ...@@ -1020,13 +1015,11 @@ static int set_config_personality(const char *key, const char *value,
static int set_config_pty_max(const char *key, const char *value, static int set_config_pty_max(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->pts = 0; lxc_conf->pts = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->pts) < 0) if (lxc_safe_uint(value, &lxc_conf->pts) < 0)
return -1; return -1;
...@@ -1046,13 +1039,11 @@ static int set_config_start(const char *key, const char *value, ...@@ -1046,13 +1039,11 @@ static int set_config_start(const char *key, const char *value,
is_empty = lxc_config_value_empty(value); is_empty = lxc_config_value_empty(value);
if (*(key + 10) == 'a') { /* lxc.start.auto */ if (*(key + 10) == 'a') { /* lxc.start.auto */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_auto = 0; lxc_conf->start_auto = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0) if (lxc_safe_uint(value, &lxc_conf->start_auto) < 0)
return -1; return -1;
...@@ -1061,43 +1052,35 @@ static int set_config_start(const char *key, const char *value, ...@@ -1061,43 +1052,35 @@ static int set_config_start(const char *key, const char *value,
return 0; return 0;
} else if (*(key + 10) == 'd') { /* lxc.start.delay */ } else if (*(key + 10) == 'd') { /* lxc.start.delay */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_delay = 0; lxc_conf->start_delay = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_uint(value, &lxc_conf->start_delay); return lxc_safe_uint(value, &lxc_conf->start_delay);
} else if (*(key + 10) == 'o') { /* lxc.start.order */ } else if (*(key + 10) == 'o') { /* lxc.start.order */
/* Set config value to default. */
if (is_empty) { if (is_empty) {
lxc_conf->start_order = 0; lxc_conf->start_order = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_int(value, &lxc_conf->start_order); return lxc_safe_int(value, &lxc_conf->start_order);
} }
SYSERROR("Unknown key: %s", key);
return -1; return -1;
} }
static int set_config_monitor(const char *key, const char *value, static int set_config_monitor(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->monitor_unshare = 0; lxc_conf->monitor_unshare = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (strcmp(key + 12, "unshare") == 0) if (strcmp(key + 12, "unshare") == 0)
return lxc_safe_uint(value, &lxc_conf->monitor_unshare); return lxc_safe_uint(value, &lxc_conf->monitor_unshare);
SYSERROR("Unknown key: %s", key);
return -1; return -1;
} }
...@@ -1112,13 +1095,11 @@ static int set_config_group(const char *key, const char *value, ...@@ -1112,13 +1095,11 @@ static int set_config_group(const char *key, const char *value,
return lxc_clear_groups(lxc_conf); return lxc_clear_groups(lxc_conf);
groups = strdup(value); groups = strdup(value);
if (!groups) { if (!groups)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several groups are specified in a single line /* In case several groups are specified in a single line split these
* split these groups in a single element for the list. * groups in a single element for the list.
*/ */
for (groupptr = groups;; groupptr = NULL) { for (groupptr = groups;; groupptr = NULL) {
token = strtok_r(groupptr, " \t", &sptr); token = strtok_r(groupptr, " \t", &sptr);
...@@ -1128,14 +1109,11 @@ static int set_config_group(const char *key, const char *value, ...@@ -1128,14 +1109,11 @@ static int set_config_group(const char *key, const char *value,
} }
grouplist = malloc(sizeof(*grouplist)); grouplist = malloc(sizeof(*grouplist));
if (!grouplist) { if (!grouplist)
SYSERROR("failed to allocate groups list");
break; break;
}
grouplist->elem = strdup(token); grouplist->elem = strdup(token);
if (!grouplist->elem) { if (!grouplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(grouplist); free(grouplist);
break; break;
} }
...@@ -1176,13 +1154,11 @@ on_error: ...@@ -1176,13 +1154,11 @@ on_error:
static int set_config_tty_max(const char *key, const char *value, static int set_config_tty_max(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->tty = 0; lxc_conf->tty = 0;
return 0; return 0;
} }
/* Parse new config value. */
return lxc_safe_uint(value, &lxc_conf->tty); return lxc_safe_uint(value, &lxc_conf->tty);
} }
...@@ -1204,21 +1180,16 @@ static int set_config_apparmor_allow_incomplete(const char *key, ...@@ -1204,21 +1180,16 @@ static int set_config_apparmor_allow_incomplete(const char *key,
struct lxc_conf *lxc_conf, struct lxc_conf *lxc_conf,
void *data) void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->lsm_aa_allow_incomplete = 0; lxc_conf->lsm_aa_allow_incomplete = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0) if (lxc_safe_uint(value, &lxc_conf->lsm_aa_allow_incomplete) < 0)
return -1; return -1;
if (lxc_conf->lsm_aa_allow_incomplete > 1) { if (lxc_conf->lsm_aa_allow_incomplete > 1)
ERROR("Wrong value for lxc.apparmor.allow_incomplete. Can only "
"be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -1246,6 +1217,7 @@ static int set_config_log_file(const char *key, const char *value, ...@@ -1246,6 +1217,7 @@ static int set_config_log_file(const char *key, const char *value,
ret = set_config_path_item(&c->logfile, value); ret = set_config_path_item(&c->logfile, value);
if (ret == 0) if (ret == 0)
ret = lxc_log_set_file(&c->logfd, c->logfile); ret = lxc_log_set_file(&c->logfd, c->logfile);
return ret; return ret;
} }
...@@ -1254,13 +1226,11 @@ static int set_config_log_level(const char *key, const char *value, ...@@ -1254,13 +1226,11 @@ static int set_config_log_level(const char *key, const char *value,
{ {
int newlevel; int newlevel;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->loglevel = LXC_LOG_LEVEL_NOTSET; lxc_conf->loglevel = LXC_LOG_LEVEL_NOTSET;
return 0; return 0;
} }
/* Parse new config value. */
if (value[0] >= '0' && value[0] <= '9') { if (value[0] >= '0' && value[0] <= '9') {
if (lxc_safe_int(value, &newlevel) < 0) if (lxc_safe_int(value, &newlevel) < 0)
return -1; return -1;
...@@ -1278,20 +1248,16 @@ static int set_config_log_level(const char *key, const char *value, ...@@ -1278,20 +1248,16 @@ static int set_config_log_level(const char *key, const char *value,
static int set_config_autodev(const char *key, const char *value, static int set_config_autodev(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->autodev = 0; lxc_conf->autodev = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->autodev) < 0) if (lxc_safe_uint(value, &lxc_conf->autodev) < 0)
return -1; return -1;
if (lxc_conf->autodev > 1) { if (lxc_conf->autodev > 1)
ERROR("Wrong value for lxc.autodev. Can only be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -1350,17 +1316,15 @@ static int set_config_signal_halt(const char *key, const char *value, ...@@ -1350,17 +1316,15 @@ static int set_config_signal_halt(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->haltsignal = 0; lxc_conf->haltsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->haltsignal = sig_n; lxc_conf->haltsignal = sig_n;
return 0; return 0;
...@@ -1371,16 +1335,15 @@ static int set_config_signal_reboot(const char *key, const char *value, ...@@ -1371,16 +1335,15 @@ static int set_config_signal_reboot(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->rebootsignal = 0; lxc_conf->rebootsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->rebootsignal = sig_n; lxc_conf->rebootsignal = sig_n;
return 0; return 0;
...@@ -1391,16 +1354,15 @@ static int set_config_signal_stop(const char *key, const char *value, ...@@ -1391,16 +1354,15 @@ static int set_config_signal_stop(const char *key, const char *value,
{ {
int sig_n; int sig_n;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->stopsignal = 0; lxc_conf->stopsignal = 0;
return 0; return 0;
} }
/* Parse new config value. */
sig_n = sig_parse(value); sig_n = sig_parse(value);
if (sig_n < 0) if (sig_n < 0)
return -1; return -1;
lxc_conf->stopsignal = sig_n; lxc_conf->stopsignal = sig_n;
return 0; return 0;
...@@ -1452,12 +1414,9 @@ static int set_config_cgroup(const char *key, const char *value, ...@@ -1452,12 +1414,9 @@ static int set_config_cgroup(const char *key, const char *value,
out: out:
free(cglist); free(cglist);
if (cgelem) { if (cgelem) {
free(cgelem->subsystem); free(cgelem->subsystem);
free(cgelem->value); free(cgelem->value);
free(cgelem); free(cgelem);
} }
...@@ -1580,7 +1539,7 @@ static int set_config_idmaps(const char *key, const char *value, ...@@ -1580,7 +1539,7 @@ static int set_config_idmaps(const char *key, const char *value,
if (ret < 0) if (ret < 0)
goto on_error; goto on_error;
INFO("read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range); INFO("Read uid map: type %c nsid %lu hostid %lu range %lu", type, nsid, hostid, range);
if (type == 'u') if (type == 'u')
idmap->idtype = ID_TYPE_UID; idmap->idtype = ID_TYPE_UID;
else if (type == 'g') else if (type == 'g')
...@@ -1641,9 +1600,9 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1641,9 +1600,9 @@ static int set_config_mount_auto(const char *key, const char *value,
{ "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED }, { "cgroup-full:mixed", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_MIXED },
{ "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO }, { "cgroup-full:ro", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RO },
{ "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW }, { "cgroup-full:rw", LXC_AUTO_CGROUP_MASK, LXC_AUTO_CGROUP_FULL_RW },
/* NB: For adding anything that is just a single on/off, but has /* For adding anything that is just a single on/off, but has no
* no options: keep mask and flag identical and just define the * options: keep mask and flag identical and just define the enum
* enum value as an unused bit so far * value as an unused bit so far
*/ */
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
...@@ -1654,10 +1613,8 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1654,10 +1613,8 @@ static int set_config_mount_auto(const char *key, const char *value,
} }
autos = strdup(value); autos = strdup(value);
if (!autos) { if (!autos)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
for (autoptr = autos;; autoptr = NULL) { for (autoptr = autos;; autoptr = NULL) {
token = strtok_r(autoptr, " \t", &sptr); token = strtok_r(autoptr, " \t", &sptr);
...@@ -1672,7 +1629,7 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1672,7 +1629,7 @@ static int set_config_mount_auto(const char *key, const char *value,
} }
if (!allowed_auto_mounts[i].token) { if (!allowed_auto_mounts[i].token) {
ERROR("Invalid filesystem to automount: %s", token); ERROR("Invalid filesystem to automount \"%s\"", token);
break; break;
} }
...@@ -1720,10 +1677,8 @@ static int set_config_cap_keep(const char *key, const char *value, ...@@ -1720,10 +1677,8 @@ static int set_config_cap_keep(const char *key, const char *value,
return lxc_clear_config_keepcaps(lxc_conf); return lxc_clear_config_keepcaps(lxc_conf);
keepcaps = strdup(value); keepcaps = strdup(value);
if (!keepcaps) { if (!keepcaps)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several capability keep is specified in a single line /* In case several capability keep is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
...@@ -1739,14 +1694,11 @@ static int set_config_cap_keep(const char *key, const char *value, ...@@ -1739,14 +1694,11 @@ static int set_config_cap_keep(const char *key, const char *value,
lxc_clear_config_keepcaps(lxc_conf); lxc_clear_config_keepcaps(lxc_conf);
keeplist = malloc(sizeof(*keeplist)); keeplist = malloc(sizeof(*keeplist));
if (!keeplist) { if (!keeplist)
SYSERROR("failed to allocate keepcap list");
break; break;
}
keeplist->elem = strdup(token); keeplist->elem = strdup(token);
if (!keeplist->elem) { if (!keeplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(keeplist); free(keeplist);
break; break;
} }
...@@ -1770,10 +1722,8 @@ static int set_config_cap_drop(const char *key, const char *value, ...@@ -1770,10 +1722,8 @@ static int set_config_cap_drop(const char *key, const char *value,
return lxc_clear_config_caps(lxc_conf); return lxc_clear_config_caps(lxc_conf);
dropcaps = strdup(value); dropcaps = strdup(value);
if (!dropcaps) { if (!dropcaps)
SYSERROR("failed to dup '%s'", value);
return -1; return -1;
}
/* In case several capability drop is specified in a single line /* In case several capability drop is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
...@@ -1786,14 +1736,11 @@ static int set_config_cap_drop(const char *key, const char *value, ...@@ -1786,14 +1736,11 @@ static int set_config_cap_drop(const char *key, const char *value,
} }
droplist = malloc(sizeof(*droplist)); droplist = malloc(sizeof(*droplist));
if (!droplist) { if (!droplist)
SYSERROR("failed to allocate drop list");
break; break;
}
droplist->elem = strdup(token); droplist->elem = strdup(token);
if (!droplist->elem) { if (!droplist->elem) {
SYSERROR("failed to dup '%s'", token);
free(droplist); free(droplist);
break; break;
} }
...@@ -1841,6 +1788,7 @@ int append_unexp_config_line(const char *line, struct lxc_conf *conf) ...@@ -1841,6 +1788,7 @@ int append_unexp_config_line(const char *line, struct lxc_conf *conf)
strcat(conf->unexpanded_config, "\n"); strcat(conf->unexpanded_config, "\n");
conf->unexpanded_len++; conf->unexpanded_len++;
} }
return 0; return 0;
} }
...@@ -1853,10 +1801,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1853,10 +1801,8 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
int ret = -1; int ret = -1;
dir = opendir(dirp); dir = opendir(dirp);
if (!dir) { if (!dir)
SYSERROR("failed to open '%s'", dirp);
return -1; return -1;
}
while ((direntp = readdir(dir))) { while ((direntp = readdir(dir))) {
const char *fnam; const char *fnam;
...@@ -1873,9 +1819,9 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1873,9 +1819,9 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
len = strlen(fnam); len = strlen(fnam);
if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0) if (len < 6 || strncmp(fnam + len - 5, ".conf", 5) != 0)
continue; continue;
len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam); len = snprintf(path, MAXPATHLEN, "%s/%s", dirp, fnam);
if (len < 0 || len >= MAXPATHLEN) { if (len < 0 || len >= MAXPATHLEN) {
ERROR("lxc.include filename too long under '%s'", dirp);
ret = -1; ret = -1;
goto out; goto out;
} }
...@@ -1887,8 +1833,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf) ...@@ -1887,8 +1833,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
ret = 0; ret = 0;
out: out:
if (closedir(dir)) closedir(dir);
WARN("lxc.include dir: failed to close directory");
return ret; return ret;
} }
...@@ -1896,13 +1841,11 @@ out: ...@@ -1896,13 +1841,11 @@ out:
static int set_config_includefiles(const char *key, const char *value, static int set_config_includefiles(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
clr_config_includefiles(key, lxc_conf, NULL); clr_config_includefiles(key, lxc_conf, NULL);
return 0; return 0;
} }
/* Parse new config value. */
if (is_dir(value)) if (is_dir(value))
return do_includedir(value, lxc_conf); return do_includedir(value, lxc_conf);
...@@ -1944,13 +1887,10 @@ static int set_config_uts_name(const char *key, const char *value, ...@@ -1944,13 +1887,10 @@ static int set_config_uts_name(const char *key, const char *value,
} }
utsname = malloc(sizeof(*utsname)); utsname = malloc(sizeof(*utsname));
if (!utsname) { if (!utsname)
SYSERROR("failed to allocate memory");
return -1; return -1;
}
if (strlen(value) >= sizeof(utsname->nodename)) { if (strlen(value) >= sizeof(utsname->nodename)) {
ERROR("node name '%s' is too long", value);
free(utsname); free(utsname);
return -1; return -1;
} }
...@@ -1977,15 +1917,13 @@ static int parse_line(char *buffer, void *data) ...@@ -1977,15 +1917,13 @@ static int parse_line(char *buffer, void *data)
if (lxc_is_line_empty(buffer)) if (lxc_is_line_empty(buffer))
return 0; return 0;
/* we have to dup the buffer otherwise, at the re-exec for /* We have to dup the buffer otherwise, at the re-exec for reboot we
* reboot we modified the original string on the stack by * modified the original string on the stack by replacing '=' by '\0'
* replacing '=' by '\0' below * below.
*/ */
linep = line = strdup(buffer); linep = line = strdup(buffer);
if (!line) { if (!line)
SYSERROR("failed to allocate memory for '%s'", buffer);
return -1; return -1;
}
if (!plc->from_include) if (!plc->from_include)
if ((ret = append_unexp_config_line(line, plc->conf))) if ((ret = append_unexp_config_line(line, plc->conf)))
...@@ -2019,7 +1957,9 @@ static int parse_line(char *buffer, void *data) ...@@ -2019,7 +1957,9 @@ static int parse_line(char *buffer, void *data)
value[lxc_char_right_gc(value, strlen(value))] = '\0'; value[lxc_char_right_gc(value, strlen(value))] = '\0';
if (*value == '\'' || *value == '\"') { if (*value == '\'' || *value == '\"') {
size_t len = strlen(value); size_t len;
len = strlen(value);
if (len > 1 && value[len - 1] == *value) { if (len > 1 && value[len - 1] == *value) {
value[len - 1] = '\0'; value[len - 1] = '\0';
value++; value++;
...@@ -2028,7 +1968,7 @@ static int parse_line(char *buffer, void *data) ...@@ -2028,7 +1968,7 @@ static int parse_line(char *buffer, void *data)
config = lxc_get_config(key); config = lxc_get_config(key);
if (!config) { if (!config) {
ERROR("unknown key %s", key); ERROR("Unknown configuration key \"%s\"", key);
goto out; goto out;
} }
...@@ -2064,16 +2004,17 @@ static int lxc_config_readline(char *buffer, struct lxc_conf *conf) ...@@ -2064,16 +2004,17 @@ static int lxc_config_readline(char *buffer, struct lxc_conf *conf)
int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include) int lxc_config_read(const char *file, struct lxc_conf *conf, bool from_include)
{ {
int ret;
struct parse_line_conf c; struct parse_line_conf c;
c.conf = conf; c.conf = conf;
c.from_include = from_include; c.from_include = from_include;
if (access(file, R_OK) == -1) { ret = access(file, R_OK);
if (ret < 0)
return -1; return -1;
}
/* Catch only the top level config file name in the structure */ /* Catch only the top level config file name in the structure. */
if (!conf->rcfile) if (!conf->rcfile)
conf->rcfile = strdup(file); conf->rcfile = strdup(file);
...@@ -2177,19 +2118,18 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags) ...@@ -2177,19 +2118,18 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
/* For the sake of backward compatibility, drop all privileges /* For the sake of backward compatibility, drop all privileges
* if none is specified. * if none is specified.
*/ */
for (i = 0; all_privs[i].token; i++) { for (i = 0; all_privs[i].token; i++)
*flags |= all_privs[i].flag; *flags |= all_privs[i].flag;
}
return 0; return 0;
} }
token = strtok_r(flaglist, "|", &saveptr); token = strtok_r(flaglist, "|", &saveptr);
while (token) { while (token) {
aflag = -1; aflag = -1;
for (i = 0; all_privs[i].token; i++) { for (i = 0; all_privs[i].token; i++)
if (!strcmp(all_privs[i].token, token)) if (!strcmp(all_privs[i].token, token))
aflag = all_privs[i].flag; aflag = all_privs[i].flag;
}
if (aflag < 0) if (aflag < 0)
return -1; return -1;
...@@ -2212,7 +2152,7 @@ void write_config(FILE *fout, struct lxc_conf *c) ...@@ -2212,7 +2152,7 @@ void write_config(FILE *fout, struct lxc_conf *c)
ret = fwrite(c->unexpanded_config, 1, len, fout); ret = fwrite(c->unexpanded_config, 1, len, fout);
if (ret != len) if (ret != len)
SYSERROR("Error writing configuration file"); SYSERROR("Failed to write configuration file");
} }
bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key,
...@@ -2289,19 +2229,15 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -2289,19 +2229,15 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
olddir = alloca(olddirlen + 1); olddir = alloca(olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath, ret = snprintf(olddir, olddirlen + 1, "%s=%s/%s", ovldir, oldpath,
oldname); oldname);
if (ret < 0 || ret >= olddirlen + 1) { if (ret < 0 || ret >= olddirlen + 1)
ERROR("failed to create string");
return false; return false;
}
newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2; newdirlen = strlen(ovldir) + strlen(newpath) + strlen(newname) + 2;
newdir = alloca(newdirlen + 1); newdir = alloca(newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath, ret = snprintf(newdir, newdirlen + 1, "%s=%s/%s", ovldir, newpath,
newname); newname);
if (ret < 0 || ret >= newdirlen + 1) { if (ret < 0 || ret >= newdirlen + 1)
ERROR("failed to create string");
return false; return false;
}
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
return true; return true;
...@@ -2361,15 +2297,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath, ...@@ -2361,15 +2297,14 @@ bool clone_update_unexp_ovl_paths(struct lxc_conf *conf, const char *oldpath,
size_t poffset = q - conf->unexpanded_config; size_t poffset = q - conf->unexpanded_config;
new = realloc(conf->unexpanded_config, newlen + 1); new = realloc(conf->unexpanded_config, newlen + 1);
if (!new) { if (!new)
ERROR("Out of memory");
return false; return false;
}
conf->unexpanded_len = newlen; conf->unexpanded_len = newlen;
conf->unexpanded_alloced = newlen + 1; conf->unexpanded_alloced = newlen + 1;
new[newlen - 1] = '\0'; new[newlen - 1] = '\0';
lend = new + (lend - conf->unexpanded_config); lend = new + (lend - conf->unexpanded_config);
/* move over the remainder to make room for the newdir /* Move over the remainder to make room for the newdir.
*/ */
memmove(new + poffset + newdirlen, memmove(new + poffset + newdirlen,
new + poffset + olddirlen, new + poffset + olddirlen,
...@@ -2398,20 +2333,18 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2398,20 +2333,18 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
olddirlen = strlen(oldpath) + strlen(oldname) + 1; olddirlen = strlen(oldpath) + strlen(oldname) + 1;
olddir = alloca(olddirlen + 1); olddir = alloca(olddirlen + 1);
ret = snprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname); ret = snprintf(olddir, olddirlen + 1, "%s/%s", oldpath, oldname);
if (ret < 0 || ret >= olddirlen + 1) { if (ret < 0 || ret >= olddirlen + 1)
ERROR("failed to create string");
return false; return false;
}
newdirlen = strlen(newpath) + strlen(newname) + 1; newdirlen = strlen(newpath) + strlen(newname) + 1;
newdir = alloca(newdirlen + 1); newdir = alloca(newdirlen + 1);
ret = snprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname); ret = snprintf(newdir, newdirlen + 1, "%s/%s", newpath, newname);
if (ret < 0 || ret >= newdirlen + 1) { if (ret < 0 || ret >= newdirlen + 1)
ERROR("failed to create string");
return false; return false;
}
if (!conf->unexpanded_config) if (!conf->unexpanded_config)
return true; return true;
while (*lstart) { while (*lstart) {
lend = strchr(lstart, '\n'); lend = strchr(lstart, '\n');
if (!lend) if (!lend)
...@@ -2454,15 +2387,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2454,15 +2387,14 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
size_t poffset = p - conf->unexpanded_config; size_t poffset = p - conf->unexpanded_config;
new = realloc(conf->unexpanded_config, newlen + 1); new = realloc(conf->unexpanded_config, newlen + 1);
if (!new) { if (!new)
ERROR("failed to allocate memory");
return false; return false;
}
conf->unexpanded_len = newlen; conf->unexpanded_len = newlen;
conf->unexpanded_alloced = newlen + 1; conf->unexpanded_alloced = newlen + 1;
new[newlen - 1] = '\0'; new[newlen - 1] = '\0';
lend = new + (lend - conf->unexpanded_config); lend = new + (lend - conf->unexpanded_config);
/* move over the remainder to make room for the newdir /* Move over the remainder to make room for the newdir.
*/ */
memmove(new + poffset + newdirlen, memmove(new + poffset + newdirlen,
new + poffset + olddirlen, new + poffset + olddirlen,
...@@ -2486,8 +2418,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath, ...@@ -2486,8 +2418,7 @@ bool clone_update_unexp_hooks(struct lxc_conf *conf, const char *oldpath,
} \ } \
} }
/* /* This is called only from clone. We wish to update all hwaddrs in the
* This is called only from clone. We wish to update all hwaddrs in the
* unexpanded config file. We can't/don't want to update any which come from * unexpanded config file. We can't/don't want to update any which come from
* lxc.includes (there shouldn't be any). * lxc.includes (there shouldn't be any).
* We can't just walk the c->lxc-conf->network list because that includes netifs * We can't just walk the c->lxc-conf->network list because that includes netifs
...@@ -2546,9 +2477,9 @@ bool network_new_hwaddrs(struct lxc_conf *conf) ...@@ -2546,9 +2477,9 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
return false; return false;
memcpy(p, newhwaddr, 17); memcpy(p, newhwaddr, 17);
lxc_list_for_each(it, &conf->network) lxc_list_for_each(it, &conf->network) {
{
struct lxc_netdev *n = it->elem; struct lxc_netdev *n = it->elem;
if (n->hwaddr && memcmp(oldhwaddr, n->hwaddr, 17) == 0) if (n->hwaddr && memcmp(oldhwaddr, n->hwaddr, 17) == 0)
memcpy(n->hwaddr, newhwaddr, 17); memcpy(n->hwaddr, newhwaddr, 17);
} }
...@@ -2562,21 +2493,16 @@ bool network_new_hwaddrs(struct lxc_conf *conf) ...@@ -2562,21 +2493,16 @@ bool network_new_hwaddrs(struct lxc_conf *conf)
static int set_config_ephemeral(const char *key, const char *value, static int set_config_ephemeral(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->ephemeral = 0; lxc_conf->ephemeral = 0;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &lxc_conf->ephemeral) < 0) if (lxc_safe_uint(value, &lxc_conf->ephemeral) < 0)
return -1; return -1;
if (lxc_conf->ephemeral > 1) { if (lxc_conf->ephemeral > 1)
ERROR(
"Wrong value for lxc.ephemeral. Can only be set to 0 or 1");
return -1; return -1;
}
return 0; return 0;
} }
...@@ -2586,22 +2512,17 @@ static int set_config_log_syslog(const char *key, const char *value, ...@@ -2586,22 +2512,17 @@ static int set_config_log_syslog(const char *key, const char *value,
{ {
int facility; int facility;
/* Clear any previously set value. */
if (lxc_conf->syslog) { if (lxc_conf->syslog) {
free(lxc_conf->syslog); free(lxc_conf->syslog);
lxc_conf->syslog = NULL; lxc_conf->syslog = NULL;
} }
/* Check if value is empty. */
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return 0; return 0;
/* Parse value. */
facility = lxc_syslog_priority_to_int(value); facility = lxc_syslog_priority_to_int(value);
if (facility == -EINVAL) { if (facility == -EINVAL)
ERROR("Wrong value for lxc.log.syslog.");
return -1; return -1;
}
lxc_log_syslog(facility); lxc_log_syslog(facility);
return set_config_string_item(&lxc_conf->syslog, value); return set_config_string_item(&lxc_conf->syslog, value);
...@@ -2612,21 +2533,16 @@ static int set_config_no_new_privs(const char *key, const char *value, ...@@ -2612,21 +2533,16 @@ static int set_config_no_new_privs(const char *key, const char *value,
{ {
unsigned int v; unsigned int v;
/* Set config value to default. */
if (lxc_config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->no_new_privs = false; lxc_conf->no_new_privs = false;
return 0; return 0;
} }
/* Parse new config value. */
if (lxc_safe_uint(value, &v) < 0) if (lxc_safe_uint(value, &v) < 0)
return -1; return -1;
if (v > 1) { if (v > 1)
ERROR("Wrong value for lxc.no_new_privs. Can only be set to 0 "
"or 1");
return -1; return -1;
}
lxc_conf->no_new_privs = v ? true : false; lxc_conf->no_new_privs = v ? true : false;
...@@ -2700,14 +2616,13 @@ static int get_config_selinux_context(const char *key, char *retv, int inlen, ...@@ -2700,14 +2616,13 @@ static int get_config_selinux_context(const char *key, char *retv, int inlen,
return lxc_get_conf_str(retv, inlen, c->lsm_se_context); return lxc_get_conf_str(retv, inlen, c->lsm_se_context);
} }
/* /* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, then
* If you ask for a specific cgroup value, i.e. lxc.cgroup.devices.list, * just the value(s) will be printed. Since there still could be more than one,
* then just the value(s) will be printed. Since there still could be * it is newline-separated.
* more than one, it is newline-separated. * (Maybe that's ambigous, since some values, i.e. devices.list, will already
* (Maybe that's ambigous, since some values, i.e. devices.list, will * have newlines?)
* already have newlines?) * If you ask for 'lxc.cgroup", then all cgroup entries will be printed, in
* If you ask for 'lxc.cgroup", then all cgroup entries will be printed, * 'lxc.cgroup.subsystem.key = value' format.
* in 'lxc.cgroup.subsystem.key = value' format.
*/ */
static int get_config_cgroup(const char *key, char *retv, int inlen, static int get_config_cgroup(const char *key, char *retv, int inlen,
struct lxc_conf *c, void *data) struct lxc_conf *c, void *data)
...@@ -2731,8 +2646,10 @@ static int get_config_cgroup(const char *key, char *retv, int inlen, ...@@ -2731,8 +2646,10 @@ static int get_config_cgroup(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->cgroup) { lxc_list_for_each(it, &c->cgroup) {
struct lxc_cgroup *cg = it->elem; struct lxc_cgroup *cg = it->elem;
if (get_all) { if (get_all) {
strprint(retv, inlen, "lxc.cgroup.%s = %s\n", cg->subsystem, cg->value); strprint(retv, inlen, "lxc.cgroup.%s = %s\n",
cg->subsystem, cg->value);
} else if (!strcmp(cg->subsystem, key)) { } else if (!strcmp(cg->subsystem, key)) {
strprint(retv, inlen, "%s\n", cg->value); strprint(retv, inlen, "%s\n", cg->value);
} }
...@@ -2905,8 +2822,7 @@ static int get_config_mount(const char *key, char *retv, int inlen, ...@@ -2905,8 +2822,7 @@ static int get_config_mount(const char *key, char *retv, int inlen,
else else
memset(retv, 0, inlen); memset(retv, 0, inlen);
lxc_list_for_each(it, &c->mount_list) lxc_list_for_each(it, &c->mount_list) {
{
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
...@@ -2953,7 +2869,6 @@ static int get_config_hooks(const char *key, char *retv, int inlen, ...@@ -2953,7 +2869,6 @@ static int get_config_hooks(const char *key, char *retv, int inlen,
struct lxc_list *it; struct lxc_list *it;
int i; int i;
/* "lxc.hook.mount" */
subkey = strchr(key, '.'); subkey = strchr(key, '.');
if (subkey) if (subkey)
subkey = strchr(subkey + 1, '.'); subkey = strchr(subkey + 1, '.');
...@@ -3016,6 +2931,7 @@ static int get_config_cap_drop(const char *key, char *retv, int inlen, ...@@ -3016,6 +2931,7 @@ static int get_config_cap_drop(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->caps) { lxc_list_for_each(it, &c->caps) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3033,6 +2949,7 @@ static int get_config_cap_keep(const char *key, char *retv, int inlen, ...@@ -3033,6 +2949,7 @@ static int get_config_cap_keep(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->keepcaps) { lxc_list_for_each(it, &c->keepcaps) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3117,6 +3034,7 @@ static int get_config_group(const char *key, char *retv, int inlen, ...@@ -3117,6 +3034,7 @@ static int get_config_group(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->groups) { lxc_list_for_each(it, &c->groups) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3134,6 +3052,7 @@ static int get_config_environment(const char *key, char *retv, int inlen, ...@@ -3134,6 +3052,7 @@ static int get_config_environment(const char *key, char *retv, int inlen,
lxc_list_for_each(it, &c->environment) { lxc_list_for_each(it, &c->environment) {
strprint(retv, inlen, "%s\n", (char *)it->elem); strprint(retv, inlen, "%s\n", (char *)it->elem);
} }
return fulllen; return fulllen;
} }
...@@ -3167,8 +3086,7 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen, ...@@ -3167,8 +3086,7 @@ static int get_config_no_new_privs(const char *key, char *retv, int inlen,
return lxc_get_conf_int(c, retv, inlen, c->no_new_privs); return lxc_get_conf_int(c, retv, inlen, c->no_new_privs);
} }
/* /* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
* If you ask for a specific value, i.e. lxc.prlimit.nofile, then just the value
* will be printed. If you ask for 'lxc.prlimit', then all limit entries will be * will be printed. If you ask for 'lxc.prlimit', then all limit entries will be
* printed, in 'lxc.prlimit.resource = value' format. * printed, in 'lxc.prlimit.resource = value' format.
*/ */
...@@ -3206,19 +3124,18 @@ static int get_config_prlimit(const char *key, char *retv, int inlen, ...@@ -3206,19 +3124,18 @@ static int get_config_prlimit(const char *key, char *retv, int inlen,
(uint64_t)lim->limit.rlim_cur); (uint64_t)lim->limit.rlim_cur);
} }
if (lim->limit.rlim_cur != lim->limit.rlim_max) { if (lim->limit.rlim_cur != lim->limit.rlim_max) {
if (lim->limit.rlim_max == RLIM_INFINITY) { if (lim->limit.rlim_max == RLIM_INFINITY)
memcpy(buf + partlen, ":unlimited", memcpy(buf + partlen, ":unlimited",
sizeof(":unlimited")); sizeof(":unlimited"));
} else { else
sprintf(buf + partlen, ":%" PRIu64, sprintf(buf + partlen, ":%" PRIu64,
(uint64_t)lim->limit.rlim_max); (uint64_t)lim->limit.rlim_max);
} }
}
if (get_all) { if (get_all) {
strprint(retv, inlen, "lxc.prlimit.%s = %s\n", strprint(retv, inlen, "lxc.prlimit.%s = %s\n",
lim->resource, buf); lim->resource, buf);
} else if (strcmp(lim->resource, key) == 0) { } else if (!strcmp(lim->resource, key)) {
strprint(retv, inlen, "%s", buf); strprint(retv, inlen, "%s", buf);
} }
} }
...@@ -3590,8 +3507,8 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -3590,8 +3507,8 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
* (Checking for INT_MAX here is intentional.) * (Checking for INT_MAX here is intentional.)
*/ */
if (tmpidx == INT_MAX) { if (tmpidx == INT_MAX) {
SYSERROR("number of configured networks would overflow the " SYSERROR("Number of configured networks would overflow the "
"counter... what are you doing?"); "counter");
goto on_error; goto on_error;
} }
*idx = tmpidx; *idx = tmpidx;
...@@ -3610,7 +3527,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key, ...@@ -3610,7 +3527,7 @@ static struct lxc_config_t *get_network_config_ops(const char *key,
config = lxc_get_config(copy); config = lxc_get_config(copy);
if (!config) { if (!config) {
ERROR("unknown network configuration key %s", key); ERROR("Unknown network configuration key \"%s\"", key);
goto on_error; goto on_error;
} }
} }
...@@ -3625,10 +3542,9 @@ on_error: ...@@ -3625,10 +3542,9 @@ on_error:
return NULL; return NULL;
} }
/* /* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' was
* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.' * found. So we make sure next comes an integer, find the right callback (by
* was found. So we make sure next comes an integer, find the right callback * rewriting the key), and call it.
* (by rewriting the key), and call it.
*/ */
static int set_config_net_nic(const char *key, const char *value, static int set_config_net_nic(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
...@@ -3662,11 +3578,6 @@ static int set_config_net_nic(const char *key, const char *value, ...@@ -3662,11 +3578,6 @@ static int set_config_net_nic(const char *key, const char *value,
return ret; return ret;
} }
/*
* Config entry is something like "lxc.net.0.ipv4" the key 'lxc.net.'
* was found. So we make sure next comes an integer, find the right callback
* (by rewriting the key), and call it.
*/
static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf, static int clr_config_net_nic(const char *key, struct lxc_conf *lxc_conf,
void *data) void *data)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment