summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-05-17 21:30:10 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-05-17 21:30:10 +0200
commitd8a3a034a13aaabe5877c6b3cdf73e0582e6425f (patch)
tree51d16652c7e72af67f16b12c6629ae23c22737cb
parentf863ed2c2d9000d95aad7f2a0a27212acf86c692 (diff)
downloadfastd-0.4-rc8.tar
fastd-0.4-rc8.zip
Close inherited file handlesv0.4-rc8
-rw-r--r--src/fastd.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/fastd.c b/src/fastd.c
index 24faf83..0ea9e26 100644
--- a/src/fastd.c
+++ b/src/fastd.c
@@ -39,6 +39,7 @@
#include <signal.h>
#include <string.h>
#include <sys/ioctl.h>
+#include <sys/resource.h>
#include <sys/socket.h>
#include <unistd.h>
@@ -614,10 +615,34 @@ static void maintenance(fastd_context *ctx) {
}
+static void close_fds(fastd_context *ctx) {
+ struct rlimit rl;
+ int fd, maxfd;
+
+ if (getrlimit(RLIMIT_NOFILE, &rl) > 0)
+ maxfd = (int)rl.rlim_max;
+ else
+ maxfd = sysconf(_SC_OPEN_MAX);
+
+ for (fd = 3; fd < maxfd; fd++) {
+ if (close(fd) < 0) {
+ if (errno == EINTR) {
+ fd--;
+ continue;
+ }
+
+ if (errno != EBADF)
+ pr_error_errno(ctx, "close");
+ }
+ }
+}
+
int main(int argc, char *argv[]) {
fastd_context ctx;
memset(&ctx, 0, sizeof(ctx));
+ close_fds(&ctx);
+
fastd_random_bytes(&ctx, &ctx.randseed, sizeof(ctx.randseed), false);
init_signals(&ctx);