All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yang Xu <xuyang2018.jy@fujitsu.com>
To: <fstests@vger.kernel.org>
Cc: Yang Xu <xuyang2018.jy@fujitsu.com>
Subject: [PATCH v2 1/3] src/*: Fix an error for the loop initialization declaration
Date: Mon, 26 Apr 2021 14:23:05 +0800	[thread overview]
Message-ID: <1619418187-19951-1-git-send-email-xuyang2018.jy@fujitsu.com> (raw)

When compile them on 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 beginning instead of in loop.

Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
---
 src/detached_mounts_propagation.c    | 4 ++--
 src/idmapped-mounts/mount-idmapped.c | 7 ++++---
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/src/detached_mounts_propagation.c b/src/detached_mounts_propagation.c
index 99b66308..d4bc87f9 100644
--- a/src/detached_mounts_propagation.c
+++ b/src/detached_mounts_propagation.c
@@ -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 |
diff --git a/src/idmapped-mounts/mount-idmapped.c b/src/idmapped-mounts/mount-idmapped.c
index 5f5ba5d2..b3e9e27b 100644
--- a/src/idmapped-mounts/mount-idmapped.c
+++ b/src/idmapped-mounts/mount-idmapped.c
@@ -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;
-- 
2.23.0


             reply	other threads:[~2021-04-26  5:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-26  6:23 Yang Xu [this message]
2021-04-26  6:23 ` [PATCH v2 2/3] idmapped-mounts.c: Use renameat instead of renameat2 Yang Xu
2021-04-26 14:32   ` Christian Brauner
2021-04-27  1:34     ` xuyang2018.jy
2021-04-28  6:50   ` Anju T Sudhakar
2021-04-26  6:23 ` [PATCH v2 3/3] src/idmapped-mounts: Remove useless header file Yang Xu
2021-04-26 14:32   ` Christian Brauner
2021-04-26 14:30 ` [PATCH v2 1/3] src/*: Fix an error for the loop initialization declaration Christian Brauner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1619418187-19951-1-git-send-email-xuyang2018.jy@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --cc=fstests@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.