2
0
mirror of git://github.com/lxc/lxc synced 2025-09-01 21:39:28 +00:00

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

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
This commit is contained in:
Christian Brauner
2018-07-26 16:08:29 +02:00
parent 8db9d26faf
commit 62dd965e45

View File

@@ -1007,9 +1007,9 @@ static int set_config_monitor_signal_pdeath(const char *key, const char *value,
static int set_config_group(const char *key, const char *value, static int set_config_group(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
char *groups, *groupptr, *sptr, *token; char *groups, *token;
struct lxc_list *grouplist; struct lxc_list *grouplist;
int ret = -1; int ret = 0;
if (lxc_config_value_empty(value)) if (lxc_config_value_empty(value))
return lxc_clear_groups(lxc_conf); return lxc_clear_groups(lxc_conf);
@@ -1021,20 +1021,17 @@ static int set_config_group(const char *key, const char *value,
/* In case several groups are specified in a single line split these /* In case several groups are specified in a single line split these
* groups in a single element for the list. * groups in a single element for the list.
*/ */
for (groupptr = groups;; groupptr = NULL) { lxc_iterate_parts(token, groups, " \t") {
token = strtok_r(groupptr, " \t", &sptr); grouplist = malloc(sizeof(*grouplist));
if (!token) { if (!grouplist) {
ret = 0; ret = -1;
break; break;
} }
grouplist = malloc(sizeof(*grouplist));
if (!grouplist)
break;
grouplist->elem = strdup(token); grouplist->elem = strdup(token);
if (!grouplist->elem) { if (!grouplist->elem) {
free(grouplist); free(grouplist);
ret = -1;
break; break;
} }
@@ -1678,7 +1675,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, static int set_config_mount_auto(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
char *autos, *autoptr, *sptr, *token; char *autos, *token;
int i; int i;
int ret = -1; int ret = -1;
static struct { static struct {
@@ -1726,15 +1723,9 @@ static int set_config_mount_auto(const char *key, const char *value,
if (!autos) if (!autos)
return -1; return -1;
for (autoptr = autos;; autoptr = NULL) { lxc_iterate_parts(token, autos, " \t") {
bool is_shmounts = false; bool is_shmounts = false;
token = strtok_r(autoptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
for (i = 0; allowed_auto_mounts[i].token; i++) { for (i = 0; allowed_auto_mounts[i].token; i++) {
if (!strcmp(allowed_auto_mounts[i].token, token)) if (!strcmp(allowed_auto_mounts[i].token, token))
break; break;
@@ -1748,7 +1739,7 @@ static int set_config_mount_auto(const char *key, const char *value,
if (!allowed_auto_mounts[i].token) { if (!allowed_auto_mounts[i].token) {
ERROR("Invalid filesystem to automount \"%s\"", token); ERROR("Invalid filesystem to automount \"%s\"", token);
break; goto on_error;
} }
lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask; lxc_conf->auto_mounts &= ~allowed_auto_mounts[i].mask;
@@ -1757,23 +1748,27 @@ static int set_config_mount_auto(const char *key, const char *value,
lxc_conf->shmount.path_host = strdup(token + (sizeof("shmounts:") - 1)); lxc_conf->shmount.path_host = strdup(token + (sizeof("shmounts:") - 1));
if (!lxc_conf->shmount.path_host) { if (!lxc_conf->shmount.path_host) {
SYSERROR("Failed to copy shmounts host path"); SYSERROR("Failed to copy shmounts host path");
break; goto on_error;
} }
if (strcmp(lxc_conf->shmount.path_host, "") == 0) { if (strcmp(lxc_conf->shmount.path_host, "") == 0) {
ERROR("Invalid shmounts path: empty"); ERROR("Invalid shmounts path: empty");
break; goto on_error;
} }
lxc_conf->shmount.path_cont = strdup("/dev/.lxc-mounts"); lxc_conf->shmount.path_cont = strdup("/dev/.lxc-mounts");
if(!lxc_conf->shmount.path_cont) { if(!lxc_conf->shmount.path_cont) {
SYSERROR("Failed to copy shmounts container path"); SYSERROR("Failed to copy shmounts container path");
break; goto on_error;
} }
} }
} }
ret = 0;
on_error:
free(autos); free(autos);
return ret; return ret;
} }
@@ -1809,7 +1804,7 @@ int add_elem_to_mount_list(const char *value, struct lxc_conf *lxc_conf) {
static int set_config_cap_keep(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) struct lxc_conf *lxc_conf, void *data)
{ {
char *keepcaps, *keepptr, *sptr, *token; char *keepcaps, *token;
struct lxc_list *keeplist; struct lxc_list *keeplist;
int ret = -1; int ret = -1;
@@ -1823,29 +1818,26 @@ static int set_config_cap_keep(const char *key, const char *value,
/* In case several capability keep is specified in a single line /* In case several capability keep is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
*/ */
for (keepptr = keepcaps;; keepptr = NULL) { lxc_iterate_parts(token, keepcaps, " \t") {
token = strtok_r(keepptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
if (!strcmp(token, "none")) if (!strcmp(token, "none"))
lxc_clear_config_keepcaps(lxc_conf); lxc_clear_config_keepcaps(lxc_conf);
keeplist = malloc(sizeof(*keeplist)); keeplist = malloc(sizeof(*keeplist));
if (!keeplist) if (!keeplist)
break; goto on_error;
keeplist->elem = strdup(token); keeplist->elem = strdup(token);
if (!keeplist->elem) { if (!keeplist->elem) {
free(keeplist); free(keeplist);
break; goto on_error;
} }
lxc_list_add_tail(&lxc_conf->keepcaps, keeplist); lxc_list_add_tail(&lxc_conf->keepcaps, keeplist);
} }
ret = 0;
on_error:
free(keepcaps); free(keepcaps);
return ret; return ret;
@@ -1854,7 +1846,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, static int set_config_cap_drop(const char *key, const char *value,
struct lxc_conf *lxc_conf, void *data) struct lxc_conf *lxc_conf, void *data)
{ {
char *dropcaps, *dropptr, *sptr, *token; char *dropcaps, *token;
struct lxc_list *droplist; struct lxc_list *droplist;
int ret = -1; int ret = -1;
@@ -1868,26 +1860,23 @@ static int set_config_cap_drop(const char *key, const char *value,
/* In case several capability drop is specified in a single line /* In case several capability drop is specified in a single line
* split these caps in a single element for the list. * split these caps in a single element for the list.
*/ */
for (dropptr = dropcaps;; dropptr = NULL) { lxc_iterate_parts(token, dropcaps, " \t") {
token = strtok_r(dropptr, " \t", &sptr);
if (!token) {
ret = 0;
break;
}
droplist = malloc(sizeof(*droplist)); droplist = malloc(sizeof(*droplist));
if (!droplist) if (!droplist)
break; goto on_error;
droplist->elem = strdup(token); droplist->elem = strdup(token);
if (!droplist->elem) { if (!droplist->elem) {
free(droplist); free(droplist);
break; goto on_error;
} }
lxc_list_add_tail(&lxc_conf->caps, droplist); lxc_list_add_tail(&lxc_conf->caps, droplist);
} }
ret = 0;
on_error:
free(dropcaps); free(dropcaps);
return ret; return ret;
@@ -2186,7 +2175,7 @@ static int set_config_uts_name(const char *key, const char *value,
static int set_config_namespace_clone(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) struct lxc_conf *lxc_conf, void *data)
{ {
char *ns, *nsptr, *token; char *ns, *token;
int cloneflag = 0; int cloneflag = 0;
char *saveptr = NULL; char *saveptr = NULL;
@@ -2203,9 +2192,8 @@ static int set_config_namespace_clone(const char *key, const char *value,
ns = strdup(value); ns = strdup(value);
if (!ns) if (!ns)
return -1; 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_left_gc(token, strlen(token));
token[lxc_char_right_gc(token, strlen(token))] = '\0'; token[lxc_char_right_gc(token, strlen(token))] = '\0';
cloneflag = lxc_namespace_2_cloneflag(token); cloneflag = lxc_namespace_2_cloneflag(token);
@@ -2223,7 +2211,7 @@ static int set_config_namespace_clone(const char *key, const char *value,
static int set_config_namespace_keep(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) struct lxc_conf *lxc_conf, void *data)
{ {
char *ns, *nsptr, *token; char *ns, *token;
int cloneflag = 0; int cloneflag = 0;
char *saveptr = NULL; char *saveptr = NULL;
@@ -2240,9 +2228,8 @@ static int set_config_namespace_keep(const char *key, const char *value,
ns = strdup(value); ns = strdup(value);
if (!ns) if (!ns)
return -1; 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_left_gc(token, strlen(token));
token[lxc_char_right_gc(token, strlen(token))] = '\0'; token[lxc_char_right_gc(token, strlen(token))] = '\0';
cloneflag = lxc_namespace_2_cloneflag(token); cloneflag = lxc_namespace_2_cloneflag(token);
@@ -2541,7 +2528,7 @@ signed long lxc_config_parse_arch(const char *arch)
int lxc_fill_elevated_privileges(char *flaglist, int *flags) int lxc_fill_elevated_privileges(char *flaglist, int *flags)
{ {
char *token, *saveptr = NULL; char *token;
int i, aflag; int i, aflag;
struct { struct {
const char *token; const char *token;
@@ -2563,8 +2550,7 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
return 0; return 0;
} }
token = strtok_r(flaglist, "|", &saveptr); lxc_iterate_parts(token, flaglist, "|") {
while (token) {
aflag = -1; aflag = -1;
for (i = 0; all_privs[i].token; i++) for (i = 0; all_privs[i].token; i++)
@@ -2575,8 +2561,6 @@ int lxc_fill_elevated_privileges(char *flaglist, int *flags)
return -1; return -1;
*flags |= aflag; *flags |= aflag;
token = strtok_r(NULL, "|", &saveptr);
} }
return 0; return 0;