confile: s/strtok_r()/lxc_iterate_parts()/g

parent 69795191
......@@ -979,9 +979,9 @@ static int set_config_monitor(const char *key, const char *value,
static int set_config_group(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *groups, *groupptr, *sptr, *token;
char *groups, *token;
struct lxc_list *grouplist;
int ret = -1;
int ret = 0;
if (lxc_config_value_empty(value))
return lxc_clear_groups(lxc_conf);
......@@ -993,20 +993,17 @@ static int set_config_group(const char *key, const char *value,
/* In case several groups are specified in a single line split these
* groups in a single element for the list.
*/
for (groupptr = groups;; groupptr = NULL) {
token = strtok_r(groupptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
lxc_iterate_parts(token, groups, " \t") {
grouplist = malloc(sizeof(*grouplist));
if (!grouplist)
if (!grouplist) {
ret = -1;
break;
}
grouplist->elem = strdup(token);
if (!grouplist->elem) {
free(grouplist);
ret = -1;
break;
}
......@@ -1590,7 +1587,7 @@ static int set_config_mount_fstab(const char *key, const char *value,
static int set_config_mount_auto(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *autos, *autoptr, *sptr, *token;
char *autos, *token;
int i;
int ret = -1;
static struct {
......@@ -1637,13 +1634,7 @@ static int set_config_mount_auto(const char *key, const char *value,
if (!autos)
return -1;
for (autoptr = autos;; autoptr = NULL) {
token = strtok_r(autoptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
lxc_iterate_parts(token, autos, " \t") {
for (i = 0; allowed_auto_mounts[i].token; i++) {
if (!strcmp(allowed_auto_mounts[i].token, token))
break;
......@@ -1651,14 +1642,18 @@ static int set_config_mount_auto(const char *key, const char *value,
if (!allowed_auto_mounts[i].token) {
ERROR("Invalid filesystem to automount \"%s\"", token);
break;
goto on_error;
}
lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
lxc_conf->auto_mounts |= allowed_auto_mounts[i].flag;
}
ret = 0;
on_error:
free(autos);
return ret;
}
......@@ -1690,7 +1685,7 @@ static int set_config_mount(const char *key, const char *value,
static int set_config_cap_keep(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *keepcaps, *keepptr, *sptr, *token;
char *keepcaps, *token;
struct lxc_list *keeplist;
int ret = -1;
......@@ -1704,29 +1699,26 @@ static int set_config_cap_keep(const char *key, const char *value,
/* In case several capability keep is specified in a single line
* split these caps in a single element for the list.
*/
for (keepptr = keepcaps;; keepptr = NULL) {
token = strtok_r(keepptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
lxc_iterate_parts(token, keepcaps, " \t") {
if (!strcmp(token, "none"))
lxc_clear_config_keepcaps(lxc_conf);
keeplist = malloc(sizeof(*keeplist));
if (!keeplist)
break;
goto on_error;
keeplist->elem = strdup(token);
if (!keeplist->elem) {
free(keeplist);
break;
goto on_error;
}
lxc_list_add_tail(&lxc_conf->keepcaps, keeplist);
}
ret = 0;
on_error:
free(keepcaps);
return ret;
......@@ -1735,7 +1727,7 @@ static int set_config_cap_keep(const char *key, const char *value,
static int set_config_cap_drop(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *dropcaps, *dropptr, *sptr, *token;
char *dropcaps, *token;
struct lxc_list *droplist;
int ret = -1;
......@@ -1749,26 +1741,23 @@ static int set_config_cap_drop(const char *key, const char *value,
/* In case several capability drop is specified in a single line
* split these caps in a single element for the list.
*/
for (dropptr = dropcaps;; dropptr = NULL) {
token = strtok_r(dropptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
lxc_iterate_parts(token, dropcaps, " \t") {
droplist = malloc(sizeof(*droplist));
if (!droplist)
break;
goto on_error;
droplist->elem = strdup(token);
if (!droplist->elem) {
free(droplist);
break;
goto on_error;
}
lxc_list_add_tail(&lxc_conf->caps, droplist);
}
ret = 0;
on_error:
free(dropcaps);
return ret;
......@@ -2067,9 +2056,8 @@ static int set_config_uts_name(const char *key, const char *value,
static int set_config_namespace_clone(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *ns, *nsptr, *token;
char *ns, *token;
int cloneflag = 0;
char *saveptr = NULL;
if (lxc_config_value_empty(value))
return clr_config_namespace_clone(key, lxc_conf, data);
......@@ -2084,9 +2072,8 @@ static int set_config_namespace_clone(const char *key, const char *value,
ns = strdup(value);
if (!ns)
return -1;
nsptr = ns;
for (; (token = strtok_r(nsptr, " \t", &saveptr)); nsptr = NULL) {
lxc_iterate_parts(token, ns, " \t") {
token += lxc_char_left_gc(token, strlen(token));
token[lxc_char_right_gc(token, strlen(token))] = '\0';
cloneflag = lxc_namespace_2_cloneflag(token);
......@@ -2104,9 +2091,8 @@ static int set_config_namespace_clone(const char *key, const char *value,
static int set_config_namespace_keep(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data)
{
char *ns, *nsptr, *token;
char *ns, *token;
int cloneflag = 0;
char *saveptr = NULL;
if (lxc_config_value_empty(value))
return clr_config_namespace_keep(key, lxc_conf, data);
......@@ -2121,9 +2107,8 @@ static int set_config_namespace_keep(const char *key, const char *value,
ns = strdup(value);
if (!ns)
return -1;
nsptr = ns;
for (; (token = strtok_r(nsptr, " \t", &saveptr)); nsptr = NULL) {
lxc_iterate_parts(token, ns, " \t") {
token += lxc_char_left_gc(token, strlen(token));
token[lxc_char_right_gc(token, strlen(token))] = '\0';
cloneflag = lxc_namespace_2_cloneflag(token);
......@@ -2422,7 +2407,7 @@ signed long lxc_config_parse_arch(const char *arch)
int lxc_fill_elevated_privileges(char *flaglist, int *flags)
{
char *token, *saveptr = NULL;
char *token;
int i, aflag;
struct {
const char *token;
......@@ -2444,8 +2429,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
return 0;
}
token = strtok_r(flaglist, "|", &saveptr);
while (token) {
lxc_iterate_parts(token, flaglist, "|") {
aflag = -1;
for (i = 0; all_privs[i].token; i++)
......@@ -2456,8 +2440,6 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
return -1;
*flags |= aflag;
token = strtok_r(NULL, "|", &saveptr);
}
return 0;
......
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