]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
tools: s/strtok_r()/lxc_iterate_parts()/g
authorChristian Brauner <christian.brauner@ubuntu.com>
Thu, 26 Jul 2018 14:19:42 +0000 (16:19 +0200)
committerChristian Brauner <christian.brauner@ubuntu.com>
Thu, 26 Jul 2018 14:38:42 +0000 (16:38 +0200)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/tools/lxc_autostart.c
src/lxc/tools/lxc_destroy.c

index 96fce421da3b49ccb26a85bfeb241859b6567aad..5d0445258ecaaefd4c4649c75005d060baf35eb7 100644 (file)
@@ -194,8 +194,6 @@ static struct lxc_list *accumulate_list(char *input, char *delimiter,
 static struct lxc_list *get_list(char *input, char *delimiter)
 {
        char *workstr = NULL;
-       char *workptr = NULL;
-       char *sptr = NULL;
        char *token = NULL;
        struct lxc_list *worklist;
        struct lxc_list *workstr_list;
@@ -212,11 +210,7 @@ static struct lxc_list *get_list(char *input, char *delimiter)
                return NULL;
        }
 
-       for (workptr = workstr;; workptr = NULL) {
-               token = strtok_r(workptr, delimiter, &sptr);
-               if (!token)
-                       break;
-
+       lxc_iterate_parts(token, workstr, delimiter) {
                worklist = malloc(sizeof(*worklist));
                if (!worklist)
                        break;
index f7bd06d87ca2ce40c0337ec10bf4e5e80bd7c667..35514689f0fb96656de08d6951f7232e204b2a3a 100644 (file)
@@ -209,10 +209,8 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
        char *buf = NULL;
        char *lxcpath = NULL;
        char *lxcname = NULL;
-       char *scratch = NULL;
        int fd;
        int ret;
-       int counter = 0;
 
        /* Destroy clones. */
        ret = snprintf(path, MAXPATHLEN, "%s/%s/lxc_snapshots", c->config_path, c->name);
@@ -244,15 +242,10 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
                }
                close(fd);
 
-               while ((lxcpath = strtok_r(!counter ? buf : NULL, "\n", &scratch))) {
-                       if (!(lxcname = strtok_r(NULL, "\n", &scratch)))
-                               break;
-
+               lxc_iterate_parts(lxcpath, buf, "\n") {
                        c1 = lxc_container_new(lxcname, lxcpath);
-                       if (!c1) {
-                               counter++;
+                       if (!c1)
                                continue;
-                       }
 
                        /* We do not destroy recursively. If a clone of a clone
                         * has clones or snapshots the user should remove it
@@ -264,7 +257,6 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
                        }
 
                        lxc_container_put(c1);
-                       counter++;
                }
                free(buf);
        }