aboutsummaryrefslogtreecommitdiffstats
path: root/getdtablecount.c
diff options
context:
space:
mode:
authorWynn Wolf Arbor2021-01-17 15:36:03 +0100
committerWynn Wolf Arbor2021-01-17 15:36:03 +0100
commit93770d7f1c78dab289d8edc597c65b3103da513d (patch)
treefa6dc694bc339daaf496200404f34b06c5a86f76 /getdtablecount.c
parent56691b1bbbb8517a01f4abc123d0ebbf34256707 (diff)
downloadslowcgi-93770d7f1c78dab289d8edc597c65b3103da513d.tar.gz
Have getdtablecount() return the right number of file descriptors6.8
To find the number of file descriptors that the process has currently open, getdtablecount() counts the number of files under '/proc/self/fd'. Previously, the special directories '.' and '..' were counted alongside any symbolic links, making getdtablecount() return the wrong number of file descriptors. Make sure that these special directories are ignored by only counting files whose name consists entirely of digits.
Diffstat (limited to 'getdtablecount.c')
-rw-r--r--getdtablecount.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/getdtablecount.c b/getdtablecount.c
index 5bfa5ed..1b59b38 100644
--- a/getdtablecount.c
+++ b/getdtablecount.c
@@ -16,7 +16,8 @@ getdtablecount(void)
n = 0;
while ((dp = readdir(dir)))
- n++;
+ if (dp->d_name[0] >= '0' && dp->d_name[0] <= '9')
+ n++;
closedir(dir);
return n;