Make config api items const

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@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Dwight Engen 2012-11-26 15:28:14 -05:00 committed by Stéphane Graber
parent 12ad0f90c1
commit 12a50cc6ab
11 changed files with 143 additions and 119 deletions

View File

@ -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' */ /* 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; char *p1;
int ret, idx, i; int ret, idx, i;
@ -2586,11 +2586,11 @@ int lxc_clear_config_caps(struct lxc_conf *c)
return 0; 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; struct lxc_list *it,*next;
bool all = false; bool all = false;
char *k = key + 11; const char *k = key + 11;
if (strcmp(key, "lxc.cgroup") == 0) if (strcmp(key, "lxc.cgroup") == 0)
all = true; all = true;
@ -2620,11 +2620,11 @@ int lxc_clear_mount_entries(struct lxc_conf *c)
return 0; 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; struct lxc_list *it,*next;
bool all = false, done = false; bool all = false, done = false;
char *k = key + 9; const char *k = key + 9;
int i; int i;
if (strcmp(key, "lxc.hook") == 0) if (strcmp(key, "lxc.hook") == 0)

View File

@ -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 void lxc_delete_tty(struct lxc_tty_info *tty_info);
extern int lxc_clear_config_network(struct lxc_conf *c); 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_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_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 * Configure the container from inside

View File

@ -20,6 +20,7 @@
* License along with this library; if not, write to the Free Software * License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#define _GNU_SOURCE
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
@ -46,40 +47,40 @@
lxc_log_define(lxc_confile, lxc); lxc_log_define(lxc_confile, lxc);
static int config_personality(const char *, char *, struct lxc_conf *); static int config_personality(const char *, const char *, struct lxc_conf *);
static int config_pts(const char *, char *, struct lxc_conf *); static int config_pts(const char *, const char *, struct lxc_conf *);
static int config_tty(const char *, char *, struct lxc_conf *); static int config_tty(const char *, const char *, struct lxc_conf *);
static int config_ttydir(const char *, char *, struct lxc_conf *); static int config_ttydir(const char *, const char *, struct lxc_conf *);
#if HAVE_APPARMOR #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 #endif
static int config_cgroup(const char *, char *, struct lxc_conf *); static int config_cgroup(const char *, const char *, struct lxc_conf *);
static int config_mount(const char *, char *, struct lxc_conf *); static int config_mount(const char *, const char *, struct lxc_conf *);
static int config_rootfs(const char *, char *, struct lxc_conf *); static int config_rootfs(const char *, const char *, struct lxc_conf *);
static int config_rootfs_mount(const char *, char *, struct lxc_conf *); static int config_rootfs_mount(const char *, const char *, struct lxc_conf *);
static int config_pivotdir(const char *, char *, struct lxc_conf *); static int config_pivotdir(const char *, const char *, struct lxc_conf *);
static int config_utsname(const char *, char *, struct lxc_conf *); static int config_utsname(const char *, const char *, struct lxc_conf *);
static int config_hook(const char *key, char *value, struct lxc_conf *lxc_conf); static int config_hook(const char *, const char *, struct lxc_conf *lxc_conf);
static int config_network_type(const char *, char *, struct lxc_conf *); static int config_network_type(const char *, const char *, struct lxc_conf *);
static int config_network_flags(const char *, char *, struct lxc_conf *); static int config_network_flags(const char *, const char *, struct lxc_conf *);
static int config_network_link(const char *, char *, struct lxc_conf *); static int config_network_link(const char *, const char *, struct lxc_conf *);
static int config_network_name(const char *, char *, struct lxc_conf *); static int config_network_name(const char *, const char *, struct lxc_conf *);
static int config_network_veth_pair(const char *, 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 *, char *, struct lxc_conf *); static int config_network_macvlan_mode(const char *, const char *, struct lxc_conf *);
static int config_network_hwaddr(const char *, char *, struct lxc_conf *); static int config_network_hwaddr(const char *, const char *, struct lxc_conf *);
static int config_network_vlan_id(const char *, char *, struct lxc_conf *); static int config_network_vlan_id(const char *, const char *, struct lxc_conf *);
static int config_network_mtu(const char *, char *, struct lxc_conf *); static int config_network_mtu(const char *, const char *, struct lxc_conf *);
static int config_network_ipv4(const char *, char *, struct lxc_conf *); static int config_network_ipv4(const char *, const char *, struct lxc_conf *);
static int config_network_ipv4_gateway(const char *, char *, struct lxc_conf *); static int config_network_ipv4_gateway(const char *, const char *, struct lxc_conf *);
static int config_network_script(const char *, char *, struct lxc_conf *); static int config_network_script(const char *, const char *, struct lxc_conf *);
static int config_network_ipv6(const char *, char *, struct lxc_conf *); static int config_network_ipv6(const char *, const char *, struct lxc_conf *);
static int config_network_ipv6_gateway(const char *, char *, struct lxc_conf *); static int config_network_ipv6_gateway(const char *, const char *, struct lxc_conf *);
static int config_cap_drop(const char *, char *, struct lxc_conf *); static int config_cap_drop(const char *, const char *, struct lxc_conf *);
static int config_console(const char *, char *, struct lxc_conf *); static int config_console(const char *, const char *, struct lxc_conf *);
static int config_seccomp(const char *, char *, struct lxc_conf *); static int config_seccomp(const char *, const char *, struct lxc_conf *);
static int config_includefile(const char *, char *, struct lxc_conf *); static int config_includefile(const char *, const char *, struct lxc_conf *);
static int config_network_nic(const char *, char *, struct lxc_conf *); static int config_network_nic(const char *, const char *, struct lxc_conf *);
static int config_autodev(const char *, char *, struct lxc_conf *); static int config_autodev(const char *, const char *, struct lxc_conf *);
static struct lxc_config_t config[] = { static struct lxc_config_t config[] = {
@ -97,7 +98,7 @@ static struct lxc_config_t config[] = {
{ "lxc.pivotdir", config_pivotdir }, { "lxc.pivotdir", config_pivotdir },
{ "lxc.utsname", config_utsname }, { "lxc.utsname", config_utsname },
{ "lxc.hook.pre-start", config_hook }, { "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.mount", config_hook },
{ "lxc.hook.start", config_hook }, { "lxc.hook.start", config_hook },
{ "lxc.hook.post-stop", 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 * comes an integer, find the right callback (by rewriting
* the key), and call it. * 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) struct lxc_conf *lxc_conf)
{ {
char *copy = strdup(key), *p; char *copy = strdup(key), *p;
@ -208,7 +209,7 @@ out:
return ret; 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_conf *lxc_conf)
{ {
struct lxc_list *network = &lxc_conf->network; struct lxc_list *network = &lxc_conf->network;
@ -302,7 +303,8 @@ static struct lxc_netdev *get_netdev_from_key(const char *key,
return netdev; 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; struct lxc_netdev *netdev;
int fulllen = 0, len; int fulllen = 0, len;
@ -369,7 +371,7 @@ static struct lxc_netdev *network_netdev(const char *key, const char *value,
return netdev; return netdev;
} }
static int network_ifname(char **valuep, char *value) static int network_ifname(char **valuep, const char *value)
{ {
if (strlen(value) >= IFNAMSIZ) { if (strlen(value) >= IFNAMSIZ) {
ERROR("interface name '%s' too long (>%d)\n", 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 # define MACVLAN_MODE_BRIDGE 4
#endif #endif
static int macvlan_mode(int *valuep, char *value) static int macvlan_mode(int *valuep, const char *value)
{ {
struct mc_mode { struct mc_mode {
char *name; char *name;
@ -422,7 +424,7 @@ static int macvlan_mode(int *valuep, char *value)
return -1; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -436,7 +438,7 @@ static int config_network_flags(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -448,7 +450,7 @@ static int config_network_link(const char *key, char *value,
return network_ifname(&netdev->link, 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -460,7 +462,7 @@ static int config_network_name(const char *key, char *value,
return network_ifname(&netdev->name, 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; 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); 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; 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); 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -506,7 +508,7 @@ static int config_network_hwaddr(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -521,7 +523,7 @@ static int config_network_vlan_id(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -543,7 +545,7 @@ static int config_network_mtu(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -571,7 +573,7 @@ static int config_network_ipv4(const char *key, char *value,
lxc_list_init(list); lxc_list_init(list);
list->elem = inetdev; list->elem = inetdev;
addr = value; addr = strdupa(value);
cursor = strstr(addr, " "); cursor = strstr(addr, " ");
if (cursor) { if (cursor) {
@ -618,7 +620,7 @@ static int config_network_ipv4(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -655,13 +657,13 @@ static int config_network_ipv4_gateway(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
struct lxc_inet6dev *inet6dev; struct lxc_inet6dev *inet6dev;
struct lxc_list *list; struct lxc_list *list;
char *slash; char *slash,*valdup;
char *netmask; char *netmask;
netdev = network_netdev(key, value, &lxc_conf->network); 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); lxc_list_init(list);
list->elem = inet6dev; list->elem = inet6dev;
valdup = strdupa(value);
inet6dev->prefix = 64; inet6dev->prefix = 64;
slash = strstr(value, "/"); slash = strstr(valdup, "/");
if (slash) { if (slash) {
*slash = '\0'; *slash = '\0';
netmask = slash + 1; netmask = slash + 1;
@ -702,7 +705,7 @@ static int config_network_ipv6(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -739,7 +742,7 @@ static int config_network_ipv6_gateway(const char *key, char *value,
return 0; 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_conf *lxc_conf)
{ {
struct lxc_netdev *netdev; struct lxc_netdev *netdev;
@ -780,7 +783,7 @@ static int add_hook(struct lxc_conf *lxc_conf, int which, char *hook)
return 0; 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) struct lxc_conf *lxc_conf)
{ {
char *path; char *path;
@ -802,7 +805,7 @@ static int config_seccomp(const char *key, char *value,
return 0; 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) struct lxc_conf *lxc_conf)
{ {
char *copy = strdup(value); char *copy = strdup(value);
@ -825,7 +828,7 @@ static int config_hook(const char *key, char *value,
return -1; 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) struct lxc_conf *lxc_conf)
{ {
signed long personality = lxc_config_parse_arch(value); signed long personality = lxc_config_parse_arch(value);
@ -838,7 +841,8 @@ static int config_personality(const char *key, char *value,
return 0; 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); int maxpts = atoi(value);
@ -847,7 +851,8 @@ static int config_pts(const char *key, char *value, struct lxc_conf *lxc_conf)
return 0; 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); int nbtty = atoi(value);
@ -856,7 +861,7 @@ static int config_tty(const char *key, char *value, struct lxc_conf *lxc_conf)
return 0; 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) struct lxc_conf *lxc_conf)
{ {
char *path; char *path;
@ -877,7 +882,8 @@ static int config_ttydir(const char *key, char *value,
} }
#if HAVE_APPARMOR #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; char *path;
@ -897,7 +903,7 @@ static int config_aa_profile(const char *key, char *value, struct lxc_conf *lxc_
} }
#endif #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) struct lxc_conf *lxc_conf)
{ {
int v = atoi(value); int v = atoi(value);
@ -907,7 +913,8 @@ static int config_autodev(const char *key, char *value,
return 0; 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 *token = "lxc.cgroup.";
char *subkey; 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); 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 *fstab_token = "lxc.mount";
char *token = "lxc.mount.entry"; 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; 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) struct lxc_conf *lxc_conf)
{ {
char *dropcaps, *dropptr, *sptr, *token; char *dropcaps, *dropptr, *sptr, *token;
@ -1074,7 +1082,7 @@ static int config_cap_drop(const char *key, char *value,
return ret; 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) struct lxc_conf *lxc_conf)
{ {
char *path; char *path;
@ -1092,28 +1100,32 @@ static int config_console(const char *key, char *value,
return 0; 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) struct lxc_conf *lxc_conf)
{ {
return lxc_config_read(value, 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); 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); 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); 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; 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, * If you ask for 'lxc.cgroup", then all cgroup entries will be printed,
* in 'lxc.cgroup.subsystem.key = value' format. * 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 fulllen = 0, len;
int all = 0; int all = 0;
@ -1323,7 +1336,8 @@ static int lxc_get_cgroup_entry(struct lxc_conf *c, char *retv, int inlen, char
return fulllen; 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; char *subkey;
int len, fulllen = 0, found = -1; 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 * things like veth.pair return '' if invalid (i.e. if called for vlan
* type). * 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; char *p1;
int len, fulllen = 0; int len, fulllen = 0;
@ -1508,7 +1523,8 @@ static int lxc_get_item_network(struct lxc_conf *c, char *retv, int inlen)
return fulllen; 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; 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); 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) if (strcmp(key, "lxc.network") == 0)
return lxc_clear_config_network(c); return lxc_clear_config_network(c);

View File

@ -27,14 +27,14 @@
struct lxc_conf; struct lxc_conf;
struct lxc_list; 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 { struct lxc_config_t {
char *name; char *name;
config_cb cb; config_cb cb;
}; };
extern struct lxc_config_t *lxc_getconfig(const char *key); 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_listconfigs(char *retv, int inlen);
extern int lxc_config_read(const char *file, struct lxc_conf *conf); extern int lxc_config_read(const char *file, struct lxc_conf *conf);
extern int lxc_config_readline(char *buffer, 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 */ /* needed for lxc-attach */
extern signed long lxc_config_parse_arch(const char *arch); 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_get_config_item(struct lxc_conf *c, const char *key, char *retv, int inlen);
extern int lxc_clear_config_item(struct lxc_conf *c, char *key); extern int lxc_clear_config_item(struct lxc_conf *c, const char *key);
extern void write_config(FILE *fout, struct lxc_conf *c); extern void write_config(FILE *fout, struct lxc_conf *c);
#endif #endif

View File

@ -182,7 +182,7 @@ extern const char const *lxc_version(void);
/* /*
* Create and return a new lxccontainer struct. * 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. * Returns 1 on success, 0 on failure.

View File

@ -218,7 +218,7 @@ static pid_t lxcapi_init_pid(struct lxc_container *c)
return ret; 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) if (!c->lxc_conf)
c->lxc_conf = lxc_conf_init(); c->lxc_conf = lxc_conf_init();
@ -227,10 +227,10 @@ static bool load_config_locked(struct lxc_container *c, char *fname)
return false; 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; bool ret = false;
char *fname; const char *fname;
if (!c) if (!c)
return false; return false;
@ -253,7 +253,7 @@ static void lxcapi_want_daemonize(struct lxc_container *c)
c->daemonize = 1; 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; 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 '...', * 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) * 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; int ret;
struct lxc_conf *conf; 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, * for ->create, argv contains the arguments to pass to the template,
* terminated by NULL. If no arguments, you can just pass NULL. * 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; bool bret = false;
pid_t pid; pid_t pid;
@ -703,7 +703,7 @@ out:
return bret; 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; int ret;
@ -717,7 +717,7 @@ static bool lxcapi_clear_config_item(struct lxc_container *c, char *key)
return ret == 0; 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; int ret;
@ -731,7 +731,7 @@ static int lxcapi_get_config_item(struct lxc_container *c, char *key, char *retv
return ret; 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) if (!key)
return lxc_listconfigs(retv, inlen); 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 */ /* default config file - should probably come through autoconf */
#define LXC_DEFAULT_CONFIG "/etc/lxc/lxc.conf" #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) if (!alt_file)
alt_file = c->configfile; alt_file = c->configfile;
@ -815,7 +815,7 @@ again:
return WEXITSTATUS(status) == 0; 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; int ret;
bool b = false; bool b = false;
@ -850,7 +850,7 @@ static char *lxcapi_config_file_name(struct lxc_container *c)
return strdup(c->configfile); 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; struct lxc_container *c;
int ret, len; int ret, len;

View File

@ -24,9 +24,9 @@ struct lxc_container {
bool (*freeze)(struct lxc_container *c); bool (*freeze)(struct lxc_container *c);
bool (*unfreeze)(struct lxc_container *c); bool (*unfreeze)(struct lxc_container *c);
pid_t (*init_pid)(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 */ /* 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 (*startl)(struct lxc_container *c, int useinit, ...);
bool (*stop)(struct lxc_container *c); bool (*stop)(struct lxc_container *c);
void (*want_daemonize)(struct lxc_container *c); void (*want_daemonize)(struct lxc_container *c);
@ -34,20 +34,20 @@ struct lxc_container {
char *(*config_file_name)(struct lxc_container *c); char *(*config_file_name)(struct lxc_container *c);
// for wait, timeout == -1 means wait forever, timeout == 0 means don't wait. // for wait, timeout == -1 means wait forever, timeout == 0 means don't wait.
// otherwise timeout is seconds to wait. // otherwise timeout is seconds to wait.
bool (*wait)(struct lxc_container *c, char *state, int timeout); bool (*wait)(struct lxc_container *c, const char *state, int timeout);
bool (*set_config_item)(struct lxc_container *c, char *key, char *value); bool (*set_config_item)(struct lxc_container *c, const char *key, const char *value);
bool (*destroy)(struct lxc_container *c); bool (*destroy)(struct lxc_container *c);
bool (*save_config)(struct lxc_container *c, char *alt_file); bool (*save_config)(struct lxc_container *c, const char *alt_file);
bool (*create)(struct lxc_container *c, char *t, char **argv); bool (*create)(struct lxc_container *c, char *t, char *const argv[]);
bool (*createl)(struct lxc_container *c, char *t, ...); bool (*createl)(struct lxc_container *c, char *t, ...);
/* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */ /* send SIGPWR. if timeout is not 0 or -1, do a hard stop after timeout seconds */
bool (*shutdown)(struct lxc_container *c, int timeout); bool (*shutdown)(struct lxc_container *c, int timeout);
/* clear all network or capability items in the in-memory configuration */ /* 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 /* print a config item to a in-memory string allocated by the caller. Return
* the length which was our would be printed. */ * the length which was our would be printed. */
int (*get_config_item)(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, char *key, char *retv, int inlen); int (*get_keys)(struct lxc_container *c, const char *key, char *retv, int inlen);
#if 0 #if 0
bool (*commit_cgroups)(struct lxc_container *c); bool (*commit_cgroups)(struct lxc_container *c);
@ -59,7 +59,7 @@ struct lxc_container {
#endif #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_get(struct lxc_container *c);
int lxc_container_put(struct lxc_container *c); int lxc_container_put(struct lxc_container *c);
int lxc_get_wait_states(const char **states); int lxc_get_wait_states(const char **states);

View File

@ -27,7 +27,7 @@
#define LXCLOCK_PREFIX "/lxcapi." #define LXCLOCK_PREFIX "/lxcapi."
static char *lxclock_name(char *container) static char *lxclock_name(const char *container)
{ {
int ret; int ret;
int len = strlen(container) + strlen(LXCLOCK_PREFIX) + 1; int len = strlen(container) + strlen(LXCLOCK_PREFIX) + 1;
@ -62,7 +62,7 @@ static sem_t *lxc_new_unnamed_sem(void)
return s; return s;
} }
sem_t *lxc_newlock(char *name) sem_t *lxc_newlock(const char *name)
{ {
char *lname; char *lname;
sem_t *lock; sem_t *lock;

View File

@ -44,7 +44,7 @@
* return NULL on failure, else a sem_t * which can be passed to * return NULL on failure, else a sem_t * which can be passed to
* lxclock() and lxcunlock(). * 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 * lxclock: take an existing lock. If timeout is 0, wait

View File

@ -21,6 +21,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
@ -164,26 +165,33 @@ out:
return ret; return ret;
} }
static int fillwaitedstates(char *strstates, int *states) static int fillwaitedstates(const char *strstates, int *states)
{ {
char *token, *saveptr = NULL; char *token, *saveptr = NULL;
char *strstates_dup = strdup(strstates);
int state; int state;
token = strtok_r(strstates, "|", &saveptr); if (!strstates_dup)
return -1;
token = strtok_r(strstates_dup, "|", &saveptr);
while (token) { while (token) {
state = lxc_str2state(token); state = lxc_str2state(token);
if (state < 0) if (state < 0) {
free(strstates_dup);
return -1; return -1;
}
states[state] = 1; states[state] = 1;
token = strtok_r(NULL, "|", &saveptr); token = strtok_r(NULL, "|", &saveptr);
} }
free(strstates_dup);
return 0; 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; struct lxc_msg msg;
int state, ret; int state, ret;

View File

@ -33,6 +33,6 @@ extern lxc_state_t lxc_getstate(const char *name);
extern lxc_state_t lxc_str2state(const char *state); extern lxc_state_t lxc_str2state(const char *state);
extern const char *lxc_state2str(lxc_state_t 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 #endif