[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <d32e90ccce3003fa0cdf05b95e0427de8a28684e.1653446538.git.peilin.ye@bytedance.com>
Date: Tue, 24 May 2022 19:53:05 -0700
From: Peilin Ye <yepeilin.cs@...il.com>
To: Stephen Hemminger <stephen@...workplumber.org>,
David Ahern <dsahern@...nel.org>, netdev@...r.kernel.org
Cc: Peilin Ye <peilin.ye@...edance.com>,
Richard Haines <richard_c_haines@...nternet.com>,
Cong Wang <cong.wang@...edance.com>,
Peilin Ye <yepeilin.cs@...il.com>
Subject: [PATCH iproute2-next 5/7] ss: Fix coding style issues in user_ent_hash_build()
From: Peilin Ye <peilin.ye@...edance.com>
Make checkpatch.pl --strict happy about user_ent_hash_build().
Signed-off-by: Peilin Ye <peilin.ye@...edance.com>
---
misc/ss.c | 22 ++++++++++++----------
1 file changed, 12 insertions(+), 10 deletions(-)
diff --git a/misc/ss.c b/misc/ss.c
index ec14d746c669..42d04bf432eb 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -599,7 +599,7 @@ static void user_ent_hash_build(void)
strlcpy(name, root, sizeof(name));
- if (strlen(name) == 0 || name[strlen(name)-1] != '/')
+ if (strlen(name) == 0 || name[strlen(name) - 1] != '/')
strcat(name, "/");
nameoff = strlen(name);
@@ -622,7 +622,8 @@ static void user_ent_hash_build(void)
snprintf(name + nameoff, sizeof(name) - nameoff, "%d/fd/", pid);
pos = strlen(name);
- if ((dir1 = opendir(name)) == NULL) {
+ dir1 = opendir(name);
+ if (!dir1) {
freecon(pid_context);
continue;
}
@@ -640,9 +641,9 @@ static void user_ent_hash_build(void)
if (sscanf(d1->d_name, "%d%*c", &fd) != 1)
continue;
- snprintf(name+pos, sizeof(name) - pos, "%d", fd);
+ snprintf(name + pos, sizeof(name) - pos, "%d", fd);
- link_len = readlink(name, lnk, sizeof(lnk)-1);
+ link_len = readlink(name, lnk, sizeof(lnk) - 1);
if (link_len == -1)
continue;
lnk[link_len] = '\0';
@@ -650,7 +651,8 @@ static void user_ent_hash_build(void)
if (strncmp(lnk, pattern, strlen(pattern)))
continue;
- sscanf(lnk, "socket:[%u]", &ino);
+ if (sscanf(lnk, "socket:[%u]", &ino) != 1)
+ continue;
if (getfilecon(name, &sock_context) <= 0)
sock_context = strdup(no_ctx);
@@ -658,16 +660,16 @@ static void user_ent_hash_build(void)
if (process[0] == '\0') {
FILE *fp;
- snprintf(tmp, sizeof(tmp), "%s/%d/stat",
- root, pid);
- if ((fp = fopen(tmp, "r")) != NULL) {
+ snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid);
+
+ fp = fopen(tmp, "r");
+ if (fp) {
if (fscanf(fp, "%*d (%[^)])", process) < 1)
; /* ignore */
fclose(fp);
}
}
- user_ent_add(ino, process, pid, fd,
- pid_context, sock_context);
+ user_ent_add(ino, process, pid, fd, pid_context, sock_context);
freecon(sock_context);
}
freecon(pid_context);
--
2.20.1
Powered by blists - more mailing lists