]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ss: Fix coding style issues in user_ent_hash_build()
authorPeilin Ye <peilin.ye@bytedance.com>
Wed, 25 May 2022 02:53:05 +0000 (19:53 -0700)
committerDavid Ahern <dsahern@kernel.org>
Mon, 30 May 2022 15:54:18 +0000 (09:54 -0600)
Make checkpatch.pl --strict happy about user_ent_hash_build().

Signed-off-by: Peilin Ye <peilin.ye@bytedance.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
misc/ss.c

index 790e511d57a943765a0b6164b266e84470bcb3ea..97f41a0eb7b08b2ce82fc99211aaaa8725144b01 100644 (file)
--- 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);