aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2012-06-22 22:14:13 -0500
committerRob Landley <rob@landley.net>2012-06-22 22:14:13 -0500
commit285019a129c0dd8f5f9f0f4a6ecda74da961a449 (patch)
tree3b10f846962f3d7aa988c19ef31fb8d854a009f0
parent97abd4a9813b0bd2f16049e2291bba076828408f (diff)
downloadtoybox-285019a129c0dd8f5f9f0f4a6ecda74da961a449.tar.gz
Minor code refactoring.
-rw-r--r--lib/lib.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/lib/lib.c b/lib/lib.c
index ec491063..1c1148c2 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -857,29 +857,27 @@ void for_each_pid_with_name_in(char **names, void (*callback)(pid_t pid))
{
DIR *dp;
struct dirent *entry;
- char cmd[PATH_MAX], path[64];
+ char cmd[sizeof(toybuf)], path[64];
char **curname;
if (!(dp = opendir("/proc"))) perror_exit("opendir");
while ((entry = readdir(dp))) {
- int fd;
+ int fd, n;
if (!isdigit(*entry->d_name)) continue;
if (sizeof(path) <= snprintf(path, sizeof(path), "/proc/%s/cmdline",
entry->d_name)) continue;
- if (-1 != (fd=xopen(path, O_RDONLY))) {
- int n = read(fd, cmd, sizeof(cmd));
+ if (-1 == (fd=open(path, O_RDONLY))) continue;
+ n = read(fd, cmd, sizeof(cmd));
+ close(fd);
+ if (n<1) continue;
- close(fd);
- if (n<1) continue;
-
- for (curname = names; *curname; curname++)
- if (!strcmp(basename(cmd), *curname))
- callback(atol(entry->d_name));
- }
+ for (curname = names; *curname; curname++)
+ if (!strcmp(basename(cmd), *curname))
+ callback(atol(entry->d_name));
}
closedir(dp);