[lxc-devel] [PATCH] Make config api items const
Dwight Engen
dwight.engen at oracle.com
Mon Nov 26 20:28:14 UTC 2012
This makes it easier to write a binding, and presents a cleaner API. Use
strdupa in a few places to get mutable strings for tokenizing / parsing.
Also change the argv type in lxcapi_start and lxcapi_create to match
that of execv(3).
Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
src/lxc/conf.c | 10 ++--
src/lxc/conf.h | 6 +-
src/lxc/confile.c | 168 ++++++++++++++++++++++++++----------------------
src/lxc/confile.h | 8 +-
src/lxc/lxc.h | 2 +-
src/lxc/lxccontainer.c | 24 ++++----
src/lxc/lxccontainer.h | 20 +++---
src/lxc/lxclock.c | 4 +-
src/lxc/lxclock.h | 2 +-
src/lxc/state.c | 16 ++++-
src/lxc/state.h | 2 +-
11 files changed, 143 insertions(+), 119 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 0753221..eb0c07e 100644
--- a/src/lxc/conf.c
+++ b/src/lxc/conf.c
@@ -2478,7 +2478,7 @@ static void lxc_remove_nic(struct lxc_list *it)
}
/* we get passed in something like '0', '0.ipv4' or '1.ipv6' */
-int lxc_clear_nic(struct lxc_conf *c, char *key)
+int lxc_clear_nic(struct lxc_conf *c, const char *key)
{
char *p1;
int ret, idx, i;
@@ -2586,11 +2586,11 @@ int lxc_clear_config_caps(struct lxc_conf *c)
return 0;
}
-int lxc_clear_cgroups(struct lxc_conf *c, char *key)
+int lxc_clear_cgroups(struct lxc_conf *c, const char *key)
{
struct lxc_list *it,*next;
bool all = false;
- char *k = key + 11;
+ const char *k = key + 11;
if (strcmp(key, "lxc.cgroup") == 0)
all = true;
@@ -2620,11 +2620,11 @@ int lxc_clear_mount_entries(struct lxc_conf *c)
return 0;
}
-int lxc_clear_hooks(struct lxc_conf *c, char *key)
+int lxc_clear_hooks(struct lxc_conf *c, const char *key)
{
struct lxc_list *it,*next;
bool all = false, done = false;
- char *k = key + 9;
+ const char *k = key + 9;
int i;
if (strcmp(key, "lxc.hook") == 0)
diff --git a/src/lxc/conf.h b/src/lxc/conf.h
index 76bf19d..535823d 100644
--- a/src/lxc/conf.h
+++ b/src/lxc/conf.h
@@ -259,11 +259,11 @@ extern int lxc_create_tty(const char *name, struct lxc_conf *conf);
extern void lxc_delete_tty(struct lxc_tty_info *tty_info);
extern int lxc_clear_config_network(struct lxc_conf *c);
-extern int lxc_clear_nic(struct lxc_conf *c, char *key);
+extern int lxc_clear_nic(struct lxc_conf *c, const char *key);
extern int lxc_clear_config_caps(struct lxc_conf *c);
-extern int lxc_clear_cgroups(struct lxc_conf *c, char *key);
+extern int lxc_clear_cgroups(struct lxc_conf *c, const char *key);
extern int lxc_clear_mount_entries(struct lxc_conf *c);
-extern int lxc_clear_hooks(struct lxc_conf *c, char *key);
+extern int lxc_clear_hooks(struct lxc_conf *c, const char *key);
/*
* Configure the container from inside
diff --git a/src/lxc/confile.c b/src/lxc/confile.c
index c1cb693..bc55f8c 100644
--- a/src/lxc/confile.c
+++ b/src/lxc/confile.c
@@ -20,6 +20,7 @@
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#define _GNU_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,40 +47,40 @@
lxc_log_define(lxc_confile, lxc);
-static int config_personality(const char *, char *, struct lxc_conf *);
-static int config_pts(const char *, char *, struct lxc_conf *);
-static int config_tty(const char *, char *, struct lxc_conf *);
-static int config_ttydir(const char *, char *, struct lxc_conf *);
+static int config_personality(const char *, const char *, struct lxc_conf *);
+static int config_pts(const char *, const char *, struct lxc_conf *);
+static int config_tty(const char *, const char *, struct lxc_conf *);
+static int config_ttydir(const char *, const char *, struct lxc_conf *);
#if HAVE_APPARMOR
-static int config_aa_profile(const char *, char *, struct lxc_conf *);
+static int config_aa_profile(const char *, const char *, struct lxc_conf *);
#endif
-static int config_cgroup(const char *, char *, struct lxc_conf *);
-static int config_mount(const char *, char *, struct lxc_conf *);
-static int config_rootfs(const char *, char *, struct lxc_conf *);
-static int config_rootfs_mount(const char *, char *, struct lxc_conf *);
-static int config_pivotdir(const char *, char *, struct lxc_conf *);
-static int config_utsname(const char *, char *, struct lxc_conf *);
-static int config_hook(const char *key, char *value, struct lxc_conf *lxc_conf);
-static int config_network_type(const char *, char *, struct lxc_conf *);
-static int config_network_flags(const char *, char *, struct lxc_conf *);
-static int config_network_link(const char *, char *, struct lxc_conf *);
-static int config_network_name(const char *, char *, struct lxc_conf *);
-static int config_network_veth_pair(const char *, char *, struct lxc_conf *);
-static int config_network_macvlan_mode(const char *, char *, struct lxc_conf *);
-static int config_network_hwaddr(const char *, char *, struct lxc_conf *);
-static int config_network_vlan_id(const char *, char *, struct lxc_conf *);
-static int config_network_mtu(const char *, char *, struct lxc_conf *);
-static int config_network_ipv4(const char *, char *, struct lxc_conf *);
-static int config_network_ipv4_gateway(const char *, char *, struct lxc_conf *);
-static int config_network_script(const char *, char *, struct lxc_conf *);
-static int config_network_ipv6(const char *, char *, struct lxc_conf *);
-static int config_network_ipv6_gateway(const char *, char *, struct lxc_conf *);
-static int config_cap_drop(const char *, char *, struct lxc_conf *);
-static int config_console(const char *, char *, struct lxc_conf *);
-static int config_seccomp(const char *, char *, struct lxc_conf *);
-static int config_includefile(const char *, char *, struct lxc_conf *);
-static int config_network_nic(const char *, char *, struct lxc_conf *);
-static int config_autodev(const char *, char *, struct lxc_conf *);
+static int config_cgroup(const char *, const char *, struct lxc_conf *);
+static int config_mount(const char *, const char *, struct lxc_conf *);
+static int config_rootfs(const char *, const char *, struct lxc_conf *);
+static int config_rootfs_mount(const char *, const char *, struct lxc_conf *);
+static int config_pivotdir(const char *, const char *, struct lxc_conf *);
+static int config_utsname(const char *, const char *, struct lxc_conf *);
+static int config_hook(const char *, const char *, struct lxc_conf *lxc_conf);
+static int config_network_type(const char *, const char *, struct lxc_conf *);
+static int config_network_flags(const char *, const char *, struct lxc_conf *);
+static int config_network_link(const char *, const char *, struct lxc_conf *);
+static int config_network_name(const char *, const char *, struct lxc_conf *);
+static int config_network_veth_pair(const char *, const char *, struct lxc_conf *);
+static int config_network_macvlan_mode(const char *, const char *, struct lxc_conf *);
+static int config_network_hwaddr(const char *, const char *, struct lxc_conf *);
+static int config_network_vlan_id(const char *, const char *, struct lxc_conf *);
+static int config_network_mtu(const char *, const char *, struct lxc_conf *);
+static int config_network_ipv4(const char *, const char *, struct lxc_conf *);
+static int config_network_ipv4_gateway(const char *, const char *, struct lxc_conf *);
+static int config_network_script(const char *, const char *, struct lxc_conf *);
+static int config_network_ipv6(const char *, const char *, struct lxc_conf *);
+static int config_network_ipv6_gateway(const char *, const char *, struct lxc_conf *);
+static int config_cap_drop(const char *, const char *, struct lxc_conf *);
+static int config_console(const char *, const char *, struct lxc_conf *);
+static int config_seccomp(const char *, const char *, struct lxc_conf *);
+static int config_includefile(const char *, const char *, struct lxc_conf *);
+static int config_network_nic(const char *, const char *, struct lxc_conf *);
+static int config_autodev(const char *, const char *, struct lxc_conf *);
static struct lxc_config_t config[] = {
@@ -97,7 +98,7 @@ static struct lxc_config_t config[] = {
{ "lxc.pivotdir", config_pivotdir },
{ "lxc.utsname", config_utsname },
{ "lxc.hook.pre-start", config_hook },
- { "lxc.hook.pre-mount", config_hook },
+ { "lxc.hook.pre-mount", config_hook },
{ "lxc.hook.mount", config_hook },
{ "lxc.hook.start", config_hook },
{ "lxc.hook.post-stop", config_hook },
@@ -173,7 +174,7 @@ int lxc_listconfigs(char *retv, int inlen)
* comes an integer, find the right callback (by rewriting
* the key), and call it.
*/
-static int config_network_nic(const char *key, char *value,
+static int config_network_nic(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *copy = strdup(key), *p;
@@ -208,7 +209,7 @@ out:
return ret;
}
-static int config_network_type(const char *key, char *value,
+static int config_network_type(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_list *network = &lxc_conf->network;
@@ -302,7 +303,8 @@ static struct lxc_netdev *get_netdev_from_key(const char *key,
return netdev;
}
-extern int lxc_list_nicconfigs(struct lxc_conf *c, char *key, char *retv, int inlen)
+extern int lxc_list_nicconfigs(struct lxc_conf *c, const char *key,
+ char *retv, int inlen)
{
struct lxc_netdev *netdev;
int fulllen = 0, len;
@@ -369,7 +371,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value,
return netdev;
}
-static int network_ifname(char **valuep, char *value)
+static int network_ifname(char **valuep, const char *value)
{
if (strlen(value) >= IFNAMSIZ) {
ERROR("interface name '%s' too long (>%d)\n",
@@ -398,7 +400,7 @@ static int network_ifname(char **valuep, char *value)
# define MACVLAN_MODE_BRIDGE 4
#endif
-static int macvlan_mode(int *valuep, char *value)
+static int macvlan_mode(int *valuep, const char *value)
{
struct mc_mode {
char *name;
@@ -422,7 +424,7 @@ static int macvlan_mode(int *valuep, char *value)
return -1;
}
-static int config_network_flags(const char *key, char *value,
+static int config_network_flags(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -436,7 +438,7 @@ static int config_network_flags(const char *key, char *value,
return 0;
}
-static int config_network_link(const char *key, char *value,
+static int config_network_link(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -448,7 +450,7 @@ static int config_network_link(const char *key, char *value,
return network_ifname(&netdev->link, value);
}
-static int config_network_name(const char *key, char *value,
+static int config_network_name(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -460,7 +462,7 @@ static int config_network_name(const char *key, char *value,
return network_ifname(&netdev->name, value);
}
-static int config_network_veth_pair(const char *key, char *value,
+static int config_network_veth_pair(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -472,7 +474,7 @@ static int config_network_veth_pair(const char *key, char *value,
return network_ifname(&netdev->priv.veth_attr.pair, value);
}
-static int config_network_macvlan_mode(const char *key, char *value,
+static int config_network_macvlan_mode(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -484,7 +486,7 @@ static int config_network_macvlan_mode(const char *key, char *value,
return macvlan_mode(&netdev->priv.macvlan_attr.mode, value);
}
-static int config_network_hwaddr(const char *key, char *value,
+static int config_network_hwaddr(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -506,7 +508,7 @@ static int config_network_hwaddr(const char *key, char *value,
return 0;
}
-static int config_network_vlan_id(const char *key, char *value,
+static int config_network_vlan_id(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -521,7 +523,7 @@ static int config_network_vlan_id(const char *key, char *value,
return 0;
}
-static int config_network_mtu(const char *key, char *value,
+static int config_network_mtu(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -543,7 +545,7 @@ static int config_network_mtu(const char *key, char *value,
return 0;
}
-static int config_network_ipv4(const char *key, char *value,
+static int config_network_ipv4(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -571,7 +573,7 @@ static int config_network_ipv4(const char *key, char *value,
lxc_list_init(list);
list->elem = inetdev;
- addr = value;
+ addr = strdupa(value);
cursor = strstr(addr, " ");
if (cursor) {
@@ -618,7 +620,7 @@ static int config_network_ipv4(const char *key, char *value,
return 0;
}
-static int config_network_ipv4_gateway(const char *key, char *value,
+static int config_network_ipv4_gateway(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -655,13 +657,13 @@ static int config_network_ipv4_gateway(const char *key, char *value,
return 0;
}
-static int config_network_ipv6(const char *key, char *value,
+static int config_network_ipv6(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev;
struct lxc_list *list;
- char *slash;
+ char *slash,*valdup;
char *netmask;
netdev = network_netdev(key, value, &lxc_conf->network);
@@ -684,8 +686,9 @@ static int config_network_ipv6(const char *key, char *value,
lxc_list_init(list);
list->elem = inet6dev;
+ valdup = strdupa(value);
inet6dev->prefix = 64;
- slash = strstr(value, "/");
+ slash = strstr(valdup, "/");
if (slash) {
*slash = '\0';
netmask = slash + 1;
@@ -702,7 +705,7 @@ static int config_network_ipv6(const char *key, char *value,
return 0;
}
-static int config_network_ipv6_gateway(const char *key, char *value,
+static int config_network_ipv6_gateway(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -739,7 +742,7 @@ static int config_network_ipv6_gateway(const char *key, char *value,
return 0;
}
-static int config_network_script(const char *key, char *value,
+static int config_network_script(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
struct lxc_netdev *netdev;
@@ -780,7 +783,7 @@ static int add_hook(struct lxc_conf *lxc_conf, int which, char *hook)
return 0;
}
-static int config_seccomp(const char *key, char *value,
+static int config_seccomp(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *path;
@@ -802,7 +805,7 @@ static int config_seccomp(const char *key, char *value,
return 0;
}
-static int config_hook(const char *key, char *value,
+static int config_hook(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *copy = strdup(value);
@@ -825,7 +828,7 @@ static int config_hook(const char *key, char *value,
return -1;
}
-static int config_personality(const char *key, char *value,
+static int config_personality(const char *key, const const char *value,
struct lxc_conf *lxc_conf)
{
signed long personality = lxc_config_parse_arch(value);
@@ -838,7 +841,8 @@ static int config_personality(const char *key, char *value,
return 0;
}
-static int config_pts(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_pts(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
int maxpts = atoi(value);
@@ -847,7 +851,8 @@ static int config_pts(const char *key, char *value, struct lxc_conf *lxc_conf)
return 0;
}
-static int config_tty(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_tty(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
int nbtty = atoi(value);
@@ -856,7 +861,7 @@ static int config_tty(const char *key, char *value, struct lxc_conf *lxc_conf)
return 0;
}
-static int config_ttydir(const char *key, char *value,
+static int config_ttydir(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *path;
@@ -877,7 +882,8 @@ static int config_ttydir(const char *key, char *value,
}
#if HAVE_APPARMOR
-static int config_aa_profile(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_aa_profile(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
char *path;
@@ -897,7 +903,7 @@ static int config_aa_profile(const char *key, char *value, struct lxc_conf *lxc_
}
#endif
-static int config_autodev(const char *key, char *value,
+static int config_autodev(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
int v = atoi(value);
@@ -907,7 +913,8 @@ static int config_autodev(const char *key, char *value,
return 0;
}
-static int config_cgroup(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_cgroup(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
char *token = "lxc.cgroup.";
char *subkey;
@@ -992,7 +999,8 @@ static int config_fstab(const char *key, const char *value,
return config_path_item(key, value, lxc_conf, &lxc_conf->fstab);
}
-static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_mount(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
char *fstab_token = "lxc.mount";
char *token = "lxc.mount.entry";
@@ -1028,7 +1036,7 @@ static int config_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
return 0;
}
-static int config_cap_drop(const char *key, char *value,
+static int config_cap_drop(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *dropcaps, *dropptr, *sptr, *token;
@@ -1074,7 +1082,7 @@ static int config_cap_drop(const char *key, char *value,
return ret;
}
-static int config_console(const char *key, char *value,
+static int config_console(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *path;
@@ -1092,28 +1100,32 @@ static int config_console(const char *key, char *value,
return 0;
}
-static int config_includefile(const char *key, char *value,
+static int config_includefile(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
return lxc_config_read(value, lxc_conf);
}
-static int config_rootfs(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_rootfs(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
return config_path_item(key, value, lxc_conf, &lxc_conf->rootfs.path);
}
-static int config_rootfs_mount(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_rootfs_mount(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
return config_path_item(key, value, lxc_conf, &lxc_conf->rootfs.mount);
}
-static int config_pivotdir(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_pivotdir(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
return config_path_item(key, value, lxc_conf, &lxc_conf->rootfs.pivot);
}
-static int config_utsname(const char *key, char *value, struct lxc_conf *lxc_conf)
+static int config_utsname(const char *key, const char *value,
+ struct lxc_conf *lxc_conf)
{
struct utsname *utsname;
@@ -1298,7 +1310,8 @@ static int lxc_get_arch_entry(struct lxc_conf *c, char *retv, int inlen)
* If you ask for 'lxc.cgroup", then all cgroup entries will be printed,
* in 'lxc.cgroup.subsystem.key = value' format.
*/
-static int lxc_get_cgroup_entry(struct lxc_conf *c, char *retv, int inlen, char *key)
+static int lxc_get_cgroup_entry(struct lxc_conf *c, char *retv, int inlen,
+ const char *key)
{
int fulllen = 0, len;
int all = 0;
@@ -1323,7 +1336,8 @@ static int lxc_get_cgroup_entry(struct lxc_conf *c, char *retv, int inlen, char
return fulllen;
}
-static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen, char *key)
+static int lxc_get_item_hooks(struct lxc_conf *c, char *retv, int inlen,
+ const char *key)
{
char *subkey;
int len, fulllen = 0, found = -1;
@@ -1398,7 +1412,8 @@ static int lxc_get_mount_entries(struct lxc_conf *c, char *retv, int inlen)
* things like veth.pair return '' if invalid (i.e. if called for vlan
* type).
*/
-static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen, char *key)
+static int lxc_get_item_nic(struct lxc_conf *c, char *retv, int inlen,
+ const char *key)
{
char *p1;
int len, fulllen = 0;
@@ -1508,7 +1523,8 @@ static int lxc_get_item_network(struct lxc_conf *c, char *retv, int inlen)
return fulllen;
}
-int lxc_get_config_item(struct lxc_conf *c, char *key, char *retv, int inlen)
+int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv,
+ int inlen)
{
char *v = NULL;
@@ -1559,7 +1575,7 @@ int lxc_get_config_item(struct lxc_conf *c, char *key, char *retv, int inlen)
return strlen(v);
}
-int lxc_clear_config_item(struct lxc_conf *c, char *key)
+int lxc_clear_config_item(struct lxc_conf *c, const char *key)
{
if (strcmp(key, "lxc.network") == 0)
return lxc_clear_config_network(c);
diff --git a/src/lxc/confile.h b/src/lxc/confile.h
index 7c52447..a96efce 100644
--- a/src/lxc/confile.h
+++ b/src/lxc/confile.h
@@ -27,14 +27,14 @@
struct lxc_conf;
struct lxc_list;
-typedef int (*config_cb)(const char *, char *, struct lxc_conf *);
+typedef int (*config_cb)(const char *, const char *, struct lxc_conf *);
struct lxc_config_t {
char *name;
config_cb cb;
};
extern struct lxc_config_t *lxc_getconfig(const char *key);
-extern int lxc_list_nicconfigs(struct lxc_conf *c, char *key, char *retv, int inlen);
+extern int lxc_list_nicconfigs(struct lxc_conf *c, const char *key, char *retv, int inlen);
extern int lxc_listconfigs(char *retv, int inlen);
extern int lxc_config_read(const char *file, struct lxc_conf *conf);
extern int lxc_config_readline(char *buffer, struct lxc_conf *conf);
@@ -46,7 +46,7 @@ extern int lxc_config_define_load(struct lxc_list *defines,
/* needed for lxc-attach */
extern signed long lxc_config_parse_arch(const char *arch);
-extern int lxc_get_config_item(struct lxc_conf *c, char *key, char *retv, int inlen);
-extern int lxc_clear_config_item(struct lxc_conf *c, char *key);
+extern int lxc_get_config_item(struct lxc_conf *c, const char *key, char *retv, int inlen);
+extern int lxc_clear_config_item(struct lxc_conf *c, const char *key);
extern void write_config(FILE *fout, struct lxc_conf *c);
#endif
diff --git a/src/lxc/lxc.h b/src/lxc/lxc.h
index 93849ec..349bbbc 100644
--- a/src/lxc/lxc.h
+++ b/src/lxc/lxc.h
@@ -182,7 +182,7 @@ extern const char const *lxc_version(void);
/*
* Create and return a new lxccontainer struct.
*/
-extern struct lxc_container *lxc_container_new(char *name);
+extern struct lxc_container *lxc_container_new(const char *name);
/*
* Returns 1 on success, 0 on failure.
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index ed2c483..1f4d390 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -218,7 +218,7 @@ static pid_t lxcapi_init_pid(struct lxc_container *c)
return ret;
}
-static bool load_config_locked(struct lxc_container *c, char *fname)
+static bool load_config_locked(struct lxc_container *c, const char *fname)
{
if (!c->lxc_conf)
c->lxc_conf = lxc_conf_init();
@@ -227,10 +227,10 @@ static bool load_config_locked(struct lxc_container *c, char *fname)
return false;
}
-static bool lxcapi_load_config(struct lxc_container *c, char *alt_file)
+static bool lxcapi_load_config(struct lxc_container *c, const char *alt_file)
{
bool ret = false;
- char *fname;
+ const char *fname;
if (!c)
return false;
@@ -253,7 +253,7 @@ static void lxcapi_want_daemonize(struct lxc_container *c)
c->daemonize = 1;
}
-static bool lxcapi_wait(struct lxc_container *c, char *state, int timeout)
+static bool lxcapi_wait(struct lxc_container *c, const char *state, int timeout)
{
int ret;
@@ -284,7 +284,7 @@ static bool wait_on_daemonized_start(struct lxc_container *c)
* I can't decide if it'd be more convenient for callers if we accept '...',
* or a null-terminated array (i.e. execl vs execv)
*/
-static bool lxcapi_start(struct lxc_container *c, int useinit, char ** argv)
+static bool lxcapi_start(struct lxc_container *c, int useinit, char * const argv[])
{
int ret;
struct lxc_conf *conf;
@@ -499,7 +499,7 @@ static bool create_container_dir(struct lxc_container *c)
* for ->create, argv contains the arguments to pass to the template,
* terminated by NULL. If no arguments, you can just pass NULL.
*/
-static bool lxcapi_create(struct lxc_container *c, char *t, char **argv)
+static bool lxcapi_create(struct lxc_container *c, char *t, char *const argv[])
{
bool bret = false;
pid_t pid;
@@ -703,7 +703,7 @@ out:
return bret;
}
-static bool lxcapi_clear_config_item(struct lxc_container *c, char *key)
+static bool lxcapi_clear_config_item(struct lxc_container *c, const char *key)
{
int ret;
@@ -717,7 +717,7 @@ static bool lxcapi_clear_config_item(struct lxc_container *c, char *key)
return ret == 0;
}
-static int lxcapi_get_config_item(struct lxc_container *c, char *key, char *retv, int inlen)
+static int lxcapi_get_config_item(struct lxc_container *c, const char *key, char *retv, int inlen)
{
int ret;
@@ -731,7 +731,7 @@ static int lxcapi_get_config_item(struct lxc_container *c, char *key, char *retv
return ret;
}
-static int lxcapi_get_keys(struct lxc_container *c, char *key, char *retv, int inlen)
+static int lxcapi_get_keys(struct lxc_container *c, const char *key, char *retv, int inlen)
{
if (!key)
return lxc_listconfigs(retv, inlen);
@@ -754,7 +754,7 @@ static int lxcapi_get_keys(struct lxc_container *c, char *key, char *retv, int i
/* default config file - should probably come through autoconf */
#define LXC_DEFAULT_CONFIG "/etc/lxc/lxc.conf"
-static bool lxcapi_save_config(struct lxc_container *c, char *alt_file)
+static bool lxcapi_save_config(struct lxc_container *c, const char *alt_file)
{
if (!alt_file)
alt_file = c->configfile;
@@ -815,7 +815,7 @@ again:
return WEXITSTATUS(status) == 0;
}
-static bool lxcapi_set_config_item(struct lxc_container *c, char *key, char *v)
+static bool lxcapi_set_config_item(struct lxc_container *c, const char *key, const char *v)
{
int ret;
bool b = false;
@@ -850,7 +850,7 @@ static char *lxcapi_config_file_name(struct lxc_container *c)
return strdup(c->configfile);
}
-struct lxc_container *lxc_container_new(char *name)
+struct lxc_container *lxc_container_new(const char *name)
{
struct lxc_container *c;
int ret, len;
diff --git a/src/lxc/lxccontainer.h b/src/lxc/lxccontainer.h
index cad31ee..2ad497e 100644
--- a/src/lxc/lxccontainer.h
+++ b/src/lxc/lxccontainer.h
@@ -25,9 +25,9 @@ struct lxc_container {
bool (*freeze)(struct lxc_container *c);
bool (*unfreeze)(struct lxc_container *c);
pid_t (*init_pid)(struct lxc_container *c);
- bool (*load_config)(struct lxc_container *c, char *alt_file);
+ bool (*load_config)(struct lxc_container *c, const char *alt_file);
/* The '...' is the command line. If provided, it must be ended with a NULL */
- bool (*start)(struct lxc_container *c, int useinit, char ** argv);
+ bool (*start)(struct lxc_container *c, int useinit, char * const argv[]);
bool (*startl)(struct lxc_container *c, int useinit, ...);
bool (*stop)(struct lxc_container *c);
void (*want_daemonize)(struct lxc_container *c);
@@ -35,20 +35,20 @@ struct lxc_container {
char *(*config_file_name)(struct lxc_container *c);
// for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
// otherwise timeout is seconds to wait.
- bool (*wait)(struct lxc_container *c, char *state, int timeout);
- bool (*set_config_item)(struct lxc_container *c, char *key, char *value);
+ bool (*wait)(struct lxc_container *c, const char *state, int timeout);
+ bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
bool (*destroy)(struct lxc_container *c);
- bool (*save_config)(struct lxc_container *c, char *alt_file);
- bool (*create)(struct lxc_container *c, char *t, char **argv);
+ bool (*save_config)(struct lxc_container *c, const char *alt_file);
+ bool (*create)(struct lxc_container *c, char *t, char *const argv[]);
bool (*createl)(struct lxc_container *c, char *t, ...);
/* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
bool (*shutdown)(struct lxc_container *c, int timeout);
/* clear all network or capability items in the in-memory configuration */
- bool (*clear_config_item)(struct lxc_container *c, char *key);
+ bool (*clear_config_item)(struct lxc_container *c, const char *key);
/* print a config item to a in-memory string allocated by the caller. Return
* the length which was our would be printed. */
- int (*get_config_item)(struct lxc_container *c, char *key, char *retv, int inlen);
- int (*get_keys)(struct lxc_container *c, char *key, char *retv, int inlen);
+ int (*get_config_item)(struct lxc_container *c, const char *key, char *retv, int inlen);
+ int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
#if 0
bool (*commit_cgroups)(struct lxc_container *c);
@@ -60,7 +60,7 @@ struct lxc_container {
#endif
};
-struct lxc_container *lxc_container_new(char *name);
+struct lxc_container *lxc_container_new(const char *name);
int lxc_container_get(struct lxc_container *c);
int lxc_container_put(struct lxc_container *c);
int lxc_get_wait_states(const char **states);
diff --git a/src/lxc/lxclock.c b/src/lxc/lxclock.c
index 95b4470..2d10d77 100644
--- a/src/lxc/lxclock.c
+++ b/src/lxc/lxclock.c
@@ -27,7 +27,7 @@
#define LXCLOCK_PREFIX "/lxcapi."
-static char *lxclock_name(char *container)
+static char *lxclock_name(const char *container)
{
int ret;
int len = strlen(container) + strlen(LXCLOCK_PREFIX) + 1;
@@ -62,7 +62,7 @@ static sem_t *lxc_new_unnamed_sem(void)
return s;
}
-sem_t *lxc_newlock(char *name)
+sem_t *lxc_newlock(const char *name)
{
char *lname;
sem_t *lock;
diff --git a/src/lxc/lxclock.h b/src/lxc/lxclock.h
index 35df182..1226c22 100644
--- a/src/lxc/lxclock.h
+++ b/src/lxc/lxclock.h
@@ -44,7 +44,7 @@
* return NULL on failure, else a sem_t * which can be passed to
* lxclock() and lxcunlock().
*/
-extern sem_t *lxc_newlock(char *name);
+extern sem_t *lxc_newlock(const char *name);
/*
* lxclock: take an existing lock. If timeout is 0, wait
diff --git a/src/lxc/state.c b/src/lxc/state.c
index be66739..7ce4b53 100644
--- a/src/lxc/state.c
+++ b/src/lxc/state.c
@@ -21,6 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <stdio.h>
+#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
@@ -164,26 +165,33 @@ out:
return ret;
}
-static int fillwaitedstates(char *strstates, int *states)
+static int fillwaitedstates(const char *strstates, int *states)
{
char *token, *saveptr = NULL;
+ char *strstates_dup = strdup(strstates);
int state;
- token = strtok_r(strstates, "|", &saveptr);
+ if (!strstates_dup)
+ return -1;
+
+ token = strtok_r(strstates_dup, "|", &saveptr);
while (token) {
state = lxc_str2state(token);
- if (state < 0)
+ if (state < 0) {
+ free(strstates_dup);
return -1;
+ }
states[state] = 1;
token = strtok_r(NULL, "|", &saveptr);
}
+ free(strstates_dup);
return 0;
}
-extern int lxc_wait(char *lxcname, char *states, int timeout)
+extern int lxc_wait(const char *lxcname, const char *states, int timeout)
{
struct lxc_msg msg;
int state, ret;
diff --git a/src/lxc/state.h b/src/lxc/state.h
index 77b3424..df8070a 100644
--- a/src/lxc/state.h
+++ b/src/lxc/state.h
@@ -33,6 +33,6 @@ extern lxc_state_t lxc_getstate(const char *name);
extern lxc_state_t lxc_str2state(const char *state);
extern const char *lxc_state2str(lxc_state_t state);
-extern int lxc_wait(char *lxcname, char *states, int timeout);
+extern int lxc_wait(const char *lxcname, const char *states, int timeout);
#endif
--
1.7.1
More information about the lxc-devel
mailing list