diff options
author | Peilin Ye <peilin.ye@bytedance.com> | 2022-05-24 19:53:05 -0700 |
---|---|---|
committer | David Ahern <dsahern@kernel.org> | 2022-05-30 09:54:18 -0600 |
commit | 210018bfe99b21effd3f6f2f67dec7dcba49decc (patch) | |
tree | 63496ae0c2754e8058b5803a6d0818c5d762a151 | |
parent | ea3b57ec3991a576a6aa7276979db518fd5488ce (diff) | |
download | iproute2-210018bfe99b21effd3f6f2f67dec7dcba49decc.tar.gz |
ss: Fix coding style issues in user_ent_hash_build()
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>
-rw-r--r-- | misc/ss.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -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); |