src: Fix an error for the loop initialization declaration
authorYang Xu <xuyang2018.jy@fujitsu.com>
Sun, 25 Apr 2021 10:02:38 +0000 (18:02 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 9 May 2021 13:49:33 +0000 (21:49 +0800)
When compile them old gcc, get the following error
mount-idmapped.c: In function 'parse_map':
mount-idmapped.c:154:2: error: 'for' loop initial declarations are only allowed in C99 mode
  for (int i = 0; i < 2; i++) {

Fix them by declaring them at the beggining instead of in loop.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
Reviewed-by: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
src/detached_mounts_propagation.c
src/idmapped-mounts/mount-idmapped.c

index 99b6630838d747bb7b63860dfd7838bb02f2a435..d4bc87f90984777c199ce734b90c2f46019d0696 100644 (file)
@@ -96,7 +96,7 @@ static const struct option longopts[] = {
 int main(int argc, char *argv[])
 {
        int exit_code = EXIT_SUCCESS, index = 0;
-       int dfd, fd_tree, new_argc, ret;
+       int dfd, fd_tree, new_argc, ret, i;
        char *base_dir;
        char *const *new_argv;
        char target[PATH_MAX];
@@ -147,7 +147,7 @@ int main(int argc, char *argv[])
         * Having a mount table with 10000 mounts is already quite excessive
         * and shoult account even for weird test systems.
         */
-       for (size_t i = 0; i < 10000; i++) {
+       for (i = 0; i < 10000; i++) {
                fd_tree = sys_open_tree(dfd, "detached-move-mount",
                                        OPEN_TREE_CLONE |
                                        OPEN_TREE_CLOEXEC |
index 5f5ba5d21658939bdb219db9c6ac98f6850e047b..b3e9e27b0f0ae3153655ded66c0f1d112f0dc3e9 100644 (file)
@@ -137,7 +137,7 @@ static int add_map_entry(__u32 id_host,
 static int parse_map(char *map)
 {
        char types[2] = {'u', 'g'};
-       int ret;
+       int ret, i;
        __u32 id_host, id_ns, range;
        char which;
 
@@ -151,7 +151,7 @@ static int parse_map(char *map)
        if (which != 'b' && which != 'u' && which != 'g')
                return -1;
 
-       for (int i = 0; i < 2; i++) {
+       for (i = 0; i < 2; i++) {
                idmap_type_t map_type;
 
                if (which != types[i] && which != 'b')
@@ -230,8 +230,9 @@ static int map_ids_from_idmap(struct list *idmap, pid_t pid)
        int fill, left;
        char mapbuf[4096] = {};
        bool had_entry = false;
+       idmap_type_t map_type, u_or_g;
 
-       for (idmap_type_t map_type = ID_TYPE_UID, u_or_g = 'u';
+       for (map_type = ID_TYPE_UID, u_or_g = 'u';
             map_type <= ID_TYPE_GID; map_type++, u_or_g = 'g') {
                char *pos = mapbuf;
                int ret;