Unverified Commit 2238c216 by Christian Brauner Committed by Stéphane Graber

network: mv config_value_empty() to confile_utils

and rename it to lxc_config_value_empty() Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent 0d75d4a4
...@@ -443,19 +443,11 @@ int lxc_listconfigs(char *retv, int inlen) ...@@ -443,19 +443,11 @@ int lxc_listconfigs(char *retv, int inlen)
return fulllen; return fulllen;
} }
static inline bool config_value_empty(const char *value)
{
if (value && strlen(value) > 0)
return false;
return true;
}
static int set_config_string_item(char **conf_item, const char *value) static int set_config_string_item(char **conf_item, const char *value)
{ {
char *new_value; char *new_value;
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
free(*conf_item); free(*conf_item);
*conf_item = NULL; *conf_item = NULL;
return 0; return 0;
...@@ -533,7 +525,7 @@ out: ...@@ -533,7 +525,7 @@ out:
static int set_config_network(const char *key, const char *value, static int set_config_network(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
if (!config_value_empty(value)) { if (!lxc_config_value_empty(value)) {
ERROR("lxc.network must not have a value"); ERROR("lxc.network must not have a value");
return -1; return -1;
} }
...@@ -550,7 +542,7 @@ static int set_config_network_type(const char *key, const char *value, ...@@ -550,7 +542,7 @@ static int set_config_network_type(const char *key, const char *value,
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_list *list; struct lxc_list *list;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_config_network(lxc_conf); return lxc_clear_config_network(lxc_conf);
netdev = malloc(sizeof(*netdev)); netdev = malloc(sizeof(*netdev));
...@@ -893,7 +885,7 @@ static int set_config_network_hwaddr(const char *key, const char *value, ...@@ -893,7 +885,7 @@ static int set_config_network_hwaddr(const char *key, const char *value,
return -1; return -1;
}; };
if (config_value_empty(new_value)) { if (lxc_config_value_empty(new_value)) {
free(new_value); free(new_value);
netdev->hwaddr = NULL; netdev->hwaddr = NULL;
return 0; return 0;
...@@ -944,7 +936,7 @@ static int set_config_network_ipv4(const char *key, const char *value, ...@@ -944,7 +936,7 @@ static int set_config_network_ipv4(const char *key, const char *value,
char *cursor, *slash; char *cursor, *slash;
char *addr = NULL, *bcast = NULL, *prefix = NULL; char *addr = NULL, *bcast = NULL, *prefix = NULL;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_network_item(key, lxc_conf); return clr_config_network_item(key, lxc_conf);
netdev = network_netdev(key, value, &lxc_conf->network); netdev = network_netdev(key, value, &lxc_conf->network);
...@@ -1038,7 +1030,7 @@ static int set_config_network_ipv4_gateway(const char *key, const char *value, ...@@ -1038,7 +1030,7 @@ static int set_config_network_ipv4_gateway(const char *key, const char *value,
free(netdev->ipv4_gateway); free(netdev->ipv4_gateway);
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
netdev->ipv4_gateway = NULL; netdev->ipv4_gateway = NULL;
} else if (!strcmp(value, "auto")) { } else if (!strcmp(value, "auto")) {
netdev->ipv4_gateway = NULL; netdev->ipv4_gateway = NULL;
...@@ -1073,7 +1065,7 @@ static int set_config_network_ipv6(const char *key, const char *value, ...@@ -1073,7 +1065,7 @@ static int set_config_network_ipv6(const char *key, const char *value,
struct lxc_list *list; struct lxc_list *list;
char *slash, *valdup, *netmask; char *slash, *valdup, *netmask;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return clr_config_network_item(key, lxc_conf); return clr_config_network_item(key, lxc_conf);
netdev = network_netdev(key, value, &lxc_conf->network); netdev = network_netdev(key, value, &lxc_conf->network);
...@@ -1139,7 +1131,7 @@ static int set_config_network_ipv6_gateway(const char *key, const char *value, ...@@ -1139,7 +1131,7 @@ static int set_config_network_ipv6_gateway(const char *key, const char *value,
free(netdev->ipv6_gateway); free(netdev->ipv6_gateway);
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
netdev->ipv6_gateway = NULL; netdev->ipv6_gateway = NULL;
} else if (!strcmp(value, "auto")) { } else if (!strcmp(value, "auto")) {
netdev->ipv6_gateway = NULL; netdev->ipv6_gateway = NULL;
...@@ -1223,7 +1215,7 @@ static int set_config_init_uid(const char *key, const char *value, ...@@ -1223,7 +1215,7 @@ 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. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_uid = 0; lxc_conf->init_uid = 0;
return 0; return 0;
} }
...@@ -1242,7 +1234,7 @@ static int set_config_init_gid(const char *key, const char *value, ...@@ -1242,7 +1234,7 @@ 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. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->init_gid = 0; lxc_conf->init_gid = 0;
return 0; return 0;
} }
...@@ -1260,7 +1252,7 @@ static int set_config_hooks(const char *key, const char *value, ...@@ -1260,7 +1252,7 @@ static int set_config_hooks(const char *key, const char *value,
{ {
char *copy; char *copy;
if (config_value_empty(value)) if (lxc_config_value_empty(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) {
...@@ -1314,7 +1306,7 @@ static int set_config_pts(const char *key, const char *value, ...@@ -1314,7 +1306,7 @@ static int set_config_pts(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->pts = 0; lxc_conf->pts = 0;
return 0; return 0;
} }
...@@ -1336,7 +1328,7 @@ static int set_config_start(const char *key, const char *value, ...@@ -1336,7 +1328,7 @@ static int set_config_start(const char *key, const char *value,
{ {
bool is_empty; bool is_empty;
is_empty = 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. */ /* Set config value to default. */
...@@ -1381,7 +1373,7 @@ static int set_config_monitor(const char *key, const char *value, ...@@ -1381,7 +1373,7 @@ static int set_config_monitor(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->monitor_unshare = 0; lxc_conf->monitor_unshare = 0;
return 0; return 0;
} }
...@@ -1401,7 +1393,7 @@ static int set_config_group(const char *key, const char *value, ...@@ -1401,7 +1393,7 @@ static int set_config_group(const char *key, const char *value,
struct lxc_list *grouplist; struct lxc_list *grouplist;
int ret = -1; int ret = -1;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_groups(lxc_conf); return lxc_clear_groups(lxc_conf);
groups = strdup(value); groups = strdup(value);
...@@ -1445,7 +1437,7 @@ static int set_config_environment(const char *key, const char *value, ...@@ -1445,7 +1437,7 @@ static int set_config_environment(const char *key, const char *value,
{ {
struct lxc_list *list_item = NULL; struct lxc_list *list_item = NULL;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_environment(lxc_conf); return lxc_clear_environment(lxc_conf);
list_item = malloc(sizeof(*list_item)); list_item = malloc(sizeof(*list_item));
...@@ -1470,7 +1462,7 @@ static int set_config_tty(const char *key, const char *value, ...@@ -1470,7 +1462,7 @@ static int set_config_tty(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->tty = 0; lxc_conf->tty = 0;
return 0; return 0;
} }
...@@ -1490,7 +1482,7 @@ static int set_config_kmsg(const char *key, const char *value, ...@@ -1490,7 +1482,7 @@ static int set_config_kmsg(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->kmsg = 0; lxc_conf->kmsg = 0;
return 0; return 0;
} }
...@@ -1515,7 +1507,7 @@ static int set_config_lsm_aa_incomplete(const char *key, const char *value, ...@@ -1515,7 +1507,7 @@ static int set_config_lsm_aa_incomplete(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (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;
} }
...@@ -1544,7 +1536,7 @@ static int set_config_logfile(const char *key, const char *value, ...@@ -1544,7 +1536,7 @@ static int set_config_logfile(const char *key, const char *value,
{ {
int ret; int ret;
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
free(c->logfile); free(c->logfile);
c->logfile = NULL; c->logfile = NULL;
return 0; return 0;
...@@ -1565,7 +1557,7 @@ static int set_config_loglevel(const char *key, const char *value, ...@@ -1565,7 +1557,7 @@ static int set_config_loglevel(const char *key, const char *value,
int newlevel; int newlevel;
/* Set config value to default. */ /* Set config value to default. */
if (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;
} }
...@@ -1589,7 +1581,7 @@ static int set_config_autodev(const char *key, const char *value, ...@@ -1589,7 +1581,7 @@ static int set_config_autodev(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->autodev = 0; lxc_conf->autodev = 0;
return 0; return 0;
} }
...@@ -1661,7 +1653,7 @@ static int set_config_haltsignal(const char *key, const char *value, ...@@ -1661,7 +1653,7 @@ static int set_config_haltsignal(const char *key, const char *value,
int sig_n; int sig_n;
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->haltsignal = 0; lxc_conf->haltsignal = 0;
return 0; return 0;
} }
...@@ -1682,7 +1674,7 @@ static int set_config_rebootsignal(const char *key, const char *value, ...@@ -1682,7 +1674,7 @@ static int set_config_rebootsignal(const char *key, const char *value,
int sig_n; int sig_n;
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->rebootsignal = 0; lxc_conf->rebootsignal = 0;
return 0; return 0;
} }
...@@ -1702,7 +1694,7 @@ static int set_config_stopsignal(const char *key, const char *value, ...@@ -1702,7 +1694,7 @@ static int set_config_stopsignal(const char *key, const char *value,
int sig_n; int sig_n;
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->stopsignal = 0; lxc_conf->stopsignal = 0;
return 0; return 0;
} }
...@@ -1724,7 +1716,7 @@ static int set_config_cgroup(const char *key, const char *value, ...@@ -1724,7 +1716,7 @@ static int set_config_cgroup(const char *key, const char *value,
struct lxc_list *cglist = NULL; struct lxc_list *cglist = NULL;
struct lxc_cgroup *cgelem = NULL; struct lxc_cgroup *cgelem = NULL;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_cgroups(lxc_conf, key); return lxc_clear_cgroups(lxc_conf, key);
subkey = strstr(key, token); subkey = strstr(key, token);
...@@ -1783,7 +1775,7 @@ static int set_config_idmaps(const char *key, const char *value, ...@@ -1783,7 +1775,7 @@ static int set_config_idmaps(const char *key, const char *value,
struct lxc_list *idmaplist = NULL; struct lxc_list *idmaplist = NULL;
struct id_map *idmap = NULL; struct id_map *idmap = NULL;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_idmaps(lxc_conf); return lxc_clear_idmaps(lxc_conf);
idmaplist = malloc(sizeof(*idmaplist)); idmaplist = malloc(sizeof(*idmaplist));
...@@ -1826,7 +1818,7 @@ on_error: ...@@ -1826,7 +1818,7 @@ on_error:
static int set_config_fstab(const char *key, const char *value, static int set_config_fstab(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
clr_config_fstab(key, lxc_conf); clr_config_fstab(key, lxc_conf);
return -1; return -1;
} }
...@@ -1867,7 +1859,7 @@ static int set_config_mount_auto(const char *key, const char *value, ...@@ -1867,7 +1859,7 @@ static int set_config_mount_auto(const char *key, const char *value,
{ NULL, 0, 0 } { NULL, 0, 0 }
}; };
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->auto_mounts = 0; lxc_conf->auto_mounts = 0;
return 0; return 0;
} }
...@@ -1909,7 +1901,7 @@ static int set_config_mount(const char *key, const char *value, ...@@ -1909,7 +1901,7 @@ static int set_config_mount(const char *key, const char *value,
char *mntelem; char *mntelem;
struct lxc_list *mntlist; struct lxc_list *mntlist;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_mount_entries(lxc_conf); return lxc_clear_mount_entries(lxc_conf);
mntlist = malloc(sizeof(*mntlist)); mntlist = malloc(sizeof(*mntlist));
...@@ -1935,7 +1927,7 @@ static int set_config_cap_keep(const char *key, const char *value, ...@@ -1935,7 +1927,7 @@ static int set_config_cap_keep(const char *key, const char *value,
struct lxc_list *keeplist; struct lxc_list *keeplist;
int ret = -1; int ret = -1;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_config_keepcaps(lxc_conf); return lxc_clear_config_keepcaps(lxc_conf);
keepcaps = strdup(value); keepcaps = strdup(value);
...@@ -1985,7 +1977,7 @@ static int set_config_cap_drop(const char *key, const char *value, ...@@ -1985,7 +1977,7 @@ static int set_config_cap_drop(const char *key, const char *value,
struct lxc_list *droplist; struct lxc_list *droplist;
int ret = -1; int ret = -1;
if (config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_config_caps(lxc_conf); return lxc_clear_config_caps(lxc_conf);
dropcaps = strdup(value); dropcaps = strdup(value);
...@@ -2150,7 +2142,7 @@ static int set_config_includefiles(const char *key, const char *value, ...@@ -2150,7 +2142,7 @@ static int set_config_includefiles(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
clr_config_includefiles(key, lxc_conf); clr_config_includefiles(key, lxc_conf);
return 0; return 0;
} }
...@@ -2183,7 +2175,7 @@ static int set_config_rootfs_options(const char *key, const char *value, ...@@ -2183,7 +2175,7 @@ static int set_config_rootfs_options(const char *key, const char *value,
static int set_config_rootfs_backend(const char *key, const char *value, static int set_config_rootfs_backend(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
free(lxc_conf->rootfs.bdev_type); free(lxc_conf->rootfs.bdev_type);
lxc_conf->rootfs.bdev_type = NULL; lxc_conf->rootfs.bdev_type = NULL;
return 0; return 0;
...@@ -2209,7 +2201,7 @@ static int set_config_utsname(const char *key, const char *value, ...@@ -2209,7 +2201,7 @@ static int set_config_utsname(const char *key, const char *value,
{ {
struct utsname *utsname; struct utsname *utsname;
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
clr_config_utsname(key, lxc_conf); clr_config_utsname(key, lxc_conf);
return 0; return 0;
} }
...@@ -2494,7 +2486,7 @@ bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key, ...@@ -2494,7 +2486,7 @@ bool do_append_unexp_config_line(struct lxc_conf *conf, const char *key,
len = strlen(key) + strlen(v) + 4; len = strlen(key) + strlen(v) + 4;
tmp = alloca(len); tmp = alloca(len);
if (config_value_empty(v)) if (lxc_config_value_empty(v))
ret = snprintf(tmp, len, "%s =", key); ret = snprintf(tmp, len, "%s =", key);
else else
ret = snprintf(tmp, len, "%s = %s", key, v); ret = snprintf(tmp, len, "%s = %s", key, v);
...@@ -2849,7 +2841,7 @@ static int set_config_ephemeral(const char *key, const char *value, ...@@ -2849,7 +2841,7 @@ static int set_config_ephemeral(const char *key, const char *value,
struct lxc_conf *lxc_conf) struct lxc_conf *lxc_conf)
{ {
/* Set config value to default. */ /* Set config value to default. */
if (config_value_empty(value)) { if (lxc_config_value_empty(value)) {
lxc_conf->ephemeral = 0; lxc_conf->ephemeral = 0;
return 0; return 0;
} }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include "conf.h"
#include "log.h"
#include "utils.h" #include "utils.h"
int parse_idmaps(const char *idmap, char *type, unsigned long *nsid, int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
...@@ -146,3 +148,11 @@ on_error: ...@@ -146,3 +148,11 @@ on_error:
return ret; return ret;
} }
bool lxc_config_value_empty(const char *value)
{
if (value && strlen(value) > 0)
return false;
return true;
}
...@@ -20,7 +20,11 @@ ...@@ -20,7 +20,11 @@
#ifndef __LXC_CONFILE_UTILS_H #ifndef __LXC_CONFILE_UTILS_H
#define __LXC_CONFILE_UTILS_H #define __LXC_CONFILE_UTILS_H
#include <stdbool.h>
extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid, extern int parse_idmaps(const char *idmap, char *type, unsigned long *nsid,
unsigned long *hostid, unsigned long *range); unsigned long *hostid, unsigned long *range);
extern bool lxc_config_value_empty(const char *value);
#endif /* __LXC_CONFILE_UTILS_H */ #endif /* __LXC_CONFILE_UTILS_H */
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